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