C12Adapter Opensource C++ Interface
|
Value to represent a moment in time, consists of both date and time information. More...
Public Types | |
enum | MonthType { MonthJanuary = 1, MonthFebruary = 2, MonthMarch = 3, MonthApril = 4, MonthMay = 5, MonthJune = 6, MonthJuly = 7, MonthAugust = 8, MonthSeptember = 9, MonthOctober = 10, MonthNovember = 11, MonthDecember = 12 } |
Month enumeration type. More... | |
enum | DayOfWeekType { WeekdaySunday = 0, WeekdayMonday = 1, WeekdayTuesday = 2, WeekdayWednesday = 3, WeekdayThursday = 4, WeekdayFriday = 5, WeekdaySaturday = 6 } |
Week day constants. More... | |
enum | KindEnum { KindNull = 0, KindUnspecified = 1, KindUtc = 2, KindLocal = 3 } |
Kind of time. More... | |
typedef Mint64 | InternalTimeType |
Public Member Functions | |
MTime () | |
Default constructor, set the time to a null value. More... | |
MTime (struct tm *value) | |
Constructor, which initializes the object with the standard C structure tm pointer. More... | |
MTime (time_t value) | |
Constructor, which initializes the object with the standard C time_t value. More... | |
MTime (const MStdString &str) | |
Constructor, does conversion of time from string. More... | |
MTime (int year, int month, int days, int hours=0, int minutes=0, int seconds=0) | |
Constructor, which directly initializes the value with the given parameters. More... | |
MTime (const MTime &other) | |
Copy constructor, one which copies the time from the time value given. | |
virtual | ~MTime () |
Class destructor. | |
MTime & | operator= (const MTime &other) |
Assignment operator. | |
int | Compare (const MTime &) const |
Compare this time with another time, ternary outcome comparison operator. More... | |
bool | operator== (const MTime &other) const |
Equality test binary operator. More... | |
bool | operator!= (const MTime &other) const |
Inequality test binary operator. More... | |
bool | operator< (const MTime &other) const |
Less than test binary operator. More... | |
bool | operator> (const MTime &other) const |
Greater than test binary operator. More... | |
bool | operator<= (const MTime &other) const |
Less than or equal test binary operator. More... | |
bool | operator>= (const MTime &other) const |
Greater than or equal test binary operator. More... | |
MVariant | NewClone () const |
Reflection enabled copy constructor, creating an object embedded directly into MTime. | |
MVariant | Add (const MVariant &) const |
Add an object to time object and return the result, reflection-enabling service. More... | |
MVariant | Subtract (const MVariant &) const |
Subtract an object to time object and return the result, reflection-enabling service. More... | |
void | Set (int year, int month, int day, int hour=0, int minute=0, int second=0) |
Initializes time value with all time parameters such as date, and possibly time. More... | |
void | SetDate (int year, int month, int day) |
Initializes time value with date, reflective call. More... | |
struct tm * | GetTM (struct tm *tmBuffer) const |
Get the value of this object as a standard C structure tm. More... | |
void | SetTM (struct tm *) |
Set the value for this object from a value given as standard C structure tm. More... | |
DayOfWeekType | GetDayOfWeek () const |
Gets the day of the week. More... | |
int | GetWeekOfMonth (bool startsOnSunday) const |
Get the week of the month for the date. More... | |
int | GetWeekOfYear (bool startsOnSunday) const |
Get the week of the year for the date. More... | |
void | SetToNull () |
Set this time to null value. | |
MTime | AsDate () const |
Return the date fraction of this MTime object, does not change this object. More... | |
MStdString | AsFormattedString (MConstChars formatString) const |
AsFormattedString time using standard C function strftime as formatter. More... | |
bool | IsNull () const |
Returns whether this time is a null time, a special value that tells that the time is not initialized. More... | |
void | CheckIfNotNull () const |
Check if this time is not null. More... | |
int | GetNumberOfDaysInThisMonth () const |
Get number of days in specified year and month. More... | |
bool | IsThisYearLeap () |
Tells if This year is a leap year. More... | |
virtual unsigned | GetEmbeddedSizeof () const |
Time is an embedded object type, therefore return its size in bytes. More... | |
time_t | GetTimeT () const |
void | SetTimeT (time_t value) |
double | GetSecondsSince1970 () const |
void | SetSecondsSince1970 (double seconds) |
int | GetYear () const |
void | SetYear (int) |
int | GetDayOfMonth () const |
void | SetDayOfMonth (int) |
int | GetDayOfYear () const |
void | SetDayOfYear (int) |
int | GetMonth () const |
void | SetMonth (int) |
int | GetHours () const |
void | SetHours (int) |
int | GetMinutes () const |
void | SetMinutes (int) |
int | GetSeconds () const |
void | SetSeconds (int) |
MStdString | AsString () const |
void | SetAsString (const MStdString &) |
![]() | |
virtual | ~MObject () |
Object destructor. | |
virtual const MClass * | GetClass () const =0 |
Get the final class of the object. More... | |
bool | IsEmbeddedObject () const |
Tell if the object is of embedded kind. More... | |
SHOW_INTERNAL MVariant | Call (const MStdString &name, const MVariant ¶ms) |
Call the object service with parameters, given as variant. More... | |
MVariant | Call0 (const MStdString &name) |
Call the object service with no parameters. More... | |
MVariant | Call1 (const MStdString &name, const MVariant &p1) |
Call the object service with one parameter. More... | |
MVariant | Call2 (const MStdString &name, const MVariant &p1, const MVariant &p2) |
Call the object service with two parameter. More... | |
MVariant | Call3 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3) |
Call the object service with three parameter. More... | |
MVariant | Call4 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4) |
Call the object service with four parameter. More... | |
MVariant | Call5 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5) |
Call the object service with five parameter. More... | |
MVariant | Call6 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5, const MVariant &p6) |
Call the object service with six parameter. More... | |
virtual MVariant | CallV (const MStdString &name, const MVariant::VariantVector ¶ms) |
Call the object service with parameters, given as variant vector. More... | |
virtual bool | IsPropertyPresent (const MStdString &name) const |
Tell if the property with the given name exists. | |
virtual bool | IsServicePresent (const MStdString &name) const |
Tell if the service with the given name exists. | |
virtual MVariant | GetProperty (const MStdString &name) const |
Get the property value using name of the property. More... | |
virtual void | SetProperty (const MStdString &name, const MVariant &value) |
Set the property using name of the property, and value. More... | |
virtual MStdStringVector | GetAllPropertyNames () const |
Return the list of publicly available properties, persistent or not. More... | |
virtual MStdStringVector | GetAllPersistentPropertyNames () const |
Return the list of persistent properties. More... | |
virtual void | SetPersistentPropertiesToDefault () |
Set the persistent properties of the object to their default values. More... | |
virtual MVariant | GetPersistentPropertyDefaultValue (const MStdString &name) const |
Get the default value of persistent property with the name given. More... | |
virtual void | SetPersistentPropertyToDefault (const MStdString &name) |
Set the persistent property with the name given to default value. More... | |
virtual const char * | GetType () const |
Get the name of the type for the object (could be the same as class name). | |
virtual void | SetType (const MStdString &) |
Intentionally, it will set the name of the type for the object, but the service will not allow setting the name to anything other than the current name. More... | |
virtual void | Validate () |
Validate internal structures of the object. More... | |
Static Public Member Functions | |
static InternalTimeType | GetUtcSecondsSince1970 () |
Get Greenwich Mean Time (or UTC). More... | |
static MTime | GetCurrentUtcTime () |
Get Greenwich Mean Time (or UTC). | |
static MTime | GetCurrentLocalTime () |
Get local time according to the current computer settings. More... | |
static MTime | GetCurrentStandardTime () |
Get current standard time according to the current computer settings. More... | |
static int | GetNumberOfDaysInMonth (int year, int month) |
Get number of days in specified year and month. More... | |
static bool | IsLeapYear (int year) |
Tells if a given year is a leap year. More... | |
static int | Year2to4 (int year) |
Convert two-digit year number to four-digit according to the currently active calendar conventions. More... | |
static int | Year4to2 (int year) |
Convert four-digit year number to two-digit according to the currently active calendar conventions. More... | |
![]() | |
static const MClass * | GetStaticClass () |
Get the declared class of this particular object. More... | |
static bool | IsClassPresent (const MStdString &name) |
Tells if the given class name is available. More... | |
Static Public Attributes | |
static const MTime | s_null |
Null time constant value, similar to NULL for pointers. More... | |
static const int | s_leapYearDays [13] |
Array that consists of the cumulative number of days in leap year. | |
static const int | s_nonLeapYearDays [13] |
Array that consists of the cumulative number of days in non-leap year. | |
![]() | |
static const MClass | s_class |
Class of MObject. | |
Friends | |
M_FUNC MTime & | operator+= (MTime &, const MTimeSpan &) |
Add time span to this time and assign the result back to time. More... | |
M_FUNC MTime & | operator-= (MTime &, const MTimeSpan &) |
Subtract time span to this time and assign the result back to time. More... | |
M_FUNC MTime | operator+ (const MTime &, const MTimeSpan &) |
Add a time span to time value, and without changing the two, return the result. More... | |
M_FUNC MTime | operator+ (const MTimeSpan &, const MTime &) |
Add a time span to time value, and without changing the two, return the result. More... | |
M_FUNC MTime | operator- (const MTime &, const MTimeSpan &) |
Subtract a time span from time value, and without changing the two, return the result. More... | |
M_FUNC MTimeSpan | operator- (const MTime &, const MTime &) |
Subtract one time value from another and return the resultant time span. More... | |
Additional Inherited Members | |
![]() | |
MObject () | |
Object constructor, protected as the class is abstract. | |
void | DoSetPersistentPropertiesToDefault (const MClass *staticClass) |
Set the persistent properties to their default values for one object provided the class for that object. More... | |
Value to represent a moment in time, consists of both date and time information.
The time range currently supported is from year 1970 to year 2099 inclusively, and the class is tested against Year 2038 problem, http://en.wikipedia.org/wiki/Year_2038_problem. Attempts to manipulate out of range dates will lead to a bad date exception. During assignment of properties the following constraints should be met:
No DST or timezone transformation is done automatically within the class during manipulations with time. This is because the current computer timezone is not necessarily the one the applications manipulate. Because the object does not have a flag indicating whether the time is UTC or local, and the DST status is not available for the specific time, it is up to the user to manipulate the information consistently.
Among all available time functions, only AsFormattedString is based on the current computer's locale. Also, AsFormattedString exposes the current computer timezone with its Z format.
If MTime is created with no parameters, it will be initialized with null time, which is a special value, much like a NULL pointer. Null time value is also available as MTime::s_null static constant.
Attempts to change null time by ways other than full assignment of all time components will fail with No value exception.
One can nullify time value by either of the following sequences:
One cannot initialize the object by calling property setters on null time separately like this:
To work around such cases, one can start with initializing the object with the current time:
typedef Mint64 MTime::InternalTimeType |
Internal time type used by the class.
It is always 64-bit, independent on time_t size.
enum MTime::DayOfWeekType |
Week day constants.
The convention is that the week starts on Sunday (which is in fact culture-related).
enum MTime::KindEnum |
enum MTime::MonthType |
Month enumeration type.
Months correspond to their ordinal numbers. The interface of MTime prefers to use int data type for month.
|
inline |
Default constructor, set the time to a null value.
Null value is indistinguishable from "1970-01-01 00:00:00"
|
inlineexplicit |
Constructor, which initializes the object with the standard C structure tm pointer.
The pointer given is not constant, and the constructor can modify the value it points to by setting the day of week and the other data within the structure.
The following integer fields within tm structure need to be initialized for the call to succeed:
Field tm_wday, day of week, 0 .. 6 starts from Sunday, and field tm_yday, day in the year, 0 .. 365, Starts from January 1 as zero day, get initialized inside the call.
|
inlineexplicit |
Constructor, which initializes the object with the standard C time_t value.
value | Number of seconds since January 1, 1970. In some 32-bit systems where time_t is defined as a 32-bit integral type, after 2038 the value of time_t will become negative. When properly handled, this is not an issue. |
|
inlineexplicit |
Constructor, does conversion of time from string.
str | Time given as string, shall correctly represent time in one of the following formats, shown as example: "2014-04-13 10:10:59", "2014-04-13 10:10" or "2014-04-13" |
|
inline |
Constructor, which directly initializes the value with the given parameters.
Add an object to time object and return the result, reflection-enabling service.
This service has little use in C++, but it is made for reflection.
MTime MTime::AsDate | ( | ) | const |
Return the date fraction of this MTime object, does not change this object.
MStdString MTime::AsFormattedString | ( | MConstChars | formatString | ) | const |
AsFormattedString time using standard C function strftime as formatter.
formatString | Format string, similar to formats supported by ANSI C function strflime(). |
The following is a full list of supported formats:
Infixes '#' and '@' in the above formats are:
Infixes are ignored in formats for which they have no effect.
MStdString MTime::AsString | ( | ) | const |
Represent this time as string in a most general way. Dependency on the current locale is watched.
void MTime::CheckIfNotNull | ( | ) | const |
Check if this time is not null.
int MTime::Compare | ( | const MTime & | ) | const |
Compare this time with another time, ternary outcome comparison operator.
|
static |
Get local time according to the current computer settings.
Note that the local time respects the DST status, while GetCurrentStandardTime does not.
|
static |
Get current standard time according to the current computer settings.
Note that the standard time does not respect the DST status, while GetCurrentLocalTime does.
int MTime::GetDayOfMonth | ( | ) | const |
Gets the day of month.
Month value in range 1 to 12. If the time is null, accessing this property results in No Value exception.
DayOfWeekType MTime::GetDayOfWeek | ( | ) | const |
Gets the day of the week.
Value is in range 0 to 6, Sunday to Saturday. If the time is null, accessing this property results in No Value exception.
int MTime::GetDayOfYear | ( | ) | const |
Day of the year starting from January 1 as day one.
Value is in range 1 to 366. If the time is null, accessing this property results in No Value exception.
|
virtual |
int MTime::GetHours | ( | ) | const |
Hours part of time of the day.
Value is in range 0 to 23. If the time is null, accessing this property results in No Value exception.
int MTime::GetMinutes | ( | ) | const |
Minutes part of time of the day.
Value is in range 0 to 59. If the time is null, accessing this property results in No Value exception.
int MTime::GetMonth | ( | ) | const |
Month number within the year of the time event.
Value is in range 1 to 12. If the time is null, accessing this property results in No Value exception.
|
static |
Get number of days in specified year and month.
Year needs to be specified to determine the number of days in February.
|
inline |
Get number of days in specified year and month.
Year needs to be specified to determine the number of days in February.
int MTime::GetSeconds | ( | ) | const |
Seconds part of time of the day.
Value is in range 0 to 59. If the time is null, accessing this property results in No Value exception.
|
inline |
Read-write property that allows handling of time object as the number of seconds since 1970.
Number of seconds since UNIX epoch, 1970, is a widely used way of representing time, and for compatibility reason, this property handles it as double precision floating point value.
|
inline |
Value of this object from a value given as time_t.
There is no implicit conversion between object and time_t to prevent misuse. For the same reason the constructor that takes time_t is declared explicit.
struct tm* MTime::GetTM | ( | struct tm * | tmBuffer | ) | const |
Get the value of this object as a standard C structure tm.
The buffer shall be provided, which is different from the standard C function gmtime.
|
static |
Get Greenwich Mean Time (or UTC).
This function is the analog of standard C runtime function time(), but it fixes a known problem with Borland C runtime, where it accounts for US timesavings only.
int MTime::GetWeekOfMonth | ( | bool | startsOnSunday | ) | const |
Get the week of the month for the date.
When the returned value is zero it means the date is part of the week that belongs to the previous month. This would be the case of April 1 if it is Friday, for example.
startsOnSunday | If the week starts on Sunday, otherwise the week starts on Monday. |
int MTime::GetWeekOfYear | ( | bool | startsOnSunday | ) | const |
Get the week of the year for the date.
startsOnSunday | If the week starts on Sunday, otherwise the week starts on Monday. |
int MTime::GetYear | ( | ) | const |
The year part of time value.
Year value supported is 1970 to 2099. If the time is null, accessing this property results in No Value exception.
|
static |
Tells if a given year is a leap year.
The algorithm is that the leap year must be divisible by 4. If the year is on a century boundary (divisible by 100), then it is only a leap year if the year is divisible by 400.
|
inline |
Returns whether this time is a null time, a special value that tells that the time is not initialized.
One can nullify time value by the following sequence:
|
inline |
Tells if This year is a leap year.
Returns information about This time object, not about the current year.
The algorithm is that the leap year must be divisible by 4. If the year is on a century boundary (divisible by 100), then it is only a leap year if the year is divisible by 400.
|
inline |
Inequality test binary operator.
Null time is equal to the other null time, and different with any other time.
|
inline |
Less than test binary operator.
|
inline |
Less than or equal test binary operator.
|
inline |
Equality test binary operator.
Null time is equal to the other null time, and different with any other time.
|
inline |
Greater than test binary operator.
|
inline |
Greater than or equal test binary operator.
void MTime::Set | ( | int | year, |
int | month, | ||
int | day, | ||
int | hour = 0 , |
||
int | minute = 0 , |
||
int | second = 0 |
||
) |
Initializes time value with all time parameters such as date, and possibly time.
Daylight saving time or local timezone are not taken into consideration.
void MTime::SetAsString | ( | const MStdString & | ) |
Represent this time as string in a most general way. Dependency on the current locale is watched.
|
inline |
Initializes time value with date, reflective call.
Daylight saving time or local timezone are not taken into consideration.
void MTime::SetDayOfMonth | ( | int | ) |
Gets the day of month.
Month value in range 1 to 12. If the time is null, accessing this property results in No Value exception.
void MTime::SetDayOfYear | ( | int | ) |
Day of the year starting from January 1 as day one.
Value is in range 1 to 366. If the time is null, accessing this property results in No Value exception.
void MTime::SetHours | ( | int | ) |
Hours part of time of the day.
Value is in range 0 to 23. If the time is null, accessing this property results in No Value exception.
void MTime::SetMinutes | ( | int | ) |
Minutes part of time of the day.
Value is in range 0 to 59. If the time is null, accessing this property results in No Value exception.
void MTime::SetMonth | ( | int | ) |
Month number within the year of the time event.
Value is in range 1 to 12. If the time is null, accessing this property results in No Value exception.
void MTime::SetSeconds | ( | int | ) |
Seconds part of time of the day.
Value is in range 0 to 59. If the time is null, accessing this property results in No Value exception.
|
inline |
Read-write property that allows handling of time object as the number of seconds since 1970.
Number of seconds since UNIX epoch, 1970, is a widely used way of representing time, and for compatibility reason, this property handles it as double precision floating point value.
|
inline |
Value of this object from a value given as time_t.
There is no implicit conversion between object and time_t to prevent misuse. For the same reason the constructor that takes time_t is declared explicit.
void MTime::SetTM | ( | struct tm * | ) |
Set the value for this object from a value given as standard C structure tm.
The following integer fields within tm structure need to be initialized for the call to succeed:
The following integer fields are initialized inside the call:
void MTime::SetYear | ( | int | ) |
The year part of time value.
Year value supported is 1970 to 2099. If the time is null, accessing this property results in No Value exception.
Subtract an object to time object and return the result, reflection-enabling service.
This service has little use in C++, but it is made for reflection.
|
static |
Convert two-digit year number to four-digit according to the currently active calendar conventions.
The current year number switch point is 90. This service is helpful for abbreviated time handling.
year | The two-digit year in range 0 to 99. Exception is thrown otherwise. |
|
static |
Convert four-digit year number to two-digit according to the currently active calendar conventions.
The current year number switch point is 90. This service is helpful for meter time handling.
year | The full four digit year in range 1990 to 2089, otherwise an exception is thrown. |
Add a time span to time value, and without changing the two, return the result.
Add a time span to time value, and without changing the two, return the result.
Add time span to this time and assign the result back to time.
Subtract a time span from time value, and without changing the two, return the result.
Subtract one time value from another and return the resultant time span.
Subtract time span to this time and assign the result back to time.
|
static |
Null time constant value, similar to NULL for pointers.
It can be used to refer to uninitialized time value.