CONZEPT 16 C++ API
C16::Value::Moment Class Reference

Absolute point in time. More...

#include "C16/Value/Moment.hpp"

Detailed Description

Absolute point in time.

Static Public Attributes

static const int YEAR_EPOCH = 1601
 Epoch year of moments. More...
 
static const int YEAR_MINIMUM = 1601
 Minimum year of a moment. More...
 
static const int YEAR_MAXIMUM = 30000
 Maximum year of a moment. More...
 
static const Moment EMPTY
 Empty moment (00000-00-00, 00:00:00). More...
 
static const Moment MINIMUM
 Minimum moment (01601-01-01, 00:00:00). More...
 
static const Moment MAXIMUM
 Maximum moment (30000-12-31, 23:59:59.9999999). More...
 

Static Public Member Functions

static Moment now ()
 Gets the current moment (UTC) of the system. More...
 
static Moment now_local ()
 Gets the current moment of the local timezone of the system. More...
 
static bool leap_year (int year)
 Gets if a year is a leap year. More...
 
static int days_in_month (int year, int month)
 Gets the days in a month. More...
 
static bool validate (int year, int month, int day, int hours=0, int minutes=0, int seconds=0, long int decimicroseconds=0)
 Validates a moment by means of its year, month, day (of the month), hours, minutes, seconds and decimicroseconds. More...
 
static bool validate (long long int serial)
 Validates a moment by means of its serial in units of decimicroseconds since the epoch. More...
 
static void validate_throw (int year, int month, int day, int hours=0, int minutes=0, int seconds=0, long int decimicroseconds=0)
 Validates a moment by means of its year, month, day (of the month), hours, minutes, seconds and decimicroseconds. More...
 
static void validate_throw (long long int serial)
 Validates a moment by means of its serial in units of decimicroseconds since the epoch. More...
 

Public Member Functions

 Moment ()
 Constructs an empty moment. More...
 
 Moment (int year, int month, int day, int hours=0, int minutes=0, int seconds=0, long int decimicroseconds=0)
 Constructs a moment by means of its year, month, day (of the month), hours, minutes, seconds and decimicroseconds. More...
 
 Moment (long long int serial)
 Constructs a moment by means of a serial in units of decimicroseconds since the epoch. More...
 
 Moment (const Date &date, const Time &time)
 Constructs a moment by means of a date and time. More...
 
 Moment (const Moment &other)
 Constructs a moment by copying another moment. More...
 
Momentoperator= (const Moment &other)
 Assigns the moment from another moment. More...
 
int compare (const Moment &other) const
 Compares the moment with another moment. More...
 
bool operator== (const Moment &other) const
 Gets if the moment is equal to another moment. More...
 
bool operator!= (const Moment &other) const
 Gets if the moment is unequal to another moment. More...
 
bool operator< (const Moment &other) const
 Gets if the moment is earlier than another moment. More...
 
bool operator<= (const Moment &other) const
 Gets if the moment is equal to or earlier than another moment. More...
 
bool operator>= (const Moment &other) const
 Gets if the moment is equal to or later than another moment. More...
 
bool operator> (const Moment &other) const
 Gets if the moment is later than another moment. More...
 
bool empty () const
 Gets if the moment is empty. More...
 
int year () const
 Gets the year of the moment. More...
 
int month () const
 Gets the month of the moment. More...
 
int day () const
 Gets the day (of the month) of the moment. More...
 
int day_of_year () const
 Gets the day of the year of the moment. More...
 
int day_of_week () const
 Gets the day of the week of the moment. More...
 
int week () const
 Gets the week (according to ISO 8601) of the moment. More...
 
int week_year () const
 Gets the year of the week (according to ISO 8601) of the moment. More...
 
bool leap_year () const
 Gets if the moment lies in a leap year. More...
 
int hours () const
 Gets the hours of the moment. More...
 
int minutes () const
 Gets the minutes of the moment since the last hour. More...
 
int seconds () const
 Gets the seconds of the moment since the last minute. More...
 
int centiseconds () const
 Gets the centiseconds of the moment since the last second. More...
 
int milliseconds () const
 Gets the milliseconds of the moment since the last second. More...
 
long int microseconds () const
 Gets the microseconds of the moment since the last second. More...
 
long int decimicroseconds () const
 Gets the decimicroseconds of the moment since the last second. More...
 
long int nanoseconds () const
 Gets the nanoseconds of the moment since the last second. More...
 
long long int serial () const
 Gets the serial of the moment in units of decimicroseconds since the epoch. More...
 
void clear ()
 Empties the moment. More...
 
