FreeFOAM The Cross-Platform CFD Toolkit
clock.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "clock.H"
27 #include <OpenFOAM/string.H>
28 
29 #include <sstream>
30 #include <iomanip>
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 const char *Foam::clock::monthNames[] =
37 {
38  "Jan", "Feb", "Mar", "Apr", "May", "Jun",
39  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
40 };
41 
42 
43 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
44 
46 {
47  return ::time(reinterpret_cast<time_t*>(0));
48 }
49 
50 
51 const struct tm Foam::clock::rawDate()
52 {
53  time_t t = getTime();
54  struct tm *timeStruct = localtime(&t);
55  return *timeStruct;
56 }
57 
58 
60 {
61  std::ostringstream osBuffer;
62 
63  time_t t = getTime();
64  struct tm *timeStruct = localtime(&t);
65 
66  osBuffer
67  << std::setfill('0')
68  << std::setw(4) << timeStruct->tm_year + 1900
69  << '-' << std::setw(2) << timeStruct->tm_mon + 1
70  << '-' << std::setw(2) << timeStruct->tm_mday
71  << 'T'
72  << std::setw(2) << timeStruct->tm_hour
73  << ':' << std::setw(2) << timeStruct->tm_min
74  << ':' << std::setw(2) << timeStruct->tm_sec;
75 
76  return osBuffer.str();
77 }
78 
80 {
81  std::ostringstream osBuffer;
82 
83  time_t t = getTime();
84  struct tm *timeStruct = localtime(&t);
85 
86  osBuffer
87  << monthNames[timeStruct->tm_mon]
88  << ' ' << std::setw(2) << std::setfill('0') << timeStruct->tm_mday
89  << ' ' << std::setw(4) << timeStruct->tm_year + 1900;
90 
91  return osBuffer.str();
92 }
93 
94 
96 {
97  std::ostringstream osBuffer;
98 
99  time_t t = getTime();
100  struct tm *timeStruct = localtime(&t);
101 
102  osBuffer
103  << std::setfill('0')
104  << std::setw(2) << timeStruct->tm_hour
105  << ':' << std::setw(2) << timeStruct->tm_min
106  << ':' << std::setw(2) << timeStruct->tm_sec;
107 
108  return osBuffer.str();
109 }
110 
111 
112 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
113 
115 :
116  startTime_(getTime()),
117  lastTime_(startTime_),
118  newTime_(startTime_)
119 {}
120 
121 
122 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
123 
125 {
126  newTime_ = getTime();
127  return newTime_ - startTime_;
128 }
129 
130 
132 {
133  lastTime_ = newTime_;
134  newTime_ = getTime();
135  return newTime_ - lastTime_;
136 }
137 
138 
139 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
140 
141 // ************************ vim: set sw=4 sts=4 et: ************************ //