C12Adapter Opensource C++ Interface
MTime Class Reference

Value to represent a moment in time, consists of both date and time information. More...

Inheritance diagram for MTime:

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.
 
MTimeoperator= (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 &)
 
- Public Member Functions inherited from MObject
virtual ~MObject ()
 Object destructor.
 
virtual const MClassGetClass () 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 &params)
 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 &params)
 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 Public Member Functions inherited from MObject
static const MClassGetStaticClass ()
 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 Public Attributes inherited from MObject
static const MClass s_class
 Class of MObject.
 

Friends

M_FUNC MTimeoperator+= (MTime &, const MTimeSpan &)
 Add time span to this time and assign the result back to time. More...
 
M_FUNC MTimeoperator-= (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

- Protected Member Functions inherited from MObject
 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...
 

Detailed Description

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:

  • Year is bigger than or equal to 1970 and smaller than or equal to 2099.
  • Month is between 1 and 12.
  • DayOfMonth is between 1 and the number of days in the month, up to 31.
  • Hour is between 0 and 23.
  • Minute is between 0 and 59.
  • Second is between 0 and 59.

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:

time.SetToNull();
time = MTime();

One cannot initialize the object by calling property setters on null time separately like this:

MTime value;
value.SetYear(2002); // Exception here, attempt to modify a null time
value.SetMonth(4); // Unreachable code

To work around such cases, one can start with initializing the object with the current time:

MTime value = MTime::GetCurrentUtcTime(); // We are creating UTC
value.SetYear(2002); // Now it will work
value.SetMonth(4);

Member Typedef Documentation

typedef Mint64 MTime::InternalTimeType

Internal time type used by the class.

It is always 64-bit, independent on time_t size.

Member Enumeration Documentation

Week day constants.

The convention is that the week starts on Sunday (which is in fact culture-related).

Enumerator
WeekdaySunday 

Sunday, zero based, starts the week.

WeekdayMonday 

Monday, 1.

WeekdayTuesday 

Tuesday, 2.

WeekdayWednesday 

Wednesday, 3.

WeekdayThursday 

Thursday, 4.

WeekdayFriday 

Friday, 5.

WeekdaySaturday 

Saturday, 6.

Kind of time.

Enumerator
KindNull 

Null time, no value.

KindUnspecified 

Unspecified or unknown, but not null. Offset is zero.

KindUtc 

UTC time, offset is zero.

KindLocal 

LOcal time, offset is present (can be zero)

Month enumeration type.

Months correspond to their ordinal numbers. The interface of MTime prefers to use int data type for month.

Enumerator
MonthJanuary 

January.

MonthFebruary 

February.

MonthMarch 

March.

MonthApril 

April.

MonthMay 

May.

MonthJune 

June.

MonthJuly 

July.

MonthAugust 

August.

MonthSeptember 

September.

MonthOctober 

October.

MonthNovember 

November.

MonthDecember 

December.

Constructor & Destructor Documentation

MTime::MTime ( )
inline

Default constructor, set the time to a null value.

Null value is indistinguishable from "1970-01-01 00:00:00"

MTime::MTime ( struct tm *  value)
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:

  • tm_hour – Hours since midnight, 0 .. 23
  • tm_isdst – Positive value will mean daylight saving time is active; zero is that it is not active; negative value is for unknown status of DST.
  • tm_mday – Day of month, 1 .. 31
  • tm_min – Minutes after hour, 0 .. 59
  • tm_mon – Month, 0 .. 11, January is 0
  • tm_sec – Seconds, 0 .. 59
  • tm_year – Year (current year minus 1900)

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.

Precondition
A given pointer has to be properly initialized with a valid time value supported by this class (see above), or an exception is thrown.
MTime::MTime ( time_t  value)
inlineexplicit

Constructor, which initializes the object with the standard C time_t value.

Parameters
valueNumber 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.
MTime::MTime ( const MStdString str)
inlineexplicit

Constructor, does conversion of time from string.

Parameters
strTime 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"
MTime::MTime ( int  year,
int  month,
int  days,
int  hours = 0,
int  minutes = 0,
int  seconds = 0 
)
inline

Constructor, which directly initializes the value with the given parameters.

Precondition
Parameters must satisfy the Set precondition, be a valid time. Please see preconditions for Set.

Member Function Documentation

MVariant MTime::Add ( const MVariant ) const

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.

Precondition
The given object shall not be NULL, and shall be compatible for addition to time.
MTime MTime::AsDate ( ) const

Return the date fraction of this MTime object, does not change this object.

Precondition
Object is initialized.
MStdString MTime::AsFormattedString ( MConstChars  formatString) const

AsFormattedString time using standard C function strftime as formatter.

Precondition
Time is not null, or an exception is thrown. If the format is bad, an error is thrown.
Parameters
formatStringFormat string, similar to formats supported by ANSI C function strflime().

The following is a full list of supported formats:

  • "%%" – Replaced by a single %
  • "%c" – Date and time in a locale sensitive representation, current thread locale.
  • "%@c" – Date and time in a locale sensitive representation, current user locale.
  • "%d" – Two-digit day of month with possible leading zero, 01 .. 31.
  • "%#d" – Two-digit day of month without the leading zero, 1 .. 31.
  • "%H" – Hour, 24 hour format 01 .. 23.
  • "%#H" – Hour, 24 hour format without a leading zero 1 .. 23.
  • "%I" – Hour, 12 hour format 01 .. 12, note that this is upper case letter i.
  • "%#I" – Hour, 12 hour format without a leading zero 0 .. 12, note that this is upper case letter i.
  • "%j" – Day of year, 001 .. 366.
  • "%#j" – Day of year without leading zeros, 1 .. 366.
  • "%m" – Digits for month, 01 .. 12.
  • "%#m" – Digits for month without leading zero, 1 .. 12.
  • "%M" – Minute, 00 .. 59.
  • "%#M" – Minute without leading zero, 0 .. 59.
  • "%p" – Expands to AM or PM.
  • "%q" – Week of the current month, 00 .. 06, where week 01 is the first full week that starts on Sunday.
  • "%#q" – Week of the current month without leading zero, 0 .. 6, where week 1 is the first full week that starts on Sunday.
  • "%Q" – Week of the current month, 00 .. 06, where week 01 is the first full week that starts on Monday.
  • "%#Q" – Week of the current month without leading zero, 0 .. 6, where week 1 is the first full week that starts on Monday.
  • "%S" – Second, 00 .. 59.
  • "%#S" – Second without leading zero, 0 .. 59.
  • "%u" – Weekday, 1 .. 7, starting from Monday.
  • "%U" – Week of the current year, 00 .. 53, where 01 is the first Sunday.
  • "%#U" – Week of the current year, 0 .. 53, where 1 is the first Sunday.
  • "%w" – Weekday, 0 .. 6, starting from Sunday.
  • "%W" – Week of the current year, 00 .. 53, where 01 is the first Monday.
  • "%#W" – Week of the current year, 0 .. 53, where 1 is the first Monday.
  • "%x" – Date fraction in a locale sensitive representation, current thread locale.
  • "%@x" – Date fraction in a locale sensitive representation, current user locale.
  • "%X" – Time fraction in a locale sensitive representation, current thread locale.
  • "%@X" – Time fraction in a locale sensitive representation, current user locale.
  • "%y" – Two-digit year format, 00 .. 99.
  • "%#y" – Two-digit year without leading zero, 0 .. 99.
  • "%Y" – Full four-digit year.

Infixes '#' and '@' in the above formats are:

  • "#" Modifies the numeric formats so that the leading zeros are not written. Different from Microsoft Visual C++, this modifier has no effect on locale sensitive formats.
  • "@" Applies to locale dependent formats, and makes usage of user locale instead of thread locale.

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.

Precondition
Object is created. If object is null, then string is "0".
void MTime::CheckIfNotNull ( ) const

Check if this time is not null.

Precondition
If this time IsNull, the exception No Value is thrown.
int MTime::Compare ( const MTime ) const

Compare this time with another time, ternary outcome comparison operator.

Precondition
Objects are valid, not null, or an exception is thrown. It is not an error to compare an object with itself.
static MTime MTime::GetCurrentLocalTime ( )
static

Get local time according to the current computer settings.

Note that the local time respects the DST status, while GetCurrentStandardTime does not.

static MTime MTime::GetCurrentStandardTime ( )
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 unsigned MTime::GetEmbeddedSizeof ( ) const
virtual

Time is an embedded object type, therefore return its size in bytes.

Returns
Size of MTime in bytes.

Reimplemented from MObject.

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 int MTime::GetNumberOfDaysInMonth ( int  year,
int  month 
)
static

Get number of days in specified year and month.

Year needs to be specified to determine the number of days in February.

Precondition
Year shall be in range 1970 to 2099, and month shall be within 1 and 12, or an exception is thrown.
int MTime::GetNumberOfDaysInThisMonth ( ) const
inline

Get number of days in specified year and month.

Year needs to be specified to determine the number of days in February.

Precondition
Year shall be in range 1970 to 2099, and month shall be within 1 and 12, or an exception is thrown.
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.

double MTime::GetSecondsSince1970 ( ) const
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.

time_t MTime::GetTimeT ( ) const
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.

Precondition
The current time value shall not be null, or a null value exception is thrown.
static InternalTimeType MTime::GetUtcSecondsSince1970 ( )
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.

Parameters
startsOnSundayIf the week starts on Sunday, otherwise the week starts on Monday.
Returns
The week number in range that starts from 1 for the first week of the month.
int MTime::GetWeekOfYear ( bool  startsOnSunday) const

Get the week of the year for the date.

Parameters
startsOnSundayIf the week starts on Sunday, otherwise the week starts on Monday.
Returns
The week number that starts from 1 for the first week of the year.
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 bool MTime::IsLeapYear ( int  year)
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.

Precondition
Year shall be within 1970 to 2099, or an exception is thrown.
bool MTime::IsNull ( ) const
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:

Precondition
The object has to be valid, or an exception is thrown.
bool MTime::IsThisYearLeap ( )
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.

Precondition
Time shall not be Null, and year of the time shall be within 1970 to 2099, or an exception is thrown.
bool MTime::operator!= ( const MTime other) const
inline

Inequality test binary operator.

Null time is equal to the other null time, and different with any other time.

bool MTime::operator< ( const MTime other) const
inline

Less than test binary operator.

Precondition
Objects are valid, not null, or an exception is thrown. It is not an error to compare an object with itself.
bool MTime::operator<= ( const MTime other) const
inline

Less than or equal test binary operator.

Precondition
Objects are valid, not null, or an exception is thrown. It is not an error to compare an object with itself.
bool MTime::operator== ( const MTime other) const
inline

Equality test binary operator.

Null time is equal to the other null time, and different with any other time.

bool MTime::operator> ( const MTime other) const
inline

Greater than test binary operator.

Precondition
Objects are valid, not null, or an exception is thrown. It is not an error to compare an object with itself.
bool MTime::operator>= ( const MTime other) const
inline

Greater than or equal test binary operator.

Precondition
Objects are valid, not null, or an exception is thrown. It is not an error to compare an object with itself.
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.

Precondition
Parameters satisfy the following rules, which are the rules for a valid MTime object:
  • Year is bigger than 1970 and smaller than or equal to 2099.
  • Month is between 1 and 12.
  • Day is between 1 and the number of days in the month, up to 31.
  • Hour is between 0 and 23.
  • Minute is between 0 and 59.
  • Second is between 0 and 59.
Bad time value exception is thrown if any of these conditions are not met.
void MTime::SetAsString ( const MStdString )

Represent this time as string in a most general way. Dependency on the current locale is watched.

Precondition
Object is created. If object is null, then string is "0".
void MTime::SetDate ( int  year,
int  month,
int  day 
)
inline

Initializes time value with date, reflective call.

Daylight saving time or local timezone are not taken into consideration.

Precondition
Parameters satisfy the following rules, which are the rules for a valid MTime object:
  • Year is bigger than 1970 and smaller than 2099.
  • Month is between 1 and 12.
  • Day is between 1 and the number of days in the month, up to 31.
Bad time value exception is thrown if any of these conditions are not met.
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.

void MTime::SetSecondsSince1970 ( double  seconds)
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.

void MTime::SetTimeT ( time_t  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:

  • tm_year – Year (current year minus 1900).
  • tm_mon – Months since January, 0 .. 11, January is 0.
  • tm_mday – Day of the month, 1 .. 31.
  • tm_hour – Hours since midnight, 0 .. 23.
  • tm_min – Minutes after the hour, 0 .. 59.
  • tm_sec – Seconds after the minute, 0 .. 59.
  • tm_isdst – Positive value indicates that daylight saving time is active; zero indicates that daylight saving time is not active; negative value indicates that the daylight saving time status is unknown.

The following integer fields are initialized inside the call:

  • tm_wday – Days since Sunday, 0 .. 6, Sunday is 0.
  • tm_yday – Days since January 1, January 1 is 0.
Precondition
A given time value satisfies the range of the time object, see above. Otherwise an exception is thrown.
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.

MVariant MTime::Subtract ( const MVariant ) const

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.

Precondition
The given object shall not be NULL, and shall be compatible for addition to time.
static int MTime::Year2to4 ( int  year)
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.

Parameters
yearThe two-digit year in range 0 to 99. Exception is thrown otherwise.
Returns
Year in range 1990 to 2089.
static int MTime::Year4to2 ( int  year)
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.

Parameters
yearThe full four digit year in range 1990 to 2089, otherwise an exception is thrown.
Returns
Two-digit year 0 to 99.

Friends And Related Function Documentation

M_FUNC MTime operator+ ( const MTime ,
const MTimeSpan  
)
friend

Add a time span to time value, and without changing the two, return the result.

Precondition
Time shall not be null, or an exception is thrown.
M_FUNC MTime operator+ ( const MTimeSpan ,
const MTime  
)
friend

Add a time span to time value, and without changing the two, return the result.

Precondition
Time shall not be null, or an exception is thrown.
M_FUNC MTime& operator+= ( MTime ,
const MTimeSpan  
)
friend

Add time span to this time and assign the result back to time.

Precondition
Time shall not be null, or an exception is thrown.
M_FUNC MTime operator- ( const MTime ,
const MTimeSpan  
)
friend

Subtract a time span from time value, and without changing the two, return the result.

Precondition
Time shall not be null, or an exception is thrown.
M_FUNC MTimeSpan operator- ( const MTime ,
const MTime  
)
friend

Subtract one time value from another and return the resultant time span.

Precondition
Both times shall not be null, or an exception is thrown.
M_FUNC MTime& operator-= ( MTime ,
const MTimeSpan  
)
friend

Subtract time span to this time and assign the result back to time.

Precondition
Time shall not be null, or an exception is thrown.

Member Data Documentation

const MTime MTime::s_null
static

Null time constant value, similar to NULL for pointers.

It can be used to refer to uninitialized time value.