nlib
nn::nlib::DateTime Class Referencefinal

The class for representing the date and time. More...

#include "nn/nlib/DateTime.h"

Public Types

enum  Week {
  WEEK_SUNDAY = 0,
  WEEK_MONDAY,
  WEEK_TUESDAY,
  WEEK_WEDNESDAY,
  WEEK_THURSDAY,
  WEEK_FRIDAY,
  WEEK_SATURDAY
}
 Constants representing the days of the week. More...
 

Public Member Functions

errno_t Init (int year, int month, int day, int hour=0, int min=0, int sec=0, int msec=0, int usec=0) noexcept
 Initializes the time. More...
 
errno_t Init (const DateTimeParams &rhs) noexcept
 Initializes the date and time using the DateTimeParams structure. Returns EINVAL if given an invalid date.
 
errno_t Init (const TimeValue &tv) noexcept
 Initializes the date and time using the TimeValue structure. Returns EINVAL if given an invalid date.
 
errno_t GetDay (int *year, int *month, int *day) const noexcept
 Gets the year, month, and day. More...
 
errno_t GetTime (int *hour, int *min, int *sec, int *msec, int *usec) const noexcept
 Gets the time. More...
 
errno_t Get (DateTimeParams *rhs) const noexcept
 Gets the time. More...
 
TimeValue ToTimeValue () const noexcept
 Returns a TimeValue object.
 
bool IsValid () const noexcept
 Checks whether the time is valid. More...
 
errno_t GetDayOfYear (int *nth) const noexcept
 Gets the day of the year based on the specified date and time. More...
 
errno_t GetDayOfWeek (Week *week) const noexcept
 Gets what day of the week it is. More...
 
errno_t Add (const TimeSpan &rhs) noexcept
 Adds the duration specified in rhs to the date and time. More...
 
errno_t AddYears (int value) noexcept
 Adds the number of years specified in value to the date and time. More...
 
errno_t AddMonths (int value) noexcept
 Adds the number of months specified in value to the date and time. More...
 
errno_t AddDays (double value) noexcept
 Adds the number of days specified in value to the date and time. More...
 
errno_t AddHours (double value) noexcept
 Adds the number of hours specified in value to the date and time. More...
 
errno_t AddMinutes (double value) noexcept
 Adds the number of minutes specified in value to the date and time. More...
 
errno_t AddSeconds (double value) noexcept
 Adds the number of seconds specified in value to the date and time. More...
 
errno_t AddMilliSeconds (double value) noexcept
 Adds the number of milliseconds specified in value to the date and time. More...
 
errno_t AddMicroSeconds (double value) noexcept
 Adds the number of microseconds specified in value to the date and time. More...
 
errno_t ToW3cDtf (char(&str)[32], const TimeSpan &zone) const noexcept
 Outputs the date and time as a string in W3CDTF format. More...
 
errno_t ToW3cDtf (char(&str)[32]) const noexcept
 Calls ToW3cDtf(str, TimeSpan()).
 
errno_t ToRfc2822 (char(&str)[32], const TimeSpan &zone) const noexcept
 Outputs the date and time as a string in RFC 2822 format. More...
 
errno_t ToRfc2822 (char(&str)[32]) const noexcept
 Calls ToRfc2822(str, TimeSpan()).
 
errno_t ToAscTime (char(&str)[26]) const noexcept
 Outputs the date and time as a string in asctime format. Note that the string ends with a newline character. More...
 
 operator bool () const
 Returns true if the time being held is valid.
 
DateTimeoperator+= (const TimeSpan &rhs) noexcept
 Adds the time indicated by rhs.
 
DateTimeoperator-= (const TimeSpan &rhs) noexcept
 Subtracts the time indicated by rhs.
 
bool operator== (const DateTime &rhs) const noexcept
 Returns true if the time is equal to rhs.
 
bool operator!= (const DateTime &rhs) const noexcept
 Returns true if the time is not equal to rhs.
 
bool operator< (const DateTime &rhs) const noexcept
 Returns true if further in the past than rhs.
 
bool operator> (const DateTime &rhs) const noexcept
 Returns true if further in the future than rhs.
 
bool operator<= (const DateTime &rhs) const noexcept
 Returns true if the same or further in the past than rhs.
 
bool operator>= (const DateTime &rhs) const noexcept
 Returns true if the same or further in the future than rhs.
 
Basic Member Functions
constexpr DateTime () noexcept
 Instantiates the object with default parameters (default constructor). Initializes with an invalid time.
 

Static Public Member Functions

static bool IsLeapYear (int year) noexcept
 Checks whether the specified year is a leap year. More...
 
static errno_t GetNow (DateTime *p) noexcept
 Sets the DateTime object based on the current time. More...
 
static int GetDaysInMonth (int year, int month) noexcept
 Gets the number of days in a particular month, based on the specified year and month. More...
 
