1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
*
* PrimeBase Media Stream for MySQL
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Original author: Paul McCullagh (H&G2JCtL)
* Continued development: Barry Leslie
*
* 2007-05-20
*
* Represents a time value from the database.
*
* NOTE: All times in the database are based on UTC
* (Universal Coordinated Time)!
*
*/
#ifndef __DBTIME_H__
#define __DBTIME_H__
#include <time.h>
#include "CSDefs.h"
#include "CSObject.h"
class CSTime : public CSObject {
public:
CSTime(): iIsNull(true) { }
CSTime(s_int year, s_int mon, s_int day, s_int hour, s_int min, s_int sec, s_int nsec);
virtual ~CSTime() { }
bool isNull();
void setNull();
/*
* Set the time. The value given is a local time
* sec - seconds (0 - 60)
* min - minutes (0 - 59)
* hour - hours (0 - 23)
* day - day of month (1 - 31)
* mon - month of year (1 - 12)
* year - where year >= 1970 (on UNIX)
*/
void setLocal(s_int year, s_int mon, s_int day, s_int hour, s_int min, s_int sec, s_int nsec);
/* Get the local time. */
void getLocal(s_int& year, s_int& mon, s_int& day, s_int& hour, s_int& min, s_int& sec, s_int& nsec);
/* Set the s_int time. */
void setUTC(s_int year, s_int mon, s_int day, s_int hour, s_int min, s_int sec, s_int nsec);
/* Get the universal time. */
void getUTC(s_int& year, s_int& mon, s_int& day, s_int& hour, s_int& min, s_int& sec, s_int& nsec);
/*
* Returns the time as a string in the local time
* (time zone adjusted).
*/
char *getCString();
/*
* As above, but using the given format.
*/
char *getCString(const char *format);
/* Set the time given a value in seconds and nanoseconds in UTC since 1970.
* Used by UNIX.
*/
void setUTC1970(time_t sec, s_int nsec);
void getUTC1970(time_t& sec, s_int& nsec);
/* Set the time given a 100 nanosecond value in UTC since 1601.
* Used by Windows.
*/
void setUTC1601(uint64_t nsec100);
uint64_t getUTC1601();
/*
* Tests if the time is more than 'max_age' seconds in the past.
*/
bool olderThen(time_t max_age);
static uint64_t getTimeCurrentTicks();
private:
bool iIsNull;
char iCString[100];
/* The time based on UTC (GMT): */
s_int iYear;
s_int iMonth;
s_int iDay;
s_int iHours;
s_int iMinutes;
s_int iSeconds;
s_int iNanoSeconds; /* Plus this number of nano seconds. */
uint64_t get1970as1601();
};
#endif
|