1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 const char *Foam::clock::monthNames[] =
39 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
40 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
44 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
46 time_t Foam::clock::getTime()
48 return ::time(reinterpret_cast<time_t*>(0));
52 const struct tm Foam::clock::rawDate()
55 struct tm *timeStruct = localtime(&t);
60 Foam::string Foam::clock::dateTime()
62 std::ostringstream osBuffer;
65 struct tm *timeStruct = localtime(&t);
69 << std::setw(4) << timeStruct->tm_year + 1900
70 << '-' << std::setw(2) << timeStruct->tm_mon + 1
71 << '-' << std::setw(2) << timeStruct->tm_mday
73 << std::setw(2) << timeStruct->tm_hour
74 << ':' << std::setw(2) << timeStruct->tm_min
75 << ':' << std::setw(2) << timeStruct->tm_sec;
77 return osBuffer.str();
80 Foam::string Foam::clock::date()
82 std::ostringstream osBuffer;
85 struct tm *timeStruct = localtime(&t);
88 << monthNames[timeStruct->tm_mon]
89 << ' ' << std::setw(2) << std::setfill('0') << timeStruct->tm_mday
90 << ' ' << std::setw(4) << timeStruct->tm_year + 1900;
92 return osBuffer.str();
96 Foam::string Foam::clock::clockTime()
98 std::ostringstream osBuffer;
100 time_t t = getTime();
101 struct tm *timeStruct = localtime(&t);
105 << std::setw(2) << timeStruct->tm_hour
106 << ':' << std::setw(2) << timeStruct->tm_min
107 << ':' << std::setw(2) << timeStruct->tm_sec;
109 return osBuffer.str();
113 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
117 startTime_(getTime()),
118 lastTime_(startTime_),
123 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
125 time_t Foam::clock::elapsedClockTime() const
127 newTime_ = getTime();
128 return newTime_ - startTime_;
132 time_t Foam::clock::clockTimeIncrement() const
134 lastTime_ = newTime_;
135 newTime_ = getTime();
136 return newTime_ - lastTime_;
140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
142 // ************************************************************************* //