static errno_t Parse (const char *str, DateTime *dt, TimeSpan *delta) noexcept
 Parses the string that denotes the date and time and sets it in a DateTime object and a TimeSpan object. More...
 

Detailed Description

The class for representing the date and time.

Description
Represents the date and the time, between 00::00 of January 1 of the year 1, to 23:59:59.999 of December 31 of the year 9999. Each day is treated as having exactly 86,400 seconds.
The date and time is represented internally as a 64-bit integer value, where 1 = 100 nanoseconds. You can use the various member functions and operators to compare dates and times and to perform operations like addition and subtraction on them.
The addition and subtraction TimeSpan objects is also supported.
// Specifies a numerical value and sets the date.
dt.Init(1973, 11, 10);
// Sets the object based on the current time.
// Sets the object based on a string.
TimeSpan delta;
DateTime::Parse("1994-11-05T08:15:30-05:00", &dt, &delta);
// Advances by one month.
dt.AddMonths(1);
Examples:
misc/datetime/datetime.cpp, msgpack/jsonrpc/jsonrpc.cpp, and msgpack/jsonrpc/server.cpp.

Definition at line 249 of file DateTime.h.

Member Enumeration Documentation

Constants representing the days of the week.

Enumerator
WEEK_SUNDAY 

Sunday.

WEEK_MONDAY 

Monday.

WEEK_TUESDAY 

Tuesday.

WEEK_WEDNESDAY 

Wednesday.

WEEK_THURSDAY 

Thursday.

WEEK_FRIDAY 

Friday.

WEEK_SATURDAY 

Saturday.

Definition at line 252 of file DateTime.h.

Member Function Documentation

nn::nlib::DateTime::Add ( const TimeSpan rhs)
inlinenoexcept

Adds the duration specified in rhs to the date and time.

Parameters
[in]rhsA duration of time.
Returns
Returns 0 if successful, or ERANGE if DateTime is or will be invalid.

Definition at line 376 of file DateTime.h.

nn::nlib::DateTime::AddDays ( double  value)
inlinenoexcept

Adds the number of days specified in value to the date and time.

Parameters
[in]valueA number of days.
Returns
Returns 0 if successful, or ERANGE if DateTime is or will be invalid.

Definition at line 381 of file DateTime.h.

nn::nlib::DateTime::AddHours ( double  value)
inlinenoexcept

Adds the number of hours specified in value to the date and time.

Parameters
[in]valueA number of hours.
Returns
Returns 0 if successful, or ERANGE if DateTime is or will be invalid.

Definition at line 387 of file DateTime.h.

nn::nlib::DateTime::AddMicroSeconds ( double  value)
inlinenoexcept

Adds the number of microseconds specified in value to the date and time.

Parameters
[in]valueA number of microseconds.
Returns
Returns 0 if successful, or ERANGE if DateTime is or will be invalid.

Definition at line 411 of file DateTime.h.

nn::nlib::DateTime::AddMilliSeconds ( double  value)
inlinenoexcept

Adds the number of milliseconds specified in value to the date and time.

Parameters
[in]valueA number of milliseconds.
Returns
Returns 0 if successful, or ERANGE if DateTime is or will be invalid.

Definition at line 405 of file DateTime.h.

nn::nlib::DateTime::AddMinutes ( double  value)
inlinenoexcept

Adds the number of minutes specified in value to the date and time.

Parameters
[in]valueA number of minutes.
Returns
Returns 0 if successful, or ERANGE if DateTime is or will be invalid.

Definition at line 393 of file DateTime.h.

nn::nlib::DateTime::AddMonths ( int  value)
noexcept

Adds the number of months specified in value to the date and time.

Parameters
[in]valueA number of months.
Returns
Returns 0 if successful, or ERANGE if DateTime is or will be invalid.
Description
If the addition operations results in a date that does not exist (such as 2000-02-29), the value is set to the last day of the relevant month.
nn::nlib::DateTime::AddSeconds ( double  value)
inlinenoexcept

Adds the number of seconds specified in value to the date and time.

Parameters
[in]valueA number of seconds.
Returns
Returns 0 if successful, or ERANGE if DateTime is or will be invalid.

Definition at line 399 of file DateTime.h.

nn::nlib::DateTime::AddYears ( int  value)
noexcept

Adds the number of years specified in value to the date and time.

Parameters
[in]valueA number of years.
Returns
Returns 0 if successful, or ERANGE if DateTime is or will be invalid.
Description
If the addition operations results in a date that does not exist (such as 2000-02-29), the value is set to the last day of the relevant month.
nn::nlib::DateTime::Get ( DateTimeParams rhs) const
noexcept

Gets the time.

Parameters
[out]rhsThe pointer to the structure when the time is written.
Returns
Returns 0 if successful, or ERANGE if DateTime is invalid.
nn::nlib::DateTime::GetDay ( int *  year,
int *  month,
int *  day 
) const
noexcept