void assign (int year, int month, int day, int hours=0, int minutes=0, int seconds=0, long int decimicroseconds=0)
 Assigns the moment by means of its year, month, day (of the month), hours, minutes, seconds and decimicroseconds. More...
 
void assign (long long int serial)
 Assigns the moment by means of its serial in units of decimicroseconds since the epoch. More...
 
void assign (const Date &date, const Time &time)
 Assigns the moment by means of a date and time. More...
 
Date date () const
 Gets the date of the moment. More...
 
Time time () const
 Gets the time of the moment. More...
 

Member Data Documentation

◆ YEAR_EPOCH

const int C16::Value::Moment::YEAR_EPOCH = 1601
static

Epoch year of moments.

◆ YEAR_MINIMUM

const int C16::Value::Moment::YEAR_MINIMUM = 1601
static

Minimum year of a moment.

◆ YEAR_MAXIMUM

const int C16::Value::Moment::YEAR_MAXIMUM = 30000
static

Maximum year of a moment.

◆ EMPTY

const Moment C16::Value::Moment::EMPTY
static

Empty moment (00000-00-00, 00:00:00).

◆ MINIMUM

const Moment C16::Value::Moment::MINIMUM
static

Minimum moment (01601-01-01, 00:00:00).

◆ MAXIMUM

const Moment C16::Value::Moment::MAXIMUM
static

Maximum moment (30000-12-31, 23:59:59.9999999).

Constructor & Destructor Documentation

◆ Moment() [1/5]

C16::Value::Moment::Moment ( )

Constructs an empty moment.

◆ Moment() [2/5]

C16::Value::Moment::Moment ( int  year,
int  month,
int  day,
int  hours = 0,
int  minutes = 0,
int  seconds = 0,
long int  decimicroseconds = 0 
)

Constructs a moment by means of its year, month, day (of the month), hours, minutes, seconds and decimicroseconds.

Parameters
yearYear of the moment (YEAR_MINIMUM to YEAR_MAXIMUM)
monthMonth of the moment (1 to 12)
dayDay (of the month) of the moment (1 to days_in_month)
hoursHours of the moment (0 to 23)
minutesMinutes of the moment since the last hour (0 to 59)
secondsSeconds of the moment since the last minute (0 to 59)
decimicrosecondsDecimicroseconds of the moment since the last second (0 to 9,999,999)
Exceptions
Exception::InvalidityYear invalid.
Exception::InvalidityMonth invalid.
Exception::InvalidityDay invalid.
Exception::InvalidityHours invalid.
Exception::InvalidityMinutes invalid.
Exception::InvaliditySeconds invalid.
Exception::InvalidityDecimicroseconds invalid.

◆ Moment() [3/5]

C16::Value::Moment::Moment ( long long int  serial)
explicit

Constructs a moment by means of a serial in units of decimicroseconds since the epoch.

Parameters
serialSerial of the moment (0 to MAXIMUM.serial())
Exceptions
Exception::InvaliditySerial invalid.

◆ Moment() [4/5]

C16::Value::Moment::Moment ( const Date date,
const Time time 
)

Constructs a moment by means of a date and time.

Parameters
dateDate of the moment
timeTime of the moment
Exceptions
Exception::InvalidityDate invalid.
Date empty.
Exception::InvalidityTime invalid.
Time empty.

◆ Moment() [5/5]

C16::Value::Moment::Moment ( const Moment other)

Constructs a moment by copying another moment.

Parameters
otherAnother moment

Member Function Documentation

◆ now()

static Moment C16::Value::Moment::now ( )
static

Gets the current moment (UTC) of the system.

Exceptions
Exception::InvalidityYear invalid.
Year of current moment (UTC) of the system is an invalid year of moment (YEAR_MINIMUM to YEAR_MAXIMUM).

◆ now_local()

static Moment C16::Value::Moment::now_local ( )
static

Gets the current moment of the local timezone of the system.

Exceptions
Exception::InvalidityYear invalid.
Year of current moment of the local timezone of the system is an invalid year of moment (YEAR_MINIMUM to YEAR_MAXIMUM).

◆ leap_year() [1/2]

static bool C16::Value::Moment::leap_year ( int  year)
static

Gets if a year is a leap year.

Parameters
yearYear (YEAR_MINIMUM to YEAR_MAXIMUM)
Exceptions
Exception::InvalidityYear invalid.

◆ days_in_month()

static int C16::Value::Moment::days_in_month ( int  year,
int  month 
)
static

Gets the days in a month.

