UCommon
|
The Datetime class uses a julian date representation of the current year, month, and day and a integer representation of the current time. More...
#include <datetime.h>
Public Types | |
enum | index_t { year = Date::year, month = Date::month, day = Date::day, dow = Date::dow, hour = Time::hour, minute = Time::minute, second = Time::second } |
Index to components we can access. | |
![]() | |
![]() |
Public Member Functions | |
DateTime (time_t time) | |
Construct a date and time from C library time_t type. | |
DateTime (tm_t *tm) | |
Construct a date and time from C library time structure. | |
DateTime (char *pointer, size_t size=0) | |
Construct a date and time from ISO string buffer. | |
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. | |
DateTime (DateTime &object) | |
Create a datetime object from another object. | |
DateTime () | |
Construct a new date and time object with current date and time. | |
String | format (char *strftime) |
Return date and time formatted using strftime format values. | |
char * | get (char *buffer) |
Get a ISO formatted date and time string for current object. | |
time_t | get (void) |
Get C library time_t type if object in C library epoch range. | |
bool | isValid (void) |
Test if object is valid. | |
operator bool () | |
Test is date and time is valid for is() operator. | |
operator double () | |
Convert date and time to julian day number. | |
operator long () | |
Casting operator to return date as number. | |
bool | operator! () |
Check if date and time is not valid. | |
bool | operator!= (DateTime &datetime) |
Compare date and time with another date and time to see if not same. | |
DateTime | operator+ (long seconds) |
Add seconds to datetime in an expression. | |
DateTime & | operator++ () |
Add a day from the current date and time. | |
DateTime & | operator+= (long seconds) |
Add seconds to the current datetime object. | |
long | operator- (DateTime &datetime) |
Operator to compute number of days between two dates. | |
DateTime | operator- (long seconds) |
Subtract seconds from datetime in an expression. | |
DateTime & | operator-- () |
Subtract a day from the current date and time. | |
DateTime & | operator-= (long seconds) |
Subtract seconds from current datetime object. | |
bool | operator< (DateTime &datetime) |
Compare date and time with another date and time to see if earlier. | |
bool | operator<= (DateTime &datetime) |
Compare date and time with another date and time to see if earlier or the same. | |
DateTime & | operator= (DateTime &datetime) |
Assign date and time from another datetime object. | |
bool | operator== (DateTime &datetime) |
Compare date and time with another date and time to see if the same. | |
bool | operator> (DateTime &datetime) |
Compare date and time with another date and time to see if later. | |
bool | operator>= (DateTime &datetime) |
Compare date and time with another date and time to see if later or the same. | |
int | operator[] (index_t component) |
Access time components. | |
void | set (void) |
Set (update) the date and time with current date and time. | |
virtual | ~DateTime () |
Destroy date and time object. | |
![]() | |
Date (time_t value) | |
Create a julian date from a time_t type. | |
Date (struct tm *object) | |
Create a julian date from a local or gmt date and time. | |
Date (char *pointer, size_t size=0) | |
Create a julian date from a ISO date string of a specified size. | |
Date (int year, unsigned month=1, unsigned day=1) | |
Create a julian date from an arbitrary year, month, and day. | |
Date (Date &object) | |
Create a julian date object from another object. | |
Date () | |
Construct a new julian date with today's date. | |
unsigned | getDay (void) |
Get the day of the month of the date. | |
unsigned | getDayOfWeek (void) |
Get the day of the week (0-7). | |
long | getJulian (void) |
Get the julian number of a date. | |
unsigned | getMonth (void) |
Get the month of the date (1-12). | |
time_t | getTime (void) |
Get a time_t for the julian date if in time_t epoch. | |
int | getYear (void) |
Get the year of the date. | |
bool | operator!= (Date &date) |
Compare julian dates if not same date. | |
String | operator() () |
Expression operator to return an ISO date string for the current julian date. | |
long | operator* () |
Access julian value. | |
long | operator- (Date &date) |
Operator to compute number of days between two dates. | |
bool | operator< (Date &date) |
Compare julian date if earlier than another date. | |
bool | operator<= (Date &date) |
Compare julian date if earlier than or equal to another date. | |
Date & | operator= (Date &date) |
Assign date from another date object. | |
bool | operator== (Date &date) |
Compare julian dates if same date. | |
bool | operator> (Date &date) |
Compare julian date if later than another date. | |
bool | operator>= (Date &date) |
Compare julian date if later than or equal to another date. | |
void | set (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. | |
![]() | |
int | getHour (void) |
Get hours from midnight. | |
int | getMinute (void) |
Get minutes from current hour. | |
int | getSecond (void) |
Get seconds from current minute. | |
bool | operator!= (Time &time) |
Compare time with another time to see if not same time. | |
String | operator() () |
Convert to standard 24 hour time string. | |
long | operator* () |
Get object time in seconds. | |
long | operator- (Time &reference) |
Get difference (in seconds) between two times. | |
bool | operator< (Time &time) |
Compare time if earlier than another time. | |
bool | operator<= (Time &time) |
Compare time if earlier than or equal to another time. | |
Time & | operator= (Time &time) |
Assign a time as a copy of another time. | |
bool | operator== (Time &time) |
Compare time with another time to see if same time. | |
bool | operator> (Time &time) |
Compare time if later than another time. | |
bool | operator>= (Time &time) |
Compare time if later than or equal to another time. | |
int | operator[] (index_t component) |
Get component of time object. | |
void | set (char *pointer, size_t size=0) |
Set time from a hh:mm:ss formatted string. | |
Time (time_t value) | |
Create a time from the time portion of a time_t. | |
Time (tm_t *object) | |
Create a time from the time portion of a date and time object. | |
Time (char *pointer, size_t size=0) | |
Create a time from a hh:mm:ss formatted time string. | |
Time (int hour, int minute, int second) | |
Create a time from hours (0-23), minutes (0-59), and seconds (0-59). | |
Time (Time &object) | |
Create a time object from another object. | |
Time () | |
Create a time from current time. | |
virtual | ~Time () |
Destroy time object. |
Static Public Member Functions | |
static tm_t * | glt (time_t *time=((void *) 0)) |
Fetch an instance of time converted to local time. | |
static tm_t * | gmt (time_t *time=((void *) 0)) |
Fetch an instance of time converted to gmt. | |
static void | release (tm_t *object) |
Release a struct tm object from glt or gmt. |
Static Public Attributes | |
static long | c_day |
Constant for number of seconds in a day. | |
static long | c_hour |
Constant for number of seconds in a hour. | |
static long | c_week |
Constant for number of seconds in a week. | |
static size_t | sz_string |
Size of datetime string field. | |
![]() | |
![]() |
Protected Member Functions | |
void | update (void) |
A method to use to "post" any changed values when shadowing a mixed object class. | |
![]() | |
void | fromJulian (char *buf) |
void | toJulian (long year, long month, long day) |
![]() | |
void | fromSeconds (char *buf) |
void | toSeconds (int hour, int minute=0, int second=0) |
Additional Inherited Members | |
![]() | |
long | julian |
![]() | |
long | seconds |
The Datetime class uses a julian date representation of the current year, month, and day and a integer representation of the current time.
This is then manipulated in several forms and may be exported as needed.
Definition at line 620 of file datetime.h.
ucommon::DateTime::DateTime | ( | time_t | time | ) |
Construct a date and time from C library time_t type.
time | type to make date and time from. |
ucommon::DateTime::DateTime | ( | tm_t * | tm | ) |
Construct a date and time from C library time structure.
tm | structure from C library (from glt or gmt). |
ucommon::DateTime::DateTime | ( | char * | pointer, |
size_t | size = 0 |
||
) |
Construct a date and time from ISO string buffer.
pointer | to string field holding date and time. |
size | of field if not null terminated string. |
ucommon::DateTime::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.
year | of object. |
month | of object (1-12). |
day | of month of object (1-31). |
hour | of object (0-23). |
minute | of object (0-59). |
second | of object (0-59). |
ucommon::DateTime::DateTime | ( | DateTime & | object | ) |
Create a datetime object from another object.
object | to copy. |
String ucommon::DateTime::format | ( | char * | strftime | ) |
Return date and time formatted using strftime format values.
strftime | format to use. |
char* ucommon::DateTime::get | ( | char * | buffer | ) |
Get a ISO formatted date and time string for current object.
buffer | to store date and time in (yyyy-mm-dd hh:mm:ss). |
Reimplemented from ucommon::Date.
time_t ucommon::DateTime::get | ( | void | ) |
Get C library time_t type if object in C library epoch range.
Reimplemented from ucommon::Date.
|
static |
Fetch an instance of time converted to local time.
If the localtime abi is not re-entrant, than a lock is held, otherwise a unique object is returned. In either case, when you are done, you must release the object.
time | object or NULL if using current time. |
|
static |
Fetch an instance of time converted to gmt.
If the gmtime abi is not re-entrant, than a lock is held, otherwise a unique object is returned. In either case, when you are done, you must release the object.
time | object or NULL if using current time. |
bool ucommon::DateTime::isValid | ( | void | ) |
ucommon::DateTime::operator bool | ( | ) |
Test is date and time is valid for is() operator.
Reimplemented from ucommon::Date.
ucommon::DateTime::operator double | ( | ) |
Convert date and time to julian day number.
|
inline |
Casting operator to return date as number.
Reimplemented from ucommon::Date.
Definition at line 844 of file datetime.h.
bool ucommon::DateTime::operator! | ( | ) |
bool ucommon::DateTime::operator!= | ( | DateTime & | datetime | ) |
Compare date and time with another date and time to see if not same.
datetime | to compare with. |
DateTime ucommon::DateTime::operator+ | ( | long | seconds | ) |
Add seconds to datetime in an expression.
Day overflows update julian date.
seconds | to add to datetime. |
Reimplemented from ucommon::Date.
DateTime& ucommon::DateTime::operator++ | ( | ) |
Add a day from the current date and time.
Reimplemented from ucommon::Date.
DateTime& ucommon::DateTime::operator+= | ( | long | seconds | ) |
Add seconds to the current datetime object.
Day overflows update julian date.
seconds | to add to object. |
Reimplemented from ucommon::Date.
long ucommon::DateTime::operator- | ( | DateTime & | datetime | ) |
Operator to compute number of days between two dates.
datetime | to offset from for computation. |
DateTime ucommon::DateTime::operator- | ( | long | seconds | ) |
Subtract seconds from datetime in an expression.
Day underflows update julian date.
seconds | to subtract from datetime. |
Reimplemented from ucommon::Date.
DateTime& ucommon::DateTime::operator-- | ( | ) |
Subtract a day from the current date and time.
Reimplemented from ucommon::Date.
DateTime& ucommon::DateTime::operator-= | ( | long | seconds | ) |
Subtract seconds from current datetime object.
Day underflows update julian date.
seconds | to subtract from object. |
Reimplemented from ucommon::Date.
bool ucommon::DateTime::operator< | ( | DateTime & | datetime | ) |
Compare date and time with another date and time to see if earlier.
datetime | to compare with. |
bool ucommon::DateTime::operator<= | ( | DateTime & | datetime | ) |
Compare date and time with another date and time to see if earlier or the same.
datetime | to compare with. |
Assign date and time from another datetime object.
datetime | object to assign from. |
bool ucommon::DateTime::operator== | ( | DateTime & | datetime | ) |
Compare date and time with another date and time to see if the same.
datetime | to compare with. |
bool ucommon::DateTime::operator> | ( | DateTime & | datetime | ) |
Compare date and time with another date and time to see if later.
datetime | to compare with. |
bool ucommon::DateTime::operator>= | ( | DateTime & | datetime | ) |
Compare date and time with another date and time to see if later or the same.
datetime | to compare with. |
int ucommon::DateTime::operator[] | ( | index_t | component | ) |
Access time components.
component | to access. |
Reimplemented from ucommon::Date.
|
static |
Release a struct tm object from glt or gmt.
object | to release. |
|
protectedvirtual |
A method to use to "post" any changed values when shadowing a mixed object class.
This is used by DateNumber and string classes.
Reimplemented from ucommon::Date.
Reimplemented in ucommon::DateTimeString.