Samchon Framework for CPP
1.0.0
|
#include <Datetime.hpp>
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... | |
![]() | |
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 | |
![]() | |
auto | toTM () const -> struct::tm |
Converts the Date to struct tm. More... | |
![]() | |
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 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... | |
Date and time.
Datetime is a Date having hours, minutes and seconds addictionally.
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.
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
Definition at line 19 of file Datetime.hpp.
Datetime::Datetime | ( | ) |
Default Constructor
The datetime will be now (Now from operating system)
Definition at line 15 of file Datetime.cpp.
Referenced by Datetime().
samchon::library::Datetime::Datetime | ( | const std::chrono::system_clock::time_point & | ) |
samchon::library::Datetime::Datetime | ( | std::chrono::system_clock::time_point && | ) |
Move Constructor
Gets the date from other and truncate the other
date | Target to be moved |
Datetime::Datetime | ( | int | year, |
int | month, | ||
int | date, | ||
int | hour = 0 , |
||
int | min = 0 , |
||
int | sec = 0 |
||
) |
Construct from datetime elements.
year | ex) 2015 |
month | January to December. 1 ~ 12 |
date | Day in month. 1 ~ 31 |
hour | Hours (0-23) |
min | Minutes (0-59) |
sec | Seconds (0-59) |
invalid_argument | parameter is out of its own range. |
Definition at line 27 of file Datetime.cpp.
References Datetime().
samchon::library::Datetime::Datetime | ( | const std::string & | ) |
Construct from string.
str | A string representing the date. (1991-01-01 09:27:03) |
invalid_argument | parameter is out of its own range. |
Datetime::Datetime | ( | const WeakString & | wStr | ) |
Construct from WeakString.
wstr | A weak_string expressing the date. (1991-01-01 09:27:03) |
invalid_argument | parameter is out of its own range. |
Definition at line 36 of file Datetime.cpp.
Datetime::Datetime | ( | long long | linuxTime | ) |
Construct from linux_time.
linuxTime | linux_time to be converted |
Definition at line 41 of file Datetime.cpp.
References set().
void samchon::library::Datetime::set | ( | const std::string & | ) |
Setter by string.
str | wstr A string expressing the date. (1991-01-01 09:27:03) |
invalid_argument | parameter is out of its own range. |
Referenced by Datetime().
|
overridevirtual |
deque by weak_string
wstr | A weak_string expressing the date. (1991-01-01 09:27:03) |
invalid_argument | parameter 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().
void Datetime::set | ( | int | year, |
int | month, | ||
int | date, | ||
int | hours = 0 , |
||
int | minutes = 0 , |
||
int | seconds = 0 |
||
) |
invalid_argument | parameter is out of range (ex: month -> 13) |
Definition at line 70 of file Datetime.cpp.
References addSecond(), and samchon::library::Date::set().
void Datetime::set | ( | long long | linuxTime | ) |
Definition at line 75 of file Datetime.cpp.
References samchon::library::Date::set().
|
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
val | Target 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().
|
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
val | Target month (1 - 12) |
invalid_argument | month 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().
|
virtual |
Set date of the Date
val | Target day in month |
invalid_argument | When 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().
void Datetime::setHour | ( | int | val | ) |
Set hour.
val | Target hour (0 - 23) |
invalid_argument | When 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().
void Datetime::setMinute | ( | int | val | ) |
Set minute.
val | Target minute (0 - 59) |
invalid_argument | When 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().
void Datetime::setSecond | ( | int | val | ) |
Set hour.
val | Target second (0 - 59) |
invalid_argument | When 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().
|
overridevirtual |
Add years to the Date.
val | Years 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().
|
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.
val | Months 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().
|
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.
val | Weeks 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().
|
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.
val | Days 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().
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.
val | hours to add |
Definition at line 161 of file Datetime.cpp.
void Datetime::addMinute | ( | int | val | ) |
Add minutes.
val | minutes to add |
Definition at line 165 of file Datetime.cpp.
void Datetime::addSecond | ( | int | val | ) |
Add seconds.
val | seconds to add |
Definition at line 169 of file Datetime.cpp.
Referenced by set().
int Datetime::getHour | ( | ) | const -> int |
Get hour.
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().
int Datetime::getMinute | ( | ) | const -> int |
Get minute.
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().
int Datetime::getSecond | ( | ) | const -> int |
Get second.
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().
|
overridevirtual |
Converts the Datetime to std::string.
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().