Samchon Framework for CPP  1.0.0
samchon::library::Date Class Reference

Date (year, month, day in month) More...

#include <Date.hpp>

Public Member Functions

 Date ()
 Default Constructor. More...
 
 Date (const super &)
 Copy Constructor. More...
 
 Date (super &&)
 
 Date (int year, int month, int date)
 Construct from date elements. More...
 
 Date (const std::string &)
 Construct from string. More...
 
 Date (const WeakString &)
 Construct from WeakString. More...
 
 Date (long long linuxTime)
 Construct from linux_time. More...
 
void set (const std::string &)
 Setter by string. More...
 
virtual void set (const WeakString &)
 Setter by weak_string. More...
 
void set (int year, int month, int date)
 Setter by elements of date. More...
 
void set (long long linuxTime)
 Setter by linux_time. More...
 
virtual void setYear (int)
 Set year of the Date. More...
 
virtual void setMonth (int)
 Set month of the Date. More...
 
virtual void setDate (int)
 
virtual void addYear (int)
 Add years to the Date. More...
 
virtual void addMonth (int)
 Add months to the Date. More...
 
virtual void addWeek (int)
 Add weeks to the Date. More...
 
virtual void addDate (int)
 Add days to the Date. More...
 
auto getYear () const -> int
 Get year of the Date. More...
 
auto getMonth () const -> int
 Get month of the Date. More...
 
auto getDate () const -> int
 Get the day in month of the Date. More...
 
auto getDay () const -> int
 Get the day in week of the Date. More...
 
auto toLinuxTime () const -> long long
 Converts the Date to linux_time. More...
 
virtual auto toString () const -> std::string
 Converts the Date to std::string. More...
 

Protected Member Functions

auto toTM () const -> struct::tm
 Converts the Date to struct tm. More...
 

Static Protected Member Functions

static auto calcSeconds (int year, int month, int date) -> long long
 Calculates how many seconds have flowen since 0000-01-01 00:00:00. More...
 
static auto calcLastDates (int year) -> std::array< int, 12 >
 Calculates and gets an array of final date of each month for that year. More...
 

Static Protected Attributes

static std::chrono::system_clock::time_point TP_1970 = chrono::system_clock::from_time_t(0)
 time_point for 1970-01-01 09:00:00 More...
 

Detailed Description

Date (year, month, day in month)

Date class is a chrono::time_point<std::chrono::system_clock>.

Date represents the date with year, month and day in month. The basic date (local time) is from your operating system.

[Inherited]

A time_point object expresses a point in time relative to a clock's epoch.

Internally, the object stores an object of a duration type, and uses the Clock type as a reference for its epoch.

Referenced comments of std::chrono::time_point

library_date.png
See also
samchon::library
Author
Jeongho Nam http://samchon.org

Definition at line 37 of file Date.hpp.

Constructor & Destructor Documentation

Date::Date ( )

Default Constructor.

The date will be now (Now's date from operating system)

Definition at line 18 of file Date.cpp.

Referenced by Date().

Here is the caller graph for this function:

Date::Date ( const super &  date)

Copy Constructor.

Copy the date from another Date

Parameters
dateTarget to be copied

Definition at line 23 of file Date.cpp.

Date::Date ( super &&  date)

Move Constructor

Gets the date from other and truncate the other

Parameters
dateTarget to be moved

Definition at line 27 of file Date.cpp.

Date::Date ( int  year,
int  month,
int  date 
)

Construct from date elements.

Parameters
yearex) 2015
monthJanuary to December. 1 ~ 12
dateday in month. 1 ~ 31
Exceptions
invalid_argumentmonth or date is invalid.

Definition at line 32 of file Date.cpp.

References Date().

Here is the call graph for this function:

samchon::library::Date::Date ( const std::string &  )

Construct from string.

Parameters
strA string represents the date. (1991-01-01)
Exceptions
invalid_argumentmonth or date is invalid.
Date::Date ( const WeakString wStr)

Construct from WeakString.

Parameters
strA weak_string expressing the date. (1991-01-01)
Exceptions
invalid_argumentmonth or date is invalid.

Definition at line 40 of file Date.cpp.

Date::Date ( long long  linuxTime)

Construct from linux_time.

Parameters
linuxTimelinux_time to be converted

Definition at line 44 of file Date.cpp.

References set().

Here is the call graph for this function:

Member Function Documentation

long long Date::calcSeconds ( int  year,
int  month,
int  date 
) -> long long
staticprotected

Calculates how many seconds have flowen since 0000-01-01 00:00:00.

This static method is used for calculate the linux_time (since 1970-01-01 09:00:00)

Returns
linux_time of the Date

Definition at line 109 of file Date.cpp.

References calcLastDates().

Referenced by set().

Here is the call graph for this function:

Here is the caller graph for this function:

auto Date::calcLastDates ( int  year) -> std::array<int, 12>
staticprotected

Calculates and gets an array of final date of each month for that year.

Parameters
yearThe target year
Returns
Array of fianl date of each month for that year

Definition at line 97 of file Date.cpp.

Referenced by addMonth(), calcSeconds(), set(), and setMonth().

Here is the caller graph for this function:

void samchon::library::Date::set ( const std::string &  )

Setter by string.

Parameters
strY-m-d
Exceptions
invalid_argumentmonth or date is invalid.

Referenced by Date(), and samchon::library::Datetime::set().

Here is the caller graph for this function:

void Date::set ( const WeakString wStr)
virtual

Setter by weak_string.

Parameters
wstrY-m-d
Exceptions
invalid_argumentmonth or date is invalid.

