Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "clock.H"
00027 #include <OpenFOAM/string.H>
00028
00029 #include <sstream>
00030 #include <iomanip>
00031
00032
00033
00034
00035
00036 const char *Foam::clock::monthNames[] =
00037 {
00038 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
00039 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
00040 };
00041
00042
00043
00044
00045 time_t Foam::clock::getTime()
00046 {
00047 return ::time(reinterpret_cast<time_t*>(0));
00048 }
00049
00050
00051 const struct tm Foam::clock::rawDate()
00052 {
00053 time_t t = getTime();
00054 struct tm *timeStruct = localtime(&t);
00055 return *timeStruct;
00056 }
00057
00058
00059 Foam::string Foam::clock::dateTime()
00060 {
00061 std::ostringstream osBuffer;
00062
00063 time_t t = getTime();
00064 struct tm *timeStruct = localtime(&t);
00065
00066 osBuffer
00067 << std::setfill('0')
00068 << std::setw(4) << timeStruct->tm_year + 1900
00069 << '-' << std::setw(2) << timeStruct->tm_mon + 1
00070 << '-' << std::setw(2) << timeStruct->tm_mday
00071 << 'T'
00072 << std::setw(2) << timeStruct->tm_hour
00073 << ':' << std::setw(2) << timeStruct->tm_min
00074 << ':' << std::setw(2) << timeStruct->tm_sec;
00075
00076 return osBuffer.str();
00077 }
00078
00079 Foam::string Foam::clock::date()
00080 {
00081 std::ostringstream osBuffer;
00082
00083 time_t t = getTime();
00084 struct tm *timeStruct = localtime(&t);
00085
00086 osBuffer
00087 << monthNames[timeStruct->tm_mon]
00088 << ' ' << std::setw(2) << std::setfill('0') << timeStruct->tm_mday
00089 << ' ' << std::setw(4) << timeStruct->tm_year + 1900;
00090
00091 return osBuffer.str();
00092 }
00093
00094
00095 Foam::string Foam::clock::clockTime()
00096 {
00097 std::ostringstream osBuffer;
00098
00099 time_t t = getTime();
00100 struct tm *timeStruct = localtime(&t);
00101
00102 osBuffer
00103 << std::setfill('0')
00104 << std::setw(2) << timeStruct->tm_hour
00105 << ':' << std::setw(2) << timeStruct->tm_min
00106 << ':' << std::setw(2) << timeStruct->tm_sec;
00107
00108 return osBuffer.str();
00109 }
00110
00111
00112
00113
00114 Foam::clock::clock()
00115 :
00116 startTime_(getTime()),
00117 lastTime_(startTime_),
00118 newTime_(startTime_)
00119 {}
00120
00121
00122
00123
00124 time_t Foam::clock::elapsedClockTime() const
00125 {
00126 newTime_ = getTime();
00127 return newTime_ - startTime_;
00128 }
00129
00130
00131 time_t Foam::clock::clockTimeIncrement() const
00132 {
00133 lastTime_ = newTime_;
00134 newTime_ = getTime();
00135 return newTime_ - lastTime_;
00136 }
00137
00138
00139
00140
00141