Parameters
yearYear of the month (YEAR_MINIMUM to YEAR_MAXIMUM)
monthMonth (1 to 12)
Exceptions
Exception::InvalidityYear invalid.
Exception::InvalidityMonth invalid.

◆ validate() [1/2]

static bool C16::Value::Moment::validate ( int  year,
int  month,
int  day,
int  hours = 0,
int  minutes = 0,
int  seconds = 0,
long int  decimicroseconds = 0 
)
static

Validates a moment by means of its year, month, day (of the month), hours, minutes, seconds and decimicroseconds.

Parameters
yearYear of the moment (YEAR_MINIMUM to YEAR_MAXIMUM)
monthMonth of the moment (1 to 12)
dayDay (of the month) of the moment (1 to days_in_month)
hoursHours of the moment (0 to 23)
minutesMinutes of the moment since the last hour (0 to 59)
secondsSeconds of the moment since the last minute (0 to 59)
decimicrosecondsDecimicroseconds of the moment since the last second (0 to 9,999,999)
Returns
Validity of the moment

◆ validate() [2/2]

static bool C16::Value::Moment::validate ( long long int  serial)
static

Validates a moment by means of its serial in units of decimicroseconds since the epoch.

Parameters
serialSerial of the moment (0 to MAXIMUM.serial())
Returns
Validity of the moment

◆ validate_throw() [1/2]

static void C16::Value::Moment::validate_throw ( int  year,
int  month,
int  day,
int  hours = 0,
int  minutes = 0,
int  seconds = 0,
long int  decimicroseconds = 0 
)
static

Validates a moment by means of its year, month, day (of the month), hours, minutes, seconds and decimicroseconds.

Parameters
yearYear of the moment (YEAR_MINIMUM to YEAR_MAXIMUM)
monthMonth of the moment (1 to 12)
dayDay (of the month) of the moment (1 to days_in_month)
hoursHours of the moment (0 to 23)
minutesMinutes of the moment since the last hour (0 to 59)
secondsSeconds of the moment since the last minute (0 to 59)
decimicrosecondsDecimicroseconds of the moment since the last second (0 to 9,999,999)
Exceptions
Exception::InvalidityYear invalid.
Exception::InvalidityMonth invalid.
Exception::InvalidityDay invalid.
Exception::InvalidityHours invalid.
Exception::InvalidityMinutes invalid.
Exception::InvaliditySeconds invalid.
Exception::InvalidityDecimicroseconds invalid.

◆ validate_throw() [2/2]

static void C16::Value::Moment::validate_throw ( long long int  serial)
static

Validates a moment by means of its serial in units of decimicroseconds since the epoch.

Parameters
serialSerial of the moment (0 to MAXIMUM.serial())
Exceptions
Exception::InvaliditySerial invalid.

◆ operator=()

Moment& C16::Value::Moment::operator= ( const Moment other)

Assigns the moment from another moment.

Parameters
otherAnother moment
Returns
This moment

◆ compare()

int C16::Value::Moment::compare ( const Moment other) const

Compares the moment with another moment.

Parameters
otherAnother moment
Returns
Difference of the moment
Return values
0The moment is equal to the other moment.
< 0The moment is earlier than the other moment.
> 0The moment is later than the other moment.

◆ operator==()

bool C16::Value::Moment::operator== ( const Moment other) const

Gets if the moment is equal to another moment.

Parameters
otherAnother moment

◆ operator!=()

bool C16::Value::Moment::operator!= ( const Moment other) const

Gets if the moment is unequal to another moment.

Parameters
otherAnother moment

◆ operator<()

bool C16::Value::Moment::operator< ( const Moment other) const

Gets if the moment is earlier than another moment.

Parameters
otherAnother moment

◆ operator<=()

bool C16::Value::Moment::operator<= ( const Moment other) const

Gets if the moment is equal to or earlier than another moment.

Parameters
otherAnother moment

◆ operator>=()

bool C16::Value::Moment::operator>= ( const Moment other) const

Gets if the moment is equal to or later than another moment.

Parameters
otherAnother moment

◆ operator>()

bool C16::Value::Moment::operator> ( const Moment other) const

Gets if the moment is later than another moment.

Parameters
otherAnother moment

◆ empty()

bool C16::Value::Moment::empty ( ) const

Gets if the moment is empty.

◆ year()

int C16::Value::Moment::year ( ) const

Gets the year of the moment.

Return values
0Moment empty.

◆ month()

int C16::Value::Moment::month ( ) const

Gets the month of the moment.

Return values
0Moment empty.

◆ day()

int C16::Value::Moment::day ( ) const

Gets the day (of the month) of the moment.

Return values
0Moment empty.

