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

Date and time. More...

#include <Datetime.hpp>

Collaboration diagram for samchon::library::Datetime:

Public Member Functions

 Datetime ()
 
 Datetime (const std::chrono::system_clock::time_point &)
 Copy Constructor. More...
 
 Datetime (std::chrono::system_clock::time_point &&)
 
 Datetime (int year, int month, int date, int hour=0, int min=0, int sec=0)
 Construct from datetime elements. More...
 
 Datetime (const std::string &)
 Construct from string. More...
 
 Datetime (const WeakString &)
 Construct from WeakString. More...
 
 Datetime (long long linuxTime)
 Construct from linux_time. More...
 
void set (const std::string &)
 Setter by string. More...
 
virtual void set (const WeakString &) override
 deque by weak_string More...
 
void set (int year, int month, int date, int hours=0, int minutes=0, int seconds=0)
 
void set (long long linuxTime)
 
virtual void setYear (int)
 Set year of the Date. More...
 
virtual void setMonth (int)
 Set month of the Date. More...
 
virtual void setDate (int)
 
void setHour (int)
 Set hour. More...
 
void setMinute (int)
 Set minute. More...
 
void setSecond (int)
 Set hour. More...
 
virtual void addYear (int) override
 Add years to the Date. More...
 
virtual void addMonth (int) override
 Add months to the Date. More...
 
virtual void addWeek (int) override
 Add weeks to the Date. More...
 
virtual void addDate (int) override
 Add days to the Date. More...
 
void addHour (int)
 Add hours. More...
 
void addMinute (int)
 Add minutes. More...
 
void addSecond (int)
 Add seconds. More...
 
auto getHour () const -> int
 Get hour. More...
 
auto getMinute () const -> int
 Get minute. More...
 
auto getSecond () const -> int
 Get second. More...
 
virtual auto toString () const -> std::string override
 Converts the Datetime to std::string. More...
 
- Public Member Functions inherited from samchon::library::Date
 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...
 
void set (int year, int month, int date)
 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 toLinuxTime () const -> long long
 Converts the Date to linux_time. More...
 

Additional Inherited Members

- Protected Member Functions inherited from samchon::library::Date
auto toTM () const -> struct::tm
 Converts the Date to struct tm. More...
 
- Static Protected Member Functions inherited from samchon::library::Date
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 inherited from samchon::library::Date
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 and time.

Datetime is a Date having hours, minutes and seconds addictionally.

[Inherited]

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 19 of file Datetime.hpp.

Constructor & Destructor Documentation

Datetime::Datetime ( )

Default Constructor

The datetime will be now (Now from operating system)

Definition at line 15 of file Datetime.cpp.

Referenced by Datetime().

Here is the caller graph for this function:

samchon::library::Datetime::Datetime ( const std::chrono::system_clock::time_point &  )

Copy Constructor.

Copy the date from another Date

Parameters
dateTarget to be copied
samchon::library::Datetime::Datetime ( std::chrono::system_clock::time_point &&  )

Move Constructor

Gets the date from other and truncate the other

Parameters
dateTarget to be moved
Datetime::Datetime ( int  year,
int  month,
int  date,
int  hour = 0,
int  min = 0,
int  sec = 0 
)

Construct from datetime elements.

Parameters
yearex) 2015
monthJanuary to December. 1 ~ 12
dateDay in month. 1 ~ 31
hourHours (0-23)
minMinutes (0-59)
secSeconds (0-59)
Exceptions
invalid_argumentparameter is out of its own range.

Definition at line 27 of file Datetime.cpp.

References Datetime().

Here is the call graph for this function:

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

Construct from string.

Parameters
strA string representing the date. (1991-01-01 09:27:03)
Exceptions
invalid_argumentparameter is out of its own range.
Datetime::Datetime ( const WeakString wStr)

Construct from WeakString.

Parameters
wstrA weak_string expressing the date. (1991-01-01 09:27:03)
Exceptions
invalid_argumentparameter is out of its own range.

Definition at line 36 of file Datetime.cpp.

Datetime::Datetime ( long long  linuxTime)

Construct from linux_time.

Parameters
linuxTimelinux_time to be converted

Definition at line 41 of file Datetime.cpp.

References set().

Here is the call graph for this function:

Member Function Documentation

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

Setter by string.

Parameters
strwstr A string expressing the date. (1991-01-01 09:27:03)
Exceptions
invalid_argumentparameter is out of its own range.

Referenced by Datetime().

Here is the caller graph for this function:

void Datetime::set ( const WeakString wStr)
overridevirtual

deque by weak_string

Parameters
wstrA weak_string expressing the date. (1991-01-01 09:27:03)
Exceptions
invalid_argumentparameter is out of its own range.

Reimplemented from samchon::library::Date.

Definition at line 52 of file Datetime.cpp.

References samchon::WeakString::between(), samchon::WeakString::find(), samchon::library::Date::getDate(), samchon::library::Date::getMonth(), samchon::library::Date::getYear(), and samchon::library::Date::set().

Here is the call graph for this function:

void Datetime::set ( int  year,
int  month,
int  date,
int  hours = 0,
int  minutes = 0,
int  seconds = 0 
)
Exceptions
invalid_argumentparameter is out of range (ex: month -> 13)

Definition at line 70 of file Datetime.cpp.

References addSecond(), and samchon::library::Date::set().

Here is the call graph for this function:

void Datetime::set ( long long  linuxTime)

