OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "clock.H"
00028 #include "string.H"
00029 
00030 #include <sstream>
00031 #include <iomanip>
00032 
00033 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00034 
00035 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
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 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
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 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00114 
00115 Foam::clock::clock()
00116 :
00117     startTime_(getTime()),
00118     lastTime_(startTime_),
00119     newTime_(startTime_)
00120 {}
00121 
00122 
00123 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
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