30 #ifndef _UCOMMON_DATETIME_H_ 31 #define _UCOMMON_DATETIME_H_ 33 #ifndef _UCOMMON_CONFIG_H_ 37 #ifndef _UCOMMON_NUMBERS_H_ 41 #ifndef _UCOMMON_TYPEREF_H_ 52 #define DATE_STRING_SIZE 10 53 #define DATE_BUFFER_SIZE 11 54 #define TIME_STRING_SIZE 8 55 #define TIME_BUFFER_SIZE 9 56 #define DATETIME_STRING_SIZE 19 57 #define DATETIME_BUFFER_SIZE 20 84 void set(
long year,
long month,
long day);
90 virtual void update(
void);
96 static const size_t sz_string;
108 Date(
const struct tm *
object);
115 Date(
const char *pointer,
size_t size = 0);
123 Date(
int year,
unsigned month,
unsigned day);
129 Date(
const Date&
object);
145 int year(
void)
const;
151 unsigned month(
void)
const;
157 unsigned day(
void)
const;
163 unsigned dow(
void)
const;
170 const char *put(
char *buffer)
const;
176 time_t timeref(
void)
const;
182 long get(void)
const;
194 void set(
const char *pointer,
size_t size = 0);
200 bool is_valid(
void)
const;
206 inline operator long()
const {
214 inline long operator*()
const {
223 stringref_t operator()()
const;
242 Date& operator+=(
long offset);
249 Date& operator-=(
long offset);
256 const Date operator+(
long days)
const;
263 const Date operator-(
long days)
const;
270 inline long operator-(
const Date &date) {
271 return (julian - date.julian);
279 Date& operator=(
const Date& date);
286 bool operator==(
const Date& date)
const;
293 bool operator!=(
const Date& date)
const;
300 bool operator<(
const Date& date)
const;
307 bool operator<=(
const Date& date)
const;
314 bool operator>(
const Date& date)
const;
321 bool operator>=(
const Date& date)
const;
327 inline bool operator!()
const {
335 inline operator bool()
const {
357 virtual void update(
void);
360 void set(
int hour,
int minute = 0,
int second = 0);
365 static const long c_day;
370 static const long c_hour;
375 static const long c_week;
380 static const size_t sz_string;
386 Time(
const time_t value);
392 Time(
const tm_t *
object);
399 Time(
const char *pointer,
size_t size = 0);
407 Time(
int hour,
int minute,
int second);
413 Time(
const Time&
object);
429 long get(void)
const;
435 int hour(
void)
const;
441 int minute(
void)
const;
447 int second(
void)
const;
454 const char *put(
char *buffer)
const;
466 void set(
const char *pointer,
size_t size = 0);
472 bool is_valid(
void)
const;
478 inline operator bool()
const {
486 inline bool operator!()
const {
495 long operator-(
const Time &reference);
502 const Time operator+(
long seconds)
const;
509 const Time operator-(
long seconds)
const;
515 inline operator long()
const {
523 inline long operator*()
const {
531 stringref_t operator()()
const;
550 Time& operator=(
const Time& time);
557 Time& operator+=(
long seconds);
564 Time& operator-=(
long seconds);
571 bool operator==(
const Time &time)
const;
578 bool operator!=(
const Time &time)
const;
585 bool operator<(
const Time &time)
const;
592 bool operator<=(
const Time &time)
const;
599 bool operator>(
const Time &time)
const;
606 bool operator>=(
const Time &time)
const;
618 class __EXPORT DateTime :
public Date,
public Time
621 virtual void update(
void) __OVERRIDE;
627 static const size_t sz_string;
633 DateTime(
const time_t time);
639 DateTime(
const tm_t *tm);
646 DateTime(
const char *pointer,
size_t size = 0);
657 DateTime(
int year,
unsigned month,
unsigned day,
658 int hour = 0,
int minute = 0,
int second = 0);
664 DateTime(
const DateTime&
object);
681 const char *put(
char *buffer)
const;
687 time_t
get(void)
const;
693 bool is_valid(
void)
const;
700 long operator-(
const DateTime &datetime);
707 DateTime& operator=(
const DateTime& datetime);
715 DateTime& operator+=(
long seconds);
723 DateTime& operator-=(
long seconds);
731 const DateTime operator+(
long seconds)
const;
739 const DateTime operator-(
long seconds)
const;
745 DateTime& operator++();
751 DateTime& operator--();
758 bool operator==(
const DateTime& datetime)
const;
765 bool operator!=(
const DateTime& datetime)
const;
772 bool operator<(
const DateTime& datetime)
const;
780 bool operator<=(
const DateTime& datetime)
const;
787 bool operator>(
const DateTime& datetime)
const;
795 bool operator>=(
const DateTime& datetime)
const;
801 bool operator!()
const;
807 operator bool()
const;
813 inline operator long()
const {
826 operator double()
const;
833 stringref_t format(
const char *strftime)
const;
843 static tm_t *local(
const time_t *time = NULL);
853 static tm_t *gmt(
const time_t *time = NULL);
859 static void release(
tm_t *
object);
869 class __EXPORT DateTimeString :
public DateTime
881 char buffer[DATETIME_BUFFER_SIZE];
885 virtual void update(
void) __OVERRIDE;
892 DateTimeString(
const time_t time);
898 DateTimeString(
const tm_t *tm);
905 DateTimeString(
const char *pointer,
size_t size = 0);
916 DateTimeString(
int year,
unsigned month,
unsigned day,
917 int hour = 0,
int minute = 0,
int second = 0);
923 DateTimeString(
const DateTimeString&
object);
928 DateTimeString(mode_t
string = DateTimeString::BOTH);
933 virtual ~DateTimeString();
940 inline const char *c_str(
void)
const {
949 inline operator const char *(void)
const {
962 void set(mode_t string);
971 class __EXPORT DateNumber :
public Number,
public Date
974 virtual void update(
void) __OVERRIDE;
981 DateNumber(
char *pointer);
986 virtual ~DateNumber();
994 class __EXPORT isotime :
public __PROTOCOL PrintProtocol,
public __PROTOCOL InputProtocol
1001 DATE, TIME, DATETIME
1008 const char *_print(
void)
const;
1010 int _input(
int code) __OVERRIDE;
1013 isotime(Date& date, Time& time);
1014 isotime(Date& date);
1015 isotime(Time& time);
DateTimeString datetimestring_t
Convenience type for using DateTimeString object.
class __attribute__((visibility("default"))) DateTime class __attribute__((visibility("default"))) DateTimeString class __attribute__((visibility("default"))) DateNumber class __attribute__((visibility("default"))) isotime typedef DateTime datetime_t
The Datetime class uses a julian date representation of the current year, month, and day and a intege...
Date date_t
Convenience type for using Date object.
Support classes for manipulation of numbers as strings.
Various miscellaneous platform specific headers and defines.
Time tod_t
Convenience type for using Time object.
struct tm tm_t
Convenience type for struct tm.
A thread-safe atomic heap management system.
Common namespace for all ucommon objects.