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 &date)
 Copy Constructor. More...
 
 Date (super &&date)
 
 Date (int year, int month, int date, int hour=0, int min=0, int sec=0)
 Construct from date elements. More...
 
 Date (const std::string &str)
 Construct from string. More...
 
 Date (long long linuxTime)
 Construct from linux_time. More...
 
void set (const WeakString &wstr)
 Setter by string. More...
 
void set (int year, int month, int date, int hour=0, int min=0, int sec=0)
 Setter by elements of date. More...
 
void set (long long linuxTime)
 Setter by linux_time. 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 getHour () const -> int
 Get hour. More...
 
auto getMinute () const -> int
 Get minute. More...
 
auto getSecond () const -> int
 Get second. More...
 
void setYear (int year)
 Set year of the Date. More...
 
void setMonth (int month)
 Set month of the Date. More...
 
void setDate (int val)
 
void setHour (int val)
 Set hour. More...
 
void setMinute (int val)
 Set minute. More...
 
void setSecond (int val)
 Set hour. More...
 
void addYear (int val)
 Add years to the Date. More...
 
void addMonth (int val)
 Add months to the Date. More...
 
void addWeek (int val)
 Add weeks to the Date. More...
 
void addDate (int val)
 Add days to the Date. More...
 
void addHour (int val)
 Add hours. More...
 
void addMinute (int val)
 Add minutes. More...
 
void addSecond (int val)
 Add seconds. More...
 
auto toTM () const -> struct::tm
 Converts the Date to struct tm. More...
 
auto toLinuxTime () const -> long long
 Converts the Date to linux_time. More...
 
auto toString () const -> std::string
 Converts the Date to std::string. More...
 

Static Private Member Functions

static auto calc_seconds (int year, int month, int date) -> long long
 Calculates how many seconds have flowen since 0000-01-01 00:00:00. More...
 
static auto calc_last_dates (int year) -> std::array< int, 12 >
 Calculates and gets an array of final date of each month for that year. 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 38 of file Date.hpp.

Constructor & Destructor Documentation

samchon::library::Date::Date ( )
inline

Default Constructor.

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

Definition at line 96 of file Date.hpp.

Referenced by Date().

Here is the caller graph for this function:

samchon::library::Date::Date ( const super &  date)
inline

Copy Constructor.

Copy the date from another Date

Parameters
dateTarget to be copied

Definition at line 106 of file Date.hpp.

samchon::library::Date::Date ( super &&  date)
inline

Move Constructor

Gets the date from other and truncate the other

Parameters
dateTarget to be moved

Definition at line 116 of file Date.hpp.

samchon::library::Date::Date ( int  year,
int  month,
int  date,
int  hour = 0,
int  min = 0,
int  sec = 0 
)
inline

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 128 of file Date.hpp.

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

Construct from string.

Parameters
strA string represents the date. (1991-01-01)
Exceptions
invalid_argumentmonth or date is invalid.

Definition at line 139 of file Date.hpp.

References Date().

Here is the call graph for this function:

samchon::library::Date::Date ( long long  linuxTime)
inline

Construct from linux_time.

Parameters
linuxTimelinux_time to be converted

Definition at line 154 of file Date.hpp.

Member Function Documentation

static auto samchon::library::Date::calc_seconds ( int  year,
int  month,
int  date 
) -> long long
inlinestaticprivate

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 50 of file Date.hpp.

References calc_last_dates().

Referenced by set().

Here is the call graph for this function:

Here is the caller graph for this function:

static auto samchon::library::Date::calc_last_dates ( int  year) -> std::array<int, 12>
inlinestaticprivate

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 74 of file Date.hpp.

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

Here is the caller graph for this function:

void samchon::library::Date::set ( const WeakString wstr)
inline

Setter by string.

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

Definition at line 165 of file Date.hpp.

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

Here is the call graph for this function:

void samchon::library::Date::set ( int  year,
int  month,
int  date,
int  hour = 0,
int  min = 0,
int  sec = 0 
)
inline

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 206 of file Date.hpp.

References calc_last_dates(), and calc_seconds().

Here is the call graph for this function:

void samchon::library::Date::set ( long long  linuxTime)
inline

Setter by linux_time.

Parameters
linuxTimelinux_time to be converted

Definition at line 227 of file Date.hpp.

auto samchon::library::Date::getYear ( ) const -> int
inline

Get year of the Date.

Returns
Year

Definition at line 246 of file Date.hpp.

References toTM().

Referenced by addMonth(), addYear(), setDate(), and setMonth().

Here is the call graph for this function:

Here is the caller graph for this function:

auto samchon::library::Date::getMonth ( ) const -> int
inline

Get month of the Date.

Returns
Month as integer (1: January, 12: December)

Definition at line 257 of file Date.hpp.

References toTM().

Referenced by addMonth(), setDate(), and setYear().

Here is the call graph for this function:

Here is the caller graph for this function:

auto samchon::library::Date::getDate ( ) const -> int
inline

Get the day in month of the Date.

Returns
Day in month (1 to 31)

Definition at line 268 of file Date.hpp.

References toTM().

Referenced by addMonth(), setMonth(), and setYear().

Here is the call graph for this function:

