29 #ifndef _UCOMMON_DATETIME_H_
30 #define _UCOMMON_DATETIME_H_
32 #ifndef _UCOMMON_CONFIG_H_
36 #ifndef _UCOMMON_NUMBERS_H_
40 #ifndef _UCOMMON_STRING_H_
46 #define DATE_STRING_SIZE 10
47 #define DATE_BUFFER_SIZE 11
48 #define TIME_STRING_SIZE 8
49 #define TIME_BUFFER_SIZE 9
50 #define DATETIME_STRING_SIZE 19
51 #define DATETIME_BUFFER_SIZE 20
78 void toJulian(
long year,
long month,
long day);
79 void fromJulian(
char *buf)
const;
85 virtual void update(
void);
91 typedef enum {year = 10, month, day, dow} index_t;
108 Date(
struct tm *
object);
123 Date(
int year,
unsigned month = 1,
unsigned day = 1);
145 int getYear(
void)
const;
151 unsigned getMonth(
void)
const;
157 unsigned getDay(
void)
const;
163 unsigned getDayOfWeek(
void)
const;
169 inline long getJulian(
void)
177 char *
get(
char *buffer)
const;
183 time_t getTime(
void)
const;
189 long get(void)
const;
201 void set(
const char *
pointer,
size_t size = 0);
207 bool isValid(
void)
const;
213 inline operator long()
const
221 int operator[](index_t component)
const;
227 inline long operator*()
const
235 String operator()()
const;
254 Date& operator+=(
long offset);
261 Date& operator-=(
long offset);
268 Date operator+(
long days);
275 Date operator-(
long days);
282 inline long operator-(
const Date &date)
283 {
return (julian - date.julian);};
297 bool operator==(
const Date& date);
304 bool operator!=(
const Date& date);
311 bool operator<(
const Date& date);
318 bool operator<=(
const Date& date);
325 bool operator>(
const Date& date);
332 bool operator>=(
const Date& date);
338 inline bool operator!()
const
339 {
return !isValid();};
345 inline operator bool()
const
366 void toSeconds(
int hour,
int minute = 0,
int second = 0);
367 void fromSeconds(
char *buf)
const;
368 virtual void update(
void);
374 typedef enum {hour = 20, minute, second} index_t;
406 Time(
int hour,
int minute,
int second);
428 long get(void)
const;
434 int getHour(
void)
const;
440 int getMinute(
void)
const;
446 int getSecond(
void)
const;
453 char *
get(
char *buffer)
const;
465 void set(
char *
pointer,
size_t size = 0);
471 bool isValid(
void)
const;
477 inline operator bool()
const
484 inline bool operator!()
const
485 {
return !isValid();};
492 long operator-(
const Time &reference);
499 Time operator+(
long seconds);
506 Time operator-(
long seconds);
512 inline operator long()
519 inline long operator*()
const
527 int operator[](index_t component)
const;
533 String operator()()
const;
559 Time& operator+=(
long seconds);
566 Time& operator-=(
long seconds);
573 bool operator==(
const Time &time);
580 bool operator!=(
const Time &time);
587 bool operator<(
const Time &time);
594 bool operator<=(
const Time &time);
601 bool operator>(
const Time &time);
608 bool operator>=(
const Time &time);
629 typedef enum {year = Date::year, month = Date::month, day = Date::day,
631 hour = Time::hour, minute = Time::minute, second = Time::second}
index_t;
681 DateTime(
int year,
unsigned month,
unsigned day,
682 int hour = 0,
int minute = 0,
int second = 0);
705 char *
get(
char *buffer)
const;
711 time_t
get(void)
const;
838 operator bool()
const;
844 inline operator long()
const
845 {
return Date::get();};
856 operator double()
const;
863 String format(
const char *strftime)
const;
873 static tm_t *glt(time_t *time = NULL);
883 static tm_t *gmt(time_t *time = NULL);
907 DATE, TIME, BOTH} mode_t;
910 char buffer[DATETIME_BUFFER_SIZE];
946 int hour = 0,
int minute = 0,
int second = 0);
969 inline const char *c_str(
void)
977 inline operator const char *(void)