Reimplemented in samchon::library::Datetime.

Definition at line 54 of file Date.cpp.

References samchon::WeakString::between(), samchon::WeakString::find(), samchon::WeakString::split(), and samchon::WeakString::trim().

Here is the call graph for this function:

void Date::set ( int  year,
int  month,
int  date 
)

Setter by elements of date.

Parameters
yearex) 2015
monthJanuary to December. 1 ~ 12
dateday in month. 1 ~ 31
Exceptions
invalid_argumentmonth or date is invalid.

Definition at line 72 of file Date.cpp.

References calcLastDates(), and calcSeconds().

Here is the call graph for this function:

void Date::set ( long long  linuxTime)

Setter by linux_time.

Parameters
linuxTimelinux_time to be converted

Definition at line 84 of file Date.cpp.

void Date::setYear ( int  year)
virtual

Set year of the Date.

If previous date is leaf month's expiration date and target year what you want is not leaf, the date will be 28

  • 2000-02-29 -> setYear(2001) -> 2001-02-28
  • 2001-02-28 -> setYear(2000) -> 2000-02-08
Parameters
valTarget year

Reimplemented in samchon::library::Datetime.

Definition at line 131 of file Date.cpp.

References getDate(), and getMonth().

Referenced by addYear(), and samchon::library::Datetime::setYear().

Here is the call graph for this function:

Here is the caller graph for this function:

void Date::setMonth ( int  month)
virtual

Set month of the Date.

If the expiration date of the month will be shrinked, the date will be changed to the expiration date

  • 2000-03-31 -> setMonth(4) -> 2000-04-30
  • 2007-08-31 -> setMonth(9) -> 2007-09-30
Parameters
valTarget month (1 - 12)
Exceptions
invalid_argumentmonth is out of range

Reimplemented in samchon::library::Datetime.

Definition at line 150 of file Date.cpp.

References calcLastDates(), getDate(), and getYear().

Referenced by samchon::library::Datetime::setMonth().

Here is the call graph for this function:

Here is the caller graph for this function:

void Date::setDate ( int  val)
virtual

Set date of the Date

Parameters
valTarget day in month
Exceptions
invalid_argumentWhen date is over expiration date in month

Reimplemented in samchon::library::Datetime.

Definition at line 168 of file Date.cpp.

References getMonth(), and getYear().

Referenced by samchon::library::Datetime::setDate().

Here is the call graph for this function:

Here is the caller graph for this function:

void Date::addYear ( int  val)
virtual

Add years to the Date.

Parameters
valYears to add

Reimplemented in samchon::library::Datetime.

Definition at line 174 of file Date.cpp.

References getYear(), and setYear().

Referenced by samchon::library::Datetime::addYear().

Here is the call graph for this function:

Here is the caller graph for this function:

void Date::addMonth ( int  val)
virtual

Add months to the Date.

Not a matter to val is over 12. If the month is over 12, then years will be added.

Parameters
valMonths to add

Reimplemented in samchon::library::Datetime.

Definition at line 179 of file Date.cpp.

References calcLastDates(), getDate(), getMonth(), and getYear().

Referenced by samchon::library::Datetime::addMonth().

Here is the call graph for this function:

Here is the caller graph for this function:

void Date::addWeek ( int  val)
virtual

Add weeks to the Date.

Not a matter that val is too huge. If the adding weeks derives modification in month or year, then it will be.

Parameters
valWeeks to add

Reimplemented in samchon::library::Datetime.

Definition at line 202 of file Date.cpp.

References addDate().

Referenced by samchon::library::Datetime::addWeek().

Here is the call graph for this function:

Here is the caller graph for this function:

void Date::addDate ( int  val)
virtual

Add days to the Date.

Not a matter that val is too huge. If the adding dates derives modification in month or year, then it will be.

Parameters
valDays to add

Reimplemented in samchon::library::Datetime.

Definition at line 206 of file Date.cpp.

Referenced by samchon::library::Datetime::addDate(), and addWeek().

Here is the caller graph for this function:

int Date::getDay ( ) const -> int

Get the day in week of the Date.

Returns
Day in week to integer (0: Sunday, 1: Monday, ..., 6: Saturday)

Definition at line 231 of file Date.cpp.

References toTM().

Here is the call graph for this function:

auto Date::toTM ( ) const -> struct ::tm
protected

Converts the Date to struct tm.

Returns
struct tm representing the Date

Definition at line 242 of file Date.cpp.

Referenced by getDate(), getDay(), samchon::library::Datetime::getHour(), samchon::library::Datetime::getMinute(), getMonth(), samchon::library::Datetime::getSecond(), and getYear().

Here is the caller graph for this function:

auto Date::toLinuxTime ( ) const -> long long

Converts the Date to linux_time.

Returns
linux_time of the Date

Definition at line 214 of file Date.cpp.

References TP_1970.

Referenced by samchon::protocol::service::IPUserPair::issueSessionID().

Here is the caller graph for this function:

auto Date::toString ( ) const -> std::string
virtual

Converts the Date to std::string.

Returns
std::string expressing the Date

Reimplemented in samchon::library::Datetime.

Definition at line 250 of file Date.cpp.

References getDate(), getMonth(), getYear(), and samchon::library::StringUtil::substitute().

Referenced by samchon::library::Datetime::toString().

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

chrono::system_clock::time_point Date::TP_1970 = chrono::system_clock::from_time_t(0)
staticprotected

time_point for 1970-01-01 09:00:00

It's the zero(0) in linux_time

Definition at line 48 of file Date.hpp.

Referenced by toLinuxTime().


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