1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 const char *Foam::clock::monthNames[] =
38 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
39 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
43 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
45 time_t Foam::clock::getTime()
47 return ::time(reinterpret_cast<time_t*>(0));
51 const struct tm Foam::clock::rawDate()
54 struct tm *timeStruct = localtime(&t);
59 Foam::string Foam::clock::dateTime()
61 std::ostringstream osBuffer;
64 struct tm *timeStruct = localtime(&t);
68 << std::setw(4) << timeStruct->tm_year + 1900
69 << '-' << std::setw(2) << timeStruct->tm_mon + 1
70 << '-' << std::setw(2) << timeStruct->tm_mday
72 << std::setw(2) << timeStruct->tm_hour
73 << ':' << std::setw(2) << timeStruct->tm_min
74 << ':' << std::setw(2) << timeStruct->tm_sec;
76 return osBuffer.str();
79 Foam::string Foam::clock::date()
81 std::ostringstream osBuffer;
84 struct tm *timeStruct = localtime(&t);
87 << monthNames[timeStruct->tm_mon]
88 << ' ' << std::setw(2) << std::setfill('0') << timeStruct->tm_mday
89 << ' ' << std::setw(4) << timeStruct->tm_year + 1900;
91 return osBuffer.str();
95 Foam::string Foam::clock::clockTime()
97 std::ostringstream osBuffer;
100 struct tm *timeStruct = localtime(&t);
104 << std::setw(2) << timeStruct->tm_hour
105 << ':' << std::setw(2) << timeStruct->tm_min
106 << ':' << std::setw(2) << timeStruct->tm_sec;
108 return osBuffer.str();
112 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
116 startTime_(getTime()),
117 lastTime_(startTime_),
122 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
124 time_t Foam::clock::elapsedClockTime() const
126 newTime_ = getTime();
127 return newTime_ - startTime_;
131 time_t Foam::clock::clockTimeIncrement() const
133 lastTime_ = newTime_;
134 newTime_ = getTime();
135 return newTime_ - lastTime_;
139 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
141 // ************************************************************************* //