Definition at line 75 of file Datetime.cpp.

References samchon::library::Date::set().

Here is the call graph for this function:

void Datetime::setYear ( int  val)
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 from samchon::library::Date.

Definition at line 84 of file Datetime.cpp.

References samchon::library::Date::getDate(), getHour(), getMinute(), samchon::library::Date::getMonth(), getSecond(), samchon::library::Date::getYear(), and samchon::library::Date::setYear().

Here is the call graph for this function:

void Datetime::setMonth ( int  val)
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 from samchon::library::Date.

Definition at line 93 of file Datetime.cpp.

References samchon::library::Date::getDate(), getHour(), getMinute(), samchon::library::Date::getMonth(), getSecond(), samchon::library::Date::getYear(), and samchon::library::Date::setMonth().

Here is the call graph for this function:

void Datetime::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 from samchon::library::Date.

Definition at line 102 of file Datetime.cpp.

References samchon::library::Date::getDate(), getHour(), getMinute(), samchon::library::Date::getMonth(), getSecond(), samchon::library::Date::getYear(), and samchon::library::Date::setDate().

Here is the call graph for this function:

void Datetime::setHour ( int  val)

Set hour.

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

Definition at line 111 of file Datetime.cpp.

References samchon::library::Date::getDate(), getMinute(), samchon::library::Date::getMonth(), getSecond(), and samchon::library::Date::getYear().

Here is the call graph for this function:

void Datetime::setMinute ( int  val)

Set minute.

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

Definition at line 115 of file Datetime.cpp.

References samchon::library::Date::getDate(), getHour(), samchon::library::Date::getMonth(), getSecond(), and samchon::library::Date::getYear().

Here is the call graph for this function:

void Datetime::setSecond ( int  val)

Set hour.

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

Definition at line 119 of file Datetime.cpp.

References samchon::library::Date::getDate(), getHour(), getMinute(), samchon::library::Date::getMonth(), and samchon::library::Date::getYear().

Here is the call graph for this function:

void Datetime::addYear ( int  val)
overridevirtual

Add years to the Date.

Parameters
valYears to add

Reimplemented from samchon::library::Date.

Definition at line 125 of file Datetime.cpp.

References samchon::library::Date::addYear(), samchon::library::Date::getDate(), getHour(), getMinute(), samchon::library::Date::getMonth(), getSecond(), and samchon::library::Date::getYear().

Here is the call graph for this function:

void Datetime::addMonth ( int  val)
overridevirtual

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 from samchon::library::Date.

Definition at line 134 of file Datetime.cpp.

References samchon::library::Date::addMonth(), samchon::library::Date::getDate(), getHour(), getMinute(), samchon::library::Date::getMonth(), getSecond(), and samchon::library::Date::getYear().

Here is the call graph for this function:

void Datetime::addWeek ( int  val)
overridevirtual

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 from samchon::library::Date.

Definition at line 143 of file Datetime.cpp.

References samchon::library::Date::addWeek(), samchon::library::Date::getDate(), getHour(), getMinute(), samchon::library::Date::getMonth(), getSecond(), and samchon::library::Date::getYear().

Here is the call graph for this function:

void Datetime::addDate ( int  val)
overridevirtual

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 from samchon::library::Date.

Definition at line 152 of file Datetime.cpp.

References samchon::library::Date::addDate(), samchon::library::Date::getDate(), getHour(), getMinute(), samchon::library::Date::getMonth(), getSecond(), and samchon::library::Date::getYear().

Here is the call graph for this function:

void Datetime::addHour ( int  val)

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 161 of file Datetime.cpp.

void Datetime::addMinute ( int  val)

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 165 of file Datetime.cpp.

void Datetime::addSecond ( int  val)

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 169 of file Datetime.cpp.

Referenced by set().

Here is the caller graph for this function:

int Datetime::getHour ( ) const -> int

Get hour.

Returns
hour of the Datetime to integer

Definition at line 175 of file Datetime.cpp.

References samchon::library::Date::toTM().

Referenced by addDate(), addMonth(), addWeek(), addYear(), setDate(), setMinute(), setMonth(), setSecond(), setYear(), and toString().

Here is the call graph for this function:

Here is the caller graph for this function:

int Datetime::getMinute ( ) const -> int

Get minute.

Returns
minute of the Datetime to integer

Definition at line 180 of file Datetime.cpp.

References samchon::library::Date::toTM().

Referenced by addDate(), addMonth(), addWeek(), addYear(), setDate(), setHour(), setMonth(), setSecond(), setYear(), and toString().

Here is the call graph for this function:

Here is the caller graph for this function:

int Datetime::getSecond ( ) const -> int

Get second.

Returns
second of the Datetime to integer

Definition at line 185 of file Datetime.cpp.

References samchon::library::Date::toTM().

Referenced by addDate(), addMonth(), addWeek(), addYear(), setDate(), setHour(), setMinute(), setMonth(), setYear(), and toString().

Here is the call graph for this function:

Here is the caller graph for this function:

auto Datetime::toString ( ) const -> std::string
overridevirtual

Converts the Datetime to std::string.

Returns
std::string expressing the Datetime

Reimplemented from samchon::library::Date.

Definition at line 192 of file Datetime.cpp.

References getHour(), getMinute(), getSecond(), samchon::library::StringUtil::substitute(), and samchon::library::Date::toString().

Here is the call graph for this function:


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