Gets the year, month, and day.

Parameters
[out]yearThe year (1-9999).
[out]monthThe month (1-12).
[out]dayThe day (1-).
Returns
Returns 0 if successful, or ERANGE if DateTime is invalid.
nn::nlib::DateTime::GetDayOfWeek ( Week week) const
noexcept

Gets what day of the week it is.

Parameters
[out]weekThe day of the week.
Returns
Returns 0 if successful, or ERANGE if DateTime is invalid.
nn::nlib::DateTime::GetDayOfYear ( int *  nth) const
noexcept

Gets the day of the year based on the specified date and time.

Parameters
[out]nthThe number of days since the start of the specified year, counted starting from 0.
Returns
Returns 0 if successful, or ERANGE if DateTime is invalid.
nn::nlib::DateTime::GetDaysInMonth ( int  year,
int  month 
)
staticnoexcept

Gets the number of days in a particular month, based on the specified year and month.

Parameters
[in]yearA year.
[in]monthA month.
Returns
The number of days in that month, or 0 if there was an error.
nn::nlib::DateTime::GetNow ( DateTime p)
staticnoexcept

Sets the DateTime object based on the current time.

Parameters
[out]pThe pointer to the DateTime.
Returns
Returns 0 if successful, and another value if the function fails.
nn::nlib::DateTime::GetTime ( int *  hour,
int *  min,
int *  sec,
int *  msec,
int *  usec 
) const
noexcept

Gets the time.

Parameters
[out]hourThe hour (1-23).
[out]minThe minute (0-59).
[out]secThe second (0-59).
[out]msecThe millisecond (0-999).
[out]usecThe microsecond (0-999).
Returns
Returns 0 if successful, or ERANGE if DateTime is invalid.
nn::nlib::DateTime::Init ( int  year,
int  month,
int  day,
int  hour = 0,
int  min = 0,
int  sec = 0,
int  msec = 0,
int  usec = 0 
)
noexcept

Initializes the time.

Parameters
[in]yearThe year (1-1999).
[in]monthThe month (1-12).
[in]dayThe day (1-).
[in]hourThe hour (0-23).
[in]minThe minute (0-59).
[in]secThe second (0-59).
[in]msecThe millisecond (0-999).
[in]usecThe microsecond (0-999999).
Returns
Returns 0 if successful, or EINVAL if an invalid date and time has been specified.
nn::nlib::DateTime::IsLeapYear ( int  year)
inlinestaticnoexcept

Checks whether the specified year is a leap year.

Parameters
[in]yearThe year to check.
Returns
Returns true if it is a leap year, and false otherwise.

Definition at line 358 of file DateTime.h.

nn::nlib::DateTime::IsValid ( ) const
noexcept

Checks whether the time is valid.

Returns
Returns true if the time is valid (that is, some time between 00::00 of January 1 of the year 1 and 23:59:59.999 of December 31 of the year 9999).
nn::nlib::DateTime::Parse ( const char *  str,
DateTime dt,
TimeSpan delta 
)
staticnoexcept

Parses the string that denotes the date and time and sets it in a DateTime object and a TimeSpan object.

Parameters
[in]strA string denoting the date and time.
[out]dtStores the date and time information.
[out]deltaStores the time zone information (for example, +09:00 hours).
Returns
Returns 0 if successful, and some other value if there was an error.
Description
Date and time notation now supports W3C-DTF (http://www.w3.org/TR/NOTE-datetime), RFC 2822 (https://www.ietf.org/rfc/rfc2822.txt), or asctime format.
The parsing supports W3CDTF date and time notation where '-' is replaced by '/' and 'T' is replaced by a blank space. In other words, the following non-standard strings can also be parsed.
  • 2012/09/10
  • 2012/09/10 17:27
nn::nlib::DateTime::ToAscTime ( char(&)  str[26]) const
noexcept

Outputs the date and time as a string in asctime format. Note that the string ends with a newline character.

Parameters
[out]strThe buffer for the 26-byte output string.
Returns
Returns 0 if successful, or ERANGE if DateTime is invalid.
nn::nlib::DateTime::ToRfc2822 ( char(&)  str[32],
const TimeSpan zone 
) const
noexcept

Outputs the date and time as a string in RFC 2822 format.

Parameters
[out]strThe buffer for the 32-byte output string.
[in]zoneThe time zone.
Returns
Returns 0 if successful, or ERANGE if DateTime is invalid.
nn::nlib::DateTime::ToW3cDtf ( char(&)  str[32],
const TimeSpan zone 
) const
noexcept

Outputs the date and time as a string in W3CDTF format.

Parameters
[out]strThe buffer for the 32-byte output string.
[in]zoneThe time zone.
Returns
Returns 0 if successful, or ERANGE if DateTime is invalid.

The documentation for this class was generated from the following files: