Go to the documentation of this file.
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
62 typedef struct tm
tm_t;
84 void set(
long year,
long month,
long day);
123 Date(
int year,
unsigned month,
unsigned day);
170 const char *
put(
char *buffer)
const;
206 inline operator long()
const {
271 return (julian - date.julian);
335 inline operator bool()
const {
357 virtual void update(
void);
360 void set(
int hour,
int minute = 0,
int second = 0);
407 Time(
int hour,
int minute,
int second);
454 const char *
put(
char *buffer)
const;
478 inline operator bool()
const {
515 inline operator long()
const {
658 int hour = 0,
int minute = 0,
int second = 0);
681 const char *
put(
char *buffer)
const;
807 operator bool()
const;
813 inline operator long()
const {
826 operator double()
const;
833 stringref_t
format(
const char *strftime)
const;
881 char buffer[DATETIME_BUFFER_SIZE];
917 int hour = 0,
int minute = 0,
int second = 0);
940 inline const char *
c_str(
void)
const {
949 inline operator const char *(void)
const {
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);
virtual void update(void)
A method to use to "post" any changed values when shadowing a mixed object class.
bool operator!=(const Date &date) const
Compare julian dates if not same date.
bool operator!() const
Check if time object has valid value for ! operator.
DateTime & operator--()
Subtract a day from the current date and time.
bool operator>(const DateTime &datetime) const
Compare date and time with another date and time to see if later.
bool operator==(const Time &time) const
Compare time with another time to see if same time.
stringref_t operator()() const
Expression operator to return an ISO date string for the current julian date.
void set(void)
Set (update) the date and time with current date and time.
void set(void)
Set (update) the time with current time.
Support classes for manipulation of numbers as strings.
DateTimeString(const char *pointer, size_t size=0)
Construct a date and time from ISO string buffer.
time_t timeref(void) const
Get a time_t for the julian date if in time_t epoch.
static const long c_hour
Constant for number of seconds in a hour.
DateTime()
Construct a new date and time object with current date and time.
static void release(tm_t *object)
Release a struct tm object from glt or gmt.
Time & operator++()
Incrememnt time by 1 second, wrap on 24 hour period.
bool operator==(const Date &date) const
Compare julian dates if same date.
The Datetime class uses a julian date representation of the current year, month, and day and a intege...
Time & operator-=(long seconds)
Decrement time by specified seconds.
time_t get(void) const
Get C library time_t type if object in C library epoch range.
virtual ~DateNumber()
Release a datenumber object.
DateTime & operator=(const DateTime &datetime)
Assign date and time from another datetime object.
Date & operator--()
Decrement date by one day.
DateTime(int year, unsigned month, unsigned day, int hour=0, int minute=0, int second=0)
Construct a date and time object from explicit date and time values.
static tm_t * local(const time_t *time=NULL)
Fetch an instance of time converted to local time.
Date(int year, unsigned month, unsigned day)
Create a julian date from an arbitrary year, month, and day.
Time & operator+=(long seconds)
Increment time by specified seconds.
const char * put(char *buffer) const
Get a hh:mm:ss formatted string for current time.
bool operator!=(const Time &time) const
Compare time with another time to see if not same time.
Time(int hour, int minute, int second)
Create a time from hours (0-23), minutes (0-59), and seconds (0-59).
bool operator<=(const Time &time) const
Compare time if earlier than or equal to another time.
void set(const char *pointer, size_t size=0)
Set time from a hh:mm:ss formatted string.
A number class that manipulates a string buffer that is also a date.
const Time operator+(long seconds) const
Add seconds to the current time, wrap if 24 hours.
virtual ~Date()
Destroy julian date object.
long get(void) const
Get current time in seconds from midnight.
A number manipulation class.
The Time class uses a integer representation of the current time.
Date(const struct tm *object)
Create a julian date from a local or gmt date and time.
DateTimeString(const time_t time)
Construct a date and time from C libraray time_t type.
int second(void) const
Get seconds from current minute.
Date(time_t value)
Create a julian date from a time_t type.
DateTime datetime_t
Convenience type for using DateTime object.
bool operator>=(const DateTime &datetime) const
Compare date and time with another date and time to see if later or the same.
DateNumber(char *pointer)
Create a date number tied to a refreshed string buffer.
Date()
Construct a new julian date with today's date.
static const size_t sz_string
Size of time string field.
Date(const char *pointer, size_t size=0)
Create a julian date from a ISO date string of a specified size.
const DateTime operator+(long seconds) const
Add seconds to datetime in an expression.
unsigned dow(void) const
Get the day of the week (0-7).
stringref_t format(const char *strftime) const
Return date and time formatted using strftime format values.
bool operator!() const
Check if julian date is not valid.
long operator-(const Time &reference)
Get difference (in seconds) between two times.
Time(const time_t value)
Create a time from the time portion of a time_t.
int hour(void) const
Get hours from midnight.
virtual ~Time()
Destroy time object.
bool operator!=(const DateTime &datetime) const
Compare date and time with another date and time to see if not same.
DateTimeString datetimestring_t
Convenience type for using DateTimeString object.
Time & operator=(const Time &time)
Assign a time as a copy of another time.
Time()
Create a time from current time.
Date & operator+=(long offset)
Increment date by offset.
long operator-(const Date &date)
Operator to compute number of days between two dates.
Time tod_t
Convenience type for using Time object.
const Date operator-(long days) const
Subtract days from a julian date in an expression.
A thread-safe atomic heap management system.
Date & operator-=(long offset)
Decrement date by offset.
Date date_t
Convenience type for using Date object.
bool operator>(const Date &date) const
Compare julian date if later than another date.
static const size_t sz_string
Size of datetime string field.
unsigned month(void) const
Get the month of the date (1-12).
virtual void update(void)
A method to use to "post" any changed values when shadowing a mixed object class.
bool operator>=(const Time &time) const
Compare time if later than or equal to another time.
bool operator<(const Date &date) const
Compare julian date if earlier than another date.
void set(void)
Set date number to current date.
bool operator<=(const DateTime &datetime) const
Compare date and time with another date and time to see if earlier or the same.
bool is_valid(void) const
Check if time object had valid value.
Various miscellaneous platform specific headers and defines.
Common namespace for all ucommon objects.
void set(const char *pointer, size_t size=0)
Set the julian date based on an ISO date string of specified size.
virtual ~DateTime()
Destroy date and time object.
bool operator<(const DateTime &datetime) const
Compare date and time with another date and time to see if earlier.
Date & operator++()
Increment date by one day.
bool operator<(const Time &time) const
Compare time if earlier than another time.
DateTime & operator+=(long seconds)
Add seconds to the current datetime object.
Time(const tm_t *object)
Create a time from the time portion of a date and time object.
void set(void)
Set (update) the date with current date.
DateTime(const char *pointer, size_t size=0)
Construct a date and time from ISO string buffer.
DateTimeString(int year, unsigned month, unsigned day, int hour=0, int minute=0, int second=0)
Construct a date and time object from explicit date and time values.
DateTime(const DateTime &object)
Create a datetime object from another object.
const DateTime operator-(long seconds) const
Subtract seconds from datetime in an expression.
Used for forming stream output.
virtual ~DateTimeString()
Destroy date time string.
const Date operator+(long days) const
Add days to julian date in an expression.
int minute(void) const
Get minutes from current hour.
unsigned day(void) const
Get the day of the month of the date.
static const long c_week
Constant for number of seconds in a week.
DateTimeString(const DateTimeString &object)
Create a datetime object from another object.
struct tm tm_t
Convenience type for struct tm.
stringref_t operator()() const
Convert to standard 24 hour time string.
DateTimeString(const tm_t *tm)
Construct a date and time from C library time structure.
virtual void update(void)
A method to use to "post" any changed values when shadowing a mixed object class.
const char * put(char *buffer) const
Get a ISO string representation of the date (yyyy-mm-dd).
DateTime & operator++()
Add a day from the current date and time.
static const long c_day
Constant for number of seconds in a day.
bool operator<=(const Date &date) const
Compare julian date if earlier than or equal to another date.
DateTime(const time_t time)
Construct a date and time from C library time_t type.
bool operator>(const Time &time) const
Compare time if later than another time.
long get(void) const
Get the date as a number for the object or 0 if invalid.
bool operator==(const DateTime &datetime) const
Compare date and time with another date and time to see if the same.
mode_t
Specify string buffer mode.
int year(void) const
Get the year of the date.
const char * c_str(void) const
Extract char from string.
virtual void update(void)
A method to use to "post" any changed values when shadowing a mixed object class.
DateTime & operator-=(long seconds)
Subtract seconds from current datetime object.
const Time operator-(long seconds) const
Subtract seconds to the current time, wrap if 24 hours.
bool operator>=(const Date &date) const
Compare julian date if later than or equal to another date.
The Date class uses a julian date representation of the current year, month, and day.
bool operator!() const
Check if date and time is not valid.
bool is_valid(void) const
Test if object is valid.
Generic smart pointer class.
const char * put(char *buffer) const
Get a ISO formatted date and time string for current object.
Date(const Date &object)
Create a julian date object from another object.
Time(const Time &object)
Create a time object from another object.
DateTimeString(mode_t string=DateTimeString::BOTH)
Construct a new date and time object with current date and time.
void set(void)
Set (update) the date and time with current date and time.
DateTime(const tm_t *tm)
Construct a date and time from C library time structure.
long operator*() const
Get object time in seconds.
long operator*() const
Access julian value.
Used for processing input.
Time & operator--()
Decrement time by 1 second, wrap on 24 hour period.
Time(const char *pointer, size_t size=0)
Create a time from a hh:mm:ss formatted time string.
long operator-(const DateTime &datetime)
Operator to compute number of days between two dates.
bool is_valid(void) const
Check if date is valid.
static tm_t * gmt(const time_t *time=NULL)
Fetch an instance of time converted to gmt.
void set(mode_t string)
Set the string mode.
Date & operator=(const Date &date)
Assign date from another date object.
static const size_t sz_string
Size of date string field.