ucommon
numbers.h
1 #ifndef COMMONCPP_NUMBERS_H_
2 #define COMMONCPP_NUMBERS_H_
3 
4 #ifndef COMMONCPP_CONFIG_H_
5 #include <commoncpp/config.h>
6 #endif
7 
8 #ifndef COMMONCPP_STRING_H_
9 #include <commoncpp/string.h>
10 #endif
11 
14 
15 class __EXPORT Date : public ucommon::Date
16 {
17 protected:
18  inline void toJulian(long year, long month, long day)
19  {ucommon::Date::set(year, month, day);}
20 
21  inline void fromJulian(char *buf) const
22  {put(buf);}
23 
24 public:
25  inline Date(time_t value) : ucommon::Date(value) {};
26 
27  inline Date(struct tm *object) : ucommon::Date(object) {};
28 
29  inline Date(const char *ptr, size_t size = 0) : ucommon::Date(ptr, size) {};
30 
31  inline Date(int y, unsigned m, unsigned d) : ucommon::Date(y, m, d) {};
32 
33  inline Date(const Date& object) : ucommon::Date(object) {};
34 
35  inline Date() : ucommon::Date() {};
36 
37  inline int getYear(void) const
38  {return year();}
39 
40  inline unsigned getMonth(void) const
41  {return month();}
42 
43  inline unsigned getDay(void) const
44  {return day();}
45 
46  inline unsigned getDayOfWeek(void) const
47  {return dow();}
48 
49  inline long getJulian(void) const
50  {return julian;}
51 
52  inline const char *get(char *buffer) const
53  {return put(buffer);}
54 
55  inline time_t getTime(void) const
56  {return timeref();}
57 
58  inline bool isValid(void) const
59  {return is_valid();}
60 };
61 
62 class __EXPORT Time : public ucommon::Time
63 {
64 protected:
65  inline void toSeconds(int h, int m = 0, int s = 0)
66  {set(h, m, s);}
67 
68  inline void fromSeconds(char *buf) const
69  {put(buf);}
70 
71 public:
72  inline Time(time_t value) : ucommon::Time(value) {};
73 
74  inline Time(tm_t *object) : ucommon::Time(object) {};
75 
76  inline Time(const char *ptr, size_t size) : ucommon::Time(ptr, size) {};
77 
78  inline Time(int h, int m, int s) : ucommon::Time(h, m, s) {};
79 
80  inline Time() : ucommon::Time() {};
81 
82  inline int getHour(void) const
83  {return hour();}
84 
85  inline int getMinute(void) const
86  {return minute();}
87 
88  inline int getSecond(void) const
89  {return second();}
90 
91  inline const char *get(char *buffer) const
92  {return put(buffer);}
93 
94  inline bool isValid(void) const
95  {return is_valid();}
96 
97 };
98 
99 class __EXPORT DateTime : public ucommon::DateTime
100 {
101 public:
102  inline DateTime(time_t time) : ucommon::DateTime(time) {};
103 
104  inline DateTime(struct tm *dt) : ucommon::DateTime(dt) {};
105 
106 
107  inline DateTime(int year, unsigned month, unsigned day,
108  int hour = 0, int minute = 0, int second = 0) :
109  ucommon::DateTime(year, month, day, hour, minute, second) {};
110 
111  inline DateTime(const char *ptr, size_t size) :
112  ucommon::DateTime(ptr, size) {};
113 
114  inline DateTime(const DateTime& obj) : ucommon::DateTime(obj) {};
115 
116  inline DateTime() : ucommon::DateTime() {};
117 
118  inline int getYear(void) const
119  {return year();}
120 
121  inline unsigned getMonth(void) const
122  {return month();}
123 
124  inline unsigned getDay(void) const
125  {return day();}
126 
127  inline unsigned getDayOfWeek(void) const
128  {return dow();}
129 
130  inline long getJulian(void) const
131  {return julian;}
132 
133  inline const char *get(char *buffer) const
134  {return ucommon::DateTime::put(buffer);}
135 
136  inline time_t getTime(void) const
137  {return ucommon::DateTime::timeref();}
138 
139  inline bool isValid(void) const
140  {return ucommon::DateTime::is_valid();}
141 
142  inline int getHour(void) const
143  {return hour();}
144 
145  inline int getMinute(void) const
146  {return minute();}
147 
148  inline int getSecond(void) const
149  {return second();}
150 
151  inline static tm_t *glt(time_t *time = NULL)
152  {return ucommon::DateTime::local(time);}
153 };
154 
155 #endif
156 
bool is_valid(void) const
Check if date is valid.
Common C++ generic string class.
int hour(void) const
Get hours from midnight.
The Datetime class uses a julian date representation of the current year, month, and day and a intege...
Definition: datetime.h:608
Time()
Create a time from current time.
const char * put(char *buffer) const
Get a ISO string representation of the date (yyyy-mm-dd).
static tm_t * local(time_t *time=((void *) 0))
Fetch an instance of time converted to local time.
time_t timeref(void) const
Get a time_t for the julian date if in time_t epoch.
int second(void) const
Get seconds from current minute.
bool is_valid(void) const
Check if time object had valid value.
bool is_valid(void) const
Test if object is valid.
void set(void)
Set (update) the date with current date.
int minute(void) const
Get minutes from current hour.
unsigned day(void) const
Get the day of the month of the date.
A number class that manipulates a string buffer that is also a date.
Definition: datetime.h:957
The Time class uses a integer representation of the current time.
Definition: datetime.h:345
int year(void) const
Get the year of the date.
DateTime()
Construct a new date and time object with current date and time.
unsigned dow(void) const
Get the day of the week (0-7).
unsigned month(void) const
Get the month of the date (1-12).
void set(void)
Set (update) the time with current time.
const char * put(char *buffer) const
Get a hh:mm:ss formatted string for current time.
struct tm tm_t
Convenience type for struct tm.
Definition: datetime.h:61
A DateTime string class.
Definition: datetime.h:858
Date()
Construct a new julian date with today&#39;s date.
The Date class uses a julian date representation of the current year, month, and day.
Definition: datetime.h:78
const char * put(char *buffer) const
Get a ISO formatted date and time string for current object.