initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / global / clock / clock.C
blobae244957d935bed9f5889bd26c137226fa18aee4
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "clock.H"
28 #include "string.H"
30 #include <sstream>
31 #include <iomanip>
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 const char *Foam::clock::monthNames[] =
39     "Jan", "Feb", "Mar", "Apr", "May", "Jun",
40     "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
44 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
46 time_t Foam::clock::getTime()
48     return ::time(reinterpret_cast<time_t*>(0));
52 const struct tm Foam::clock::rawDate()
54     time_t t = getTime();
55     struct tm *timeStruct = localtime(&t);
56     return *timeStruct;
60 Foam::string Foam::clock::dateTime()
62     std::ostringstream osBuffer;
64     time_t t = getTime();
65     struct tm *timeStruct = localtime(&t);
67     osBuffer
68         << std::setfill('0')
69         << std::setw(4) << timeStruct->tm_year + 1900
70         << '-' << std::setw(2) << timeStruct->tm_mon + 1
71         << '-' << std::setw(2) << timeStruct->tm_mday
72         << 'T'
73         << std::setw(2) << timeStruct->tm_hour
74         << ':' << std::setw(2) << timeStruct->tm_min
75         << ':' << std::setw(2) << timeStruct->tm_sec;
77     return osBuffer.str();
80 Foam::string Foam::clock::date()
82     std::ostringstream osBuffer;
84     time_t t = getTime();
85     struct tm *timeStruct = localtime(&t);
87     osBuffer
88         << monthNames[timeStruct->tm_mon]
89         << ' ' << std::setw(2) << std::setfill('0') << timeStruct->tm_mday
90         << ' ' << std::setw(4) << timeStruct->tm_year + 1900;
92     return osBuffer.str();
96 Foam::string Foam::clock::clockTime()
98     std::ostringstream osBuffer;
100     time_t t = getTime();
101     struct tm *timeStruct = localtime(&t);
103     osBuffer
104         << std::setfill('0')
105         << std::setw(2) << timeStruct->tm_hour
106         << ':' << std::setw(2) << timeStruct->tm_min
107         << ':' << std::setw(2) << timeStruct->tm_sec;
109     return osBuffer.str();
113 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
115 Foam::clock::clock()
117     startTime_(getTime()),
118     lastTime_(startTime_),
119     newTime_(startTime_)
123 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
125 time_t Foam::clock::elapsedClockTime() const
127     newTime_ = getTime();
128     return newTime_ - startTime_;
132 time_t Foam::clock::clockTimeIncrement() const
134     lastTime_ = newTime_;
135     newTime_ = getTime();
136     return newTime_ - lastTime_;
140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
142 // ************************************************************************* //