FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

clock.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "clock.H"
00027 #include <OpenFOAM/string.H>
00028 
00029 #include <sstream>
00030 #include <iomanip>
00031 
00032 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00033 
00034 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
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 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
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 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00113 
00114 Foam::clock::clock()
00115 :
00116     startTime_(getTime()),
00117     lastTime_(startTime_),
00118     newTime_(startTime_)
00119 {}
00120 
00121 
00122 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
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 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines