libUTL++
|
Date/time. More...
#include <Time.h>
Public Member Functions | |
Time (const String &fmt, const String &str) | |
Constructor. More... | |
Time (uint_t year, uint_t month=1, uint_t day=1, uint_t hour=0, uint_t min=0, double sec=0, bool isGMT=false) | |
Constructor. More... | |
Time (time_t t) | |
Constructor. More... | |
virtual int | compare (const Object &rhs) const |
Compare with another object. More... | |
virtual void | copy (const Object &rhs) |
Copy another instance. More... | |
virtual void | serialize (Stream &stream, uint_t io, uint_t mode=ser_default) |
Serialize to or from a stream. More... | |
Accessors | |
operator time_t () const | |
Return a time_t representation. More... | |
time_t | get () const |
Get the time as a time_t value. More... | |
void | getComponents (uint_t *year, uint_t *month, uint_t *day, uint_t *wday=nullptr, uint_t *hour=nullptr, uint_t *min=nullptr, double *sec=nullptr, bool *isDST=nullptr, bool isGMT=false) const |
Get the year, month, and day. More... | |
bool | isNull () const |
Get the Null flag. More... | |
void | setNull () |
Set to null. More... | |
uint_t | getYear () const |
Get the year. More... | |
uint_t | getMonth () const |
Get the month. More... | |
uint_t | getDay () const |
Get the day. More... | |
uint_t | getDayOfWeek () const |
Get the day of week [0 = Sunday, . More... | |
uint_t | getHour () const |
Get the hour [0,23]. More... | |
uint_t | getMin () const |
Get the minute [0,59]. More... | |
uint_t | getSec () const |
Get the second [0,59]. More... | |
uint_t | getTimeOfDay () const |
Get the number of seconds since midnight. More... | |
uint_t | maxDay () const |
Get the last day of this month. More... | |
void | set (time_t dateTime) |
Set with a time_t value. More... | |
void | set (uint_t year, uint_t month, uint_t day, uint_t hour=0, uint_t min=0, double sec=0, bool isGMT=false) |
Set a new date/time. More... | |
Time & | setCurrent () |
Set to the current time. More... | |
String Representation | |
virtual String | toString () const |
Return a string representation of self. More... | |
String | toString (const String &fmt) const |
Return a string representation of self. More... | |
String | toGMTstring () const |
Return a string represenation of self (in GMT). More... | |
String | toGMTstring (const String &fmt) const |
Return a string representation of self. More... | |
void | set (const String &fmt, const String &str) |
Set with a string. More... | |
Rounding | |
Time & | roundDown (uint_t unit) |
Round down to the given unit. More... | |
Time & | roundDown (const Duration &dur) |
Round down to the given resolution. More... | |
Time & | roundUp (uint_t unit) |
Round up to the given unit. More... | |
Time & | roundUp (const Duration &dur) |
Round up to the given resolution. More... | |
Operators | |
Time & | operator= (time_t t) |
Assignment from time_t. More... | |
Time | operator+ (int i) const |
Return self plus the given number of seconds. More... | |
Time | operator+ (const Duration &rhs) const |
Return self plus the given duration. More... | |
Time | operator- (const Duration &rhs) const |
Return self minus the given duration. More... | |
Time | operator- (int i) const |
Return self minus the given number of seconds. More... | |
Duration | operator- (const Time &rhs) const |
Return self minus the given time. More... | |
const Time & | operator+= (const Duration &rhs) |
Add the given duration to self. More... | |
const Time & | operator-= (const Duration &rhs) |
Subtract the given duration from self. More... | |
![]() | |
void | clear () |
Revert to initial state. More... | |
virtual void | vclone (const Object &rhs) |
Make an exact copy of another instance. More... | |
virtual void | steal (Object &rhs) |
"Steal" the internal representation from another instance. More... | |
virtual void | dump (Stream &os, uint_t level=uint_t_max) const |
Dump a human-readable representation of self to the given output stream. More... | |
void | dumpWithClassName (Stream &os, uint_t indent=4, uint_t level=uint_t_max) const |
Front-end for dump() that prints the object's class name. More... | |
virtual const Object & | getKey () const |
Get the key for this object. More... | |
bool | hasKey () const |
Determine whether or not the object has a key. More... | |
virtual const Object & | getProxiedObject () const |
Get the proxied object (= self if none). More... | |
virtual Object & | getProxiedObject () |
Get the proxied object (= self if none). More... | |
virtual size_t | hash (size_t size) const |
Get the hash code for the object. More... | |
bool | _isA (const RunTimeClass *runTimeClass) const |
Determine whether self's class is a descendent of the given class. More... | |
operator String () const | |
Conversion to String. More... | |
size_t | allocatedSize () const |
Get the total allocated size of this object. More... | |
virtual size_t | innerAllocatedSize () const |
Get the "inner" allocated size. More... | |
virtual void | addOwnedIt (const class FwdIt *it) const |
Notify self that it owns the given iterator. More... | |
virtual void | removeOwnedIt (const class FwdIt *it) const |
Notify self that the given owned iterator has been destroyed. More... | |
bool | operator< (const Object &rhs) const |
Less-than operator. More... | |
bool | operator<= (const Object &rhs) const |
Less-than-or-equal-to operator. More... | |
bool | operator> (const Object &rhs) const |
Greater-than operator. More... | |
bool | operator>= (const Object &rhs) const |
Greater-than-or-equal-to operator. More... | |
bool | operator== (const Object &rhs) const |
Equal-to operator. More... | |
bool | operator!= (const Object &rhs) const |
Unequal-to operator. More... | |
void | serializeIn (Stream &is, uint_t mode=ser_default) |
Serialize from an input stream. More... | |
void | serializeOut (Stream &os, uint_t mode=ser_default) const |
Serialize to an output stream. More... | |
void | serializeOutBoxed (Stream &os, uint_t mode=ser_default) const |
Serialize a boxed object to an output stream. More... | |
Static Public Member Functions | |
Current Time | |
static Time | current () |
Return the current time. More... | |
static Time | today (uint_t hour=0, uint_t min=0, double sec=0) |
Return a Time object for the current date at the given time. More... | |
![]() | |
static Object * | serializeInNullable (Stream &is, uint_t mode=ser_default) |
Serialize a nullptr-able object from an input stream. More... | |
static void | serializeOutNullable (const Object *object, Stream &os, uint_t mode=ser_default) |
Serialize a nullptr-able object to an output stream. More... | |
static void | serializeNullable (Object *&object, Stream &stream, uint_t io, uint_t mode=ser_default) |
Serialize a nullptr-able object to or from a stream. More... | |
static Object * | serializeInBoxed (Stream &is, uint_t mode=ser_default) |
Serialize a boxed object from an input stream. More... | |
static void | serializeBoxed (Object *&object, Stream &stream, uint_t io, uint_t mode=ser_default) |
Serialize a boxed object to or from a stream. More... | |
Static Public Attributes | |
static const char * | abbrevWeekDayName [7] |
Abbreviated weekday names. More... | |
static const char * | weekDayName [7] |
Weekday names. More... | |
static const char * | abbrevMonthName [12] |
Abbreviated month names. More... | |
static const char * | monthName [12] |
Month names. More... | |
static const uint_t | monthDays [12] |
Number of days in each month. More... | |
Date/time.
Getting a String Representation
A format string given to the toString() method contains special codes that are to be substituted with strings based on the represented time. The codes are always preceded by a $ character so the parser can recognize them. If you want to have a $ character in the format string without a format code, just put two in a row: $$.
The formatting codes for toString() are:
For example, suppose the represented time is June 15th 2000 5:43 pm DST. Here are some format strings and the corresponding results that toString() would provide.
When setting the time with a string, you provide two strings to set(). The first string is the format string that tells the parser what to expect in the second string which contains the string representation of the time. The formatting codes are not preceded by a $ character as they are with toString() because the format string contains only formatting codes.
Here are the format strings recognized by set():
|
inline |
Constructor.
year | year |
month | (optional : 1) month [1,12] |
day | (optional : 1) day [1,31] |
hour | (optional : 0) hour [0,23] |
min | (optional : 0) minute [0,59] |
sec | (optional : 0) second [0,59] |
isGMT | (optional : false) interpret as GMT ? (otherwise interpret as local time) |
Definition at line 174 of file Time.h.
References utl::min().
|
inline |
Constructor.
t | time_t value |
Definition at line 189 of file Time.h.
References utl::compare(), utl::copy(), utl::ser_default, and utl::serialize().
|
virtual |
Compare with another object.
If no overridden version succeeds in doing the comparison, then an attempt will be made to re-start the comparison process using one or both of the objects' keys. Usually, an override of compare() should call the superclass's compare() if it doesn't know how to compare itself with the rhs object.
rhs | object to compare with |
Reimplemented from utl::Object.
|
virtual |
Copy another instance.
When you override copy(), you should usually call the superclass's copy().
rhs | object to copy |
Reimplemented from utl::Object.
|
virtual |
Serialize to or from a stream.
This is the only virtual method for serialization. You must override this in any class that has data to be serialized, and ensure that the superclass's serialize() gets called.
stream | stream to serialize from/to |
io | see utl::io_t |
mode | see utl::serialize_t |
Reimplemented from utl::Object.
|
inline |
|
inline |
void utl::Time::getComponents | ( | uint_t * | year, |
uint_t * | month, | ||
uint_t * | day, | ||
uint_t * | wday = nullptr , |
||
uint_t * | hour = nullptr , |
||
uint_t * | min = nullptr , |
||
double * | sec = nullptr , |
||
bool * | isDST = nullptr , |
||
bool | isGMT = false |
||
) | const |
Get the year, month, and day.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
uint_t utl::Time::maxDay | ( | ) | const |
Get the last day of this month.
|
inline |
void utl::Time::set | ( | uint_t | year, |
uint_t | month, | ||
uint_t | day, | ||
uint_t | hour = 0 , |
||
uint_t | min = 0 , |
||
double | sec = 0 , |
||
bool | isGMT = false |
||
) |
Set a new date/time.
year | year |
month | (optional : 1) month [1,12] |
day | (optional : 1) day [1,31] |
hour | (optional : 0) hour [0,23] |
min | (optional : 0) minute [0,59] |
sec | (optional : 0) second [0,59] |
isGMT | (optional : false) interpret as GMT ? (interpret as local time if false) |
|
inline |
Set to the current time.
Definition at line 337 of file Time.h.
References utl::roundDown(), utl::roundUp(), and utl::toString().
Referenced by current().
|
virtual |
Return a string representation of self.
Reimplemented from utl::Object.
Return a string representation of self.
fmt | format string |
String utl::Time::toGMTstring | ( | ) | const |
Return a string represenation of self (in GMT).
Return a string representation of self.
fmt | format string |
Set with a string.
fmt | format string |
str | string representation |
Round down to the given unit.
unit | unit (see utl::tm_unit_t) |
Round down to the given resolution.
dur | rounding resolution |
Round up to the given unit.
unit | unit (see utl::tm_unit_t) |
Round up to the given resolution.
dur | rounding resolution |
|
inline |
|
inline |
Return self plus the given duration.
Definition at line 417 of file Time.h.
References utl::Number< T >::get().
Return self minus the given duration.
Definition at line 425 of file Time.h.
References utl::Number< T >::get().
|
inline |
Add the given duration to self.
Definition at line 442 of file Time.h.
References utl::Number< T >::get().
Subtract the given duration from self.
Definition at line 449 of file Time.h.
References utl::Number< T >::get().
|
inlinestatic |
Return a Time object for the current date at the given time.
hour | (optional : 0) hour [0,23] |
min | (optional : 0) minute [0,59] |
sec | (optional : 0) second [0,59] |
|
static |
|
static |
|
static |
|
static |
|
static |