◆ day_of_year()

int C16::Value::Moment::day_of_year ( ) const

Gets the day of the year of the moment.

Return values
0Moment empty.

◆ day_of_week()

int C16::Value::Moment::day_of_week ( ) const

Gets the day of the week of the moment.

Return values
0Moment empty.
1Monday
2Tuesday
3Wednesday
4Thursday
5Friday
6Saturday
7Sunday

◆ week()

int C16::Value::Moment::week ( ) const

Gets the week (according to ISO 8601) of the moment.

Return values
0Moment empty.

◆ week_year()

int C16::Value::Moment::week_year ( ) const

Gets the year of the week (according to ISO 8601) of the moment.

Return values
0Moment empty.

◆ leap_year() [2/2]

bool C16::Value::Moment::leap_year ( ) const

Gets if the moment lies in a leap year.

Note
Returns false if empty.

◆ hours()

int C16::Value::Moment::hours ( ) const

Gets the hours of the moment.

Note
Returns 0 if empty.

◆ minutes()

int C16::Value::Moment::minutes ( ) const

Gets the minutes of the moment since the last hour.

Note
Returns 0 if empty.

◆ seconds()

int C16::Value::Moment::seconds ( ) const

Gets the seconds of the moment since the last minute.

Note
Returns 0 if empty.

◆ centiseconds()

int C16::Value::Moment::centiseconds ( ) const

Gets the centiseconds of the moment since the last second.

Note
Returns 0 if empty.

◆ milliseconds()

int C16::Value::Moment::milliseconds ( ) const

Gets the milliseconds of the moment since the last second.

Note
Returns 0 if empty.

◆ microseconds()

long int C16::Value::Moment::microseconds ( ) const

Gets the microseconds of the moment since the last second.

Note
Returns 0 if empty.

◆ decimicroseconds()

long int C16::Value::Moment::decimicroseconds ( ) const

Gets the decimicroseconds of the moment since the last second.

Note
Returns 0 if empty.

◆ nanoseconds()

long int C16::Value::Moment::nanoseconds ( ) const

Gets the nanoseconds of the moment since the last second.

Note
Returns 0 if empty.

◆ serial()

long long int C16::Value::Moment::serial ( ) const

Gets the serial of the moment in units of decimicroseconds since the epoch.

Note
Returns 0 if empty.

◆ clear()

void C16::Value::Moment::clear ( )

Empties the moment.

◆ assign() [1/3]

void C16::Value::Moment::assign ( int  year,
int  month,
int  day,
int  hours = 0,
int  minutes = 0,
int  seconds = 0,
long int  decimicroseconds = 0 
)

Assigns the moment by means of its year, month, day (of the month), hours, minutes, seconds and decimicroseconds.

Parameters
yearYear of the moment (YEAR_MINIMUM to YEAR_MAXIMUM)
monthMonth of the moment (1 to 12)
dayDay (of the month) of the moment (1 to days_in_month)
hoursHours of the moment (0 to 23)
minutesMinutes of the moment since the last hour (0 to 59)
secondsSeconds of the moment since the last minute (0 to 59)
decimicrosecondsDecimicroseconds of the moment since the last second (0 to 9,999,999)
Exceptions
Exception::InvalidityYear invalid.
Exception::InvalidityMonth invalid.
Exception::InvalidityDay invalid.
Exception::InvalidityHours invalid.
Exception::InvalidityMinutes invalid.
Exception::InvaliditySeconds invalid.
Exception::InvalidityDecimicroseconds invalid.

◆ assign() [2/3]

void C16::Value::Moment::assign ( long long int  serial)

Assigns the moment by means of its serial in units of decimicroseconds since the epoch.

Parameters
serialSerial of the moment (0 to MAXIMUM.serial())
Exceptions
Exception::InvaliditySerial invalid.

◆ assign() [3/3]

void C16::Value::Moment::assign ( const Date date,
const Time time 
)

Assigns the moment by means of a date and time.

Parameters
dateDate of the moment
timeTime of the moment
Exceptions
Exception::InvalidityDate invalid.
Date empty.
Exception::InvalidityTime invalid.
Time empty.

◆ date()

Date C16::Value::Moment::date ( ) const

Gets the date of the moment.

Return values
Date::EMPTYMoment empty.
Exceptions
Exception::InvalidityYear invalid.
Year of moment is an invalid year of date (Date::YEAR_MINIMUM to Date::YEAR_MAXIMUM).

◆ time()

Time C16::Value::Moment::time ( ) const

Gets the time of the moment.

Return values
Time::EMPTYMoment empty.