Samchon Framework for CPP
1.0.0
|
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... | |
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.
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
Date::Date | ( | ) |
Date::Date | ( | const super & | date | ) |
Date::Date | ( | super && | date | ) |
Date::Date | ( | int | year, |
int | month, | ||
int | date | ||
) |
samchon::library::Date::Date | ( | const std::string & | ) |
Construct from string.
str | A string represents the date. (1991-01-01) |
invalid_argument | month or date is invalid. |
Date::Date | ( | const WeakString & | wStr | ) |
Construct from WeakString.
str | A weak_string expressing the date. (1991-01-01) |
invalid_argument | month or date is invalid. |
Date::Date | ( | long long | linuxTime | ) |
|
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)
Definition at line 109 of file Date.cpp.
References calcLastDates().
Referenced by set().
|
staticprotected |
Calculates and gets an array of final date of each month for that year.
year | The target year |
Definition at line 97 of file Date.cpp.
Referenced by addMonth(), calcSeconds(), set(), and setMonth().
void samchon::library::Date::set | ( | const std::string & | ) |
Setter by string.
str | Y-m-d |
invalid_argument | month or date is invalid. |
Referenced by Date(), and samchon::library::Datetime::set().
|
virtual |
Setter by weak_string.
wstr | Y-m-d |
invalid_argument | month 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().
void Date::set | ( | int | year, |
int | month, | ||
int | date | ||
) |
Setter by elements of date.
year | ex) 2015 |
month | January to December. 1 ~ 12 |
date | day in month. 1 ~ 31 |
invalid_argument | month or date is invalid. |
Definition at line 72 of file Date.cpp.
References calcLastDates(), and calcSeconds().
void Date::set | ( | long long | linuxTime | ) |
|
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 in samchon::library::Datetime.
Definition at line 131 of file Date.cpp.
References getDate(), and getMonth().
Referenced by addYear(), and samchon::library::Datetime::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 in samchon::library::Datetime.
Definition at line 150 of file Date.cpp.
References calcLastDates(), getDate(), and getYear().
Referenced by samchon::library::Datetime::setMonth().
|
virtual |
Set date of the Date
val | Target day in month |
invalid_argument | When 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().
|
virtual |
Add years to the Date.
val | Years 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().
|
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.
val | Months 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().
|
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.
val | Weeks to add |
Reimplemented in samchon::library::Datetime.
Definition at line 202 of file Date.cpp.
References addDate().
Referenced by samchon::library::Datetime::addWeek().
|
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.
val | Days to add |
Reimplemented in samchon::library::Datetime.
Definition at line 206 of file Date.cpp.
Referenced by samchon::library::Datetime::addDate(), and addWeek().
int Date::getYear | ( | ) | const -> int |
Get year of the Date.
Definition at line 221 of file Date.cpp.
References toTM().
Referenced by samchon::library::Datetime::addDate(), samchon::library::Datetime::addMonth(), addMonth(), samchon::library::Datetime::addWeek(), samchon::library::Datetime::addYear(), addYear(), samchon::library::Datetime::set(), samchon::library::Datetime::setDate(), setDate(), samchon::library::Datetime::setHour(), samchon::library::Datetime::setMinute(), samchon::library::Datetime::setMonth(), setMonth(), samchon::library::Datetime::setSecond(), samchon::library::Datetime::setYear(), and toString().
int Date::getMonth | ( | ) | const -> int |
Get month of the Date.
Definition at line 226 of file Date.cpp.
References toTM().
Referenced by samchon::library::Datetime::addDate(), samchon::library::Datetime::addMonth(), addMonth(), samchon::library::Datetime::addWeek(), samchon::library::Datetime::addYear(), samchon::library::Datetime::set(), samchon::library::Datetime::setDate(), setDate(), samchon::library::Datetime::setHour(), samchon::library::Datetime::setMinute(), samchon::library::Datetime::setMonth(), samchon::library::Datetime::setSecond(), samchon::library::Datetime::setYear(), setYear(), and toString().
int Date::getDate | ( | ) | const -> int |
Get the day in month of the Date.
Definition at line 236 of file Date.cpp.
References toTM().
Referenced by samchon::library::Datetime::addDate(), samchon::library::Datetime::addMonth(), addMonth(), samchon::library::Datetime::addWeek(), samchon::library::Datetime::addYear(), samchon::library::Datetime::set(), samchon::library::Datetime::setDate(), samchon::library::Datetime::setHour(), samchon::library::Datetime::setMinute(), samchon::library::Datetime::setMonth(), setMonth(), samchon::library::Datetime::setSecond(), samchon::library::Datetime::setYear(), setYear(), and toString().
int Date::getDay | ( | ) | const -> int |
|
protected |
Converts the Date to struct tm.
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().
auto Date::toLinuxTime | ( | ) | const -> long long |
|
virtual |
Converts the Date to std::string.
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().
|
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().