radarlib  1.4.6
time.hpp
Go to the documentation of this file.
1 /*
2  * Radar Library
3  *
4  * Copyright (C) 2009-2010 ARPA-SIM <urpsim@smr.arpa.emr.it>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  *
20  * Author: Guido Billi <guidobilli@gmail.com>
21  */
22 
27 #ifndef __RADAR_TIME_HPP__
28 #define __RADAR_TIME_HPP__
29 
30 #include <ctime>
31 #include <string>
32 #include <stdexcept>
33 
34 #include <radarlib/defs.h>
35 
36 namespace Radar {
37 
41 namespace timeutils {
42 
43 /*===========================================================================*/
44 /* FUNZIONI PER AVERE IL TEMPO */
45 /*===========================================================================*/
46 
47 RADAR_API bool isNull (time_t value);
48 RADAR_API bool isNull (double value);
49 
56 RADAR_API time_t getUTC ();
57 
68 RADAR_API time_t mktime (int year, int month, int day);
82 RADAR_API time_t mktime (int year, int month, int day, int hour, int min, int sec);
97 RADAR_API double mktime (int year, int month, int day, int hour, int min, int sec, int msec);
98 
99 /*===========================================================================*/
100 /* FUNZIONI DI CHECK */
101 /*===========================================================================*/
102 
112 RADAR_API bool isValidDate (int year, int month, int day);
122 RADAR_API bool isValidTime (int hour, int min, int sec);
123 
124 /*===========================================================================*/
125 /* SPLIT FUNCTIONS */
126 /*===========================================================================*/
127 
137 RADAR_API void splitYMD (time_t absolute, int& year, int& month, int& day);
147 RADAR_API void splitYMD (double absolute, int& year, int& month, int& day);
157 RADAR_API void splitHMS (time_t absolute, int& hour, int& min, int& sec);
168 RADAR_API void splitHMS (double absolute, int& hour, int& min, int& sec, int& msec);
181 RADAR_API void splitYMDHMS (time_t absolute, int& year, int& month, int& day, int& hour, int& min, int& sec);
195 RADAR_API void splitYMDHMS (double absolute, int& year, int& month, int& day, int& hour, int& min, int& sec, int& msec);
196 
197 /*===========================================================================*/
198 /* FUNIONI SU TEMPI ASSOLUTI */
199 /*===========================================================================*/
200 
208 RADAR_API std::string absoluteToString(time_t value);
218 RADAR_API std::string absoluteToString(double value, bool allowNAN);
228 RADAR_API time_t parseYYYYMMDDHHMMSS(const std::string& str);
232 RADAR_API time_t toEpoch (float absolute);
236 RADAR_API time_t toEpoch (double absolute);
237 
238 /*===========================================================================*/
239 /* FUNZIONI SU TEMPI GIORNALIERI */
240 /*===========================================================================*/
241 
250 RADAR_API time_t extractDate (time_t absolute);
259 RADAR_API double extractDate (double absolute);
268 RADAR_API time_t extractTime (time_t absolute);
277 RADAR_API double extractTime (double absolute);
285 RADAR_API std::string dayTimeToStr(time_t value);
293 RADAR_API std::string dayTimeToStr(double value);
294 
295 /*===========================================================================*/
296 
307 RADAR_API void convertYday(int year, int yday, int& month, int& day);
316 RADAR_API time_t convertYday(int year, int yday);
326 RADAR_API int mkYday(int year, int month, int day);
327 
328 /*===========================================================================*/
329 
330 } }
331 
332 #endif
333 
334 
335 
336 
337 
338 
339 
340 
341 
342 
343 
344 
345 
346 
347 
348 
349 
350 
351 
352 
353 
354 
355 
356 
357 
358 
Internal library macros.
time_t parseYYYYMMDDHHMMSS(const std::string &str)
Convert a string to a time_t value.
Definition: time.cpp:291
bool isValidTime(int h, int m, int s)
Check if the specified time is a valid date.
Definition: time.cpp:169
time_t extractDate(time_t absolute)
Extract the date from a time_t value to a new time_t value.
Definition: time.cpp:340
bool isValidDate(int yy, int mm, int dd)
Check if the specified date is a valid date.
Definition: time.cpp:150
time_t toEpoch(double absolute)
Reduce a double value to a time_t value, truncating the milliseconds.
Definition: time.cpp:320
std::string absoluteToString(time_t value)
, const char* fmt)
Definition: time.cpp:256
void convertYday(int year, int yday, int &month, int &day)
Convert a year day to the corresponding month and day number.
Definition: time.cpp:404
int mkYday(int year, int month, int day)
Calculate the year day from a date.
Definition: time.cpp:441
void splitHMS(time_t absolute, int &hour, int &min, int &sec)
Extract day time informations from a time_t value.
Definition: time.cpp:197
std::string dayTimeToStr(time_t value)
Convert a day time to a string.
Definition: time.cpp:367
time_t extractTime(time_t absolute)
Extract the day time from a time_t value to a new time_t value.
Definition: time.cpp:352
void splitYMDHMS(time_t absolute, int &year, int &month, int &day, int &hour, int &min, int &sec)
Extract date and day time informations from a time_t value.
Definition: time.cpp:241
time_t mktime(int year, int month, int day)
Create a time from a date.
Definition: time.cpp:110
void splitYMD(time_t absolute, int &year, int &month, int &day)
Extract date informations from a time_t value.
Definition: time.cpp:178
time_t getUTC()
Get the current UTC time from the system.
Definition: time.cpp:52