Here is the caller graph for this function:

auto samchon::library::Date::getDay ( ) const -> int
inline

Get the day in week of the Date.

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

Definition at line 279 of file Date.hpp.

References toTM().

Here is the call graph for this function:

auto samchon::library::Date::getHour ( ) const -> int
inline

Get hour.

Returns
hour of the Date to integer

Definition at line 290 of file Date.hpp.

References toTM().

Referenced by setHour().

Here is the call graph for this function:

Here is the caller graph for this function:

auto samchon::library::Date::getMinute ( ) const -> int
inline

Get minute.

Returns
minute of the Date to integer

Definition at line 301 of file Date.hpp.

References toTM().

Referenced by setMinute().

Here is the call graph for this function:

Here is the caller graph for this function:

auto samchon::library::Date::getSecond ( ) const -> int
inline

Get second.

Returns
second of the Date to integer

Definition at line 312 of file Date.hpp.

References toTM().

Referenced by setSecond().

Here is the call graph for this function:

Here is the caller graph for this function:

void samchon::library::Date::setYear ( int  year)
inline

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

Definition at line 333 of file Date.hpp.

References getDate(), and getMonth().

Referenced by addYear().

Here is the call graph for this function:

Here is the caller graph for this function:

void samchon::library::Date::setMonth ( int  month)
inline

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

Definition at line 365 of file Date.hpp.

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

Here is the call graph for this function:

void samchon::library::Date::setDate ( int  val)
inline

Set date of the Date

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

Definition at line 390 of file Date.hpp.

References getMonth(), and getYear().

Here is the call graph for this function:

void samchon::library::Date::setHour ( int  val)
inline

Set hour.

Parameters
valTarget hour (0 - 23)
Exceptions
invalid_argumentWhen hour is out of range

Definition at line 401 of file Date.hpp.

References addHour(), and getHour().

Here is the call graph for this function:

void samchon::library::Date::setMinute ( int  val)
inline

Set minute.

Parameters
valTarget minute (0 - 59)
Exceptions
invalid_argumentWhen minute is out of range

Definition at line 412 of file Date.hpp.

References addMinute(), and getMinute().

Here is the call graph for this function:

void samchon::library::Date::setSecond ( int  val)
inline

Set hour.

Parameters
valTarget second (0 - 59)
Exceptions
invalid_argumentWhen second is out of range

Definition at line 423 of file Date.hpp.

References addSecond(), and getSecond().

Here is the call graph for this function:

void samchon::library::Date::addYear ( int  val)
inline

Add years to the Date.

Parameters
valYears to add

Definition at line 437 of file Date.hpp.

References getYear(), and setYear().

Here is the call graph for this function:

void samchon::library::Date::addMonth ( int  val)
inline

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

Definition at line 452 of file Date.hpp.

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

Here is the call graph for this function:

void samchon::library::Date::addWeek ( int  val)
inline

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

Definition at line 485 of file Date.hpp.

References addDate().

Here is the call graph for this function:

void samchon::library::Date::addDate ( int  val)
inline

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

Definition at line 499 of file Date.hpp.

References addHour().

Referenced by addWeek().

Here is the call graph for this function:

Here is the caller graph for this function:

void samchon::library::Date::addHour ( int  val)
inline

Add hours.

It's same with operator+=(chrono::hours(val))

Do not worry about the out of range of the hour(val) Parent items like date, month and years will be adjusted automatically.

Parameters
valhours to add

Definition at line 515 of file Date.hpp.

Referenced by addDate(), and setHour().

Here is the caller graph for this function:

void samchon::library::Date::addMinute ( int  val)
inline

Add minutes.

It's same with operator+=(chrono::minutes(val))
Do not worry about the out of range of the minutes(val) Parent items like date, month and years will be adjusted automatically.
Parameters
valminutes to add

Definition at line 531 of file Date.hpp.

Referenced by setMinute().

Here is the caller graph for this function:

void samchon::library::Date::addSecond ( int  val)
inline

Add seconds.

It's same with operator+=(chrono::seconds(val))
Do not worry about the out of range of the seconds(val) Parent items like date, month and years will be adjusted automatically.
Parameters
valseconds to add

Definition at line 548 of file Date.hpp.

Referenced by setSecond().

Here is the caller graph for this function:

auto samchon::library::Date::toTM ( ) const -> struct ::tm
inline

Converts the Date to struct tm.

Returns
struct tm representing the Date

Definition at line 561 of file Date.hpp.

Referenced by getDate(), getDay(), getHour(), getMinute(), getMonth(), getSecond(), getYear(), and toString().

Here is the caller graph for this function:

auto samchon::library::Date::toLinuxTime ( ) const -> long long
inline

Converts the Date to linux_time.

Returns
linux_time of the Date

Definition at line 575 of file Date.hpp.

Referenced by samchon::protocol::WebServer::WebServer().

Here is the caller graph for this function:

auto samchon::library::Date::toString ( ) const -> std::string
inline

Converts the Date to std::string.

Returns
std::string expressing the Date

Definition at line 588 of file Date.hpp.

References samchon::library::StringUtil::substitute(), and toTM().

Here is the call graph for this function:


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