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