Evo C++ Library v0.5.1
|
#include <evo/time.h>
Structure holding a calendar date.
Output:
Public Member Functions | |
Date () | |
Constructor. More... | |
Date (int year, int month, int day) | |
Constructor to initialize with date. More... | |
Date (const Date &src) | |
Copy constructor. More... | |
bool | add_days (int days) |
Add days to current date, subtract if negative. More... | |
bool | add_months (int months) |
Add months to current date, subtract if negative. More... | |
bool | add_years (int years) |
Add years to current date, subtract if negative. More... | |
int | compare (const Date &oth) const |
Compare to another date. More... | |
template<class T > | |
T & | format (T &out, char delim='-') const |
Format date to String or Stream. More... | |
template<class T > | |
T & | format_yearday (T &out, char delim='-') |
Format ordinal date to String or Stream. More... | |
ulong | get_jdn () const |
Get Julian Day Number for current date. More... | |
bool | operator!= (const Date &oth) const |
Compare for inequality with another date. More... | |
bool | operator< (const Date &oth) const |
Compare whether less than another date. More... | |
bool | operator<= (const Date &oth) const |
Compare whether less than or equal to another date. More... | |
Date & | operator= (const Date &src) |
Assignment operator. More... | |
bool | operator== (const Date &oth) const |
Compare for equality with another date. More... | |
bool | operator> (const Date &oth) const |
Compare whether greater than another date. More... | |
bool | operator>= (const Date &oth) const |
Compare whether greater than or equal to another date. More... | |
bool | parse (const SubString &str) |
Set date from parsing standard date string (used internally). More... | |
bool | parse_std_impl (const char *&inp, const char *end) |
Set date from parsing standard date string (used internally). More... | |
void | set () |
Set all fields to 0, which is not a valid date. More... | |
bool | set (int new_year, int new_month, int new_day) |
Set new date fields. More... | |
bool | set_jdn (ulong jdn) |
Set date converted from Julian Day Number. More... | |
void | set_local () |
Set to current date in local time zone. More... | |
void | set_utc () |
Set to current date in UTC. More... | |
bool | validate () const |
Validate current date. More... | |
Static Public Member Functions | |
static ulong | calc_jdn (int year, int month, int day) |
Calculate Julian Day Number from date fields. More... | |
static int | days_per_month (int month, bool leap_year) |
Helper to get number of days per given month. More... | |
static int | days_per_month (int month, int year) |
Helper to get number of days per given month in given year. More... | |
static bool | is_leap_year (int year) |
Helper to check whether given year is a leap year. More... | |
static SubString | month_name (int month) |
Get name of given month. More... | |
static SubString | month_name3 (int month) |
Get abbreviated name of given month. More... | |
Public Attributes | |
int | day |
Day of month (1 - 31) More... | |
int | month |
Month of year (1 - 12) More... | |
int | year |
4 digit year (1000 - 9999) More... | |
Static Public Attributes | |
static const int | DAY_MAX = 31 |
Max day for any month – see days_per_month() More... | |
static const int | DAY_MIN = 1 |
First day per month. More... | |
static const ulong | JDN_MIN = 2086302 |
Minimum Julian Day Number for Jan 1, 1000. More... | |
static const ulong | JDN_MOD = 2400000 |
Julian Day Number for Modified Julian Day, subtract from JDN to get MJD (smaller number), add back for normal JDN. More... | |
static const int | MONTH_MAX = 12 |
Last month per year. More... | |
static const int | MONTH_MIN = 1 |
First month per year. More... | |
static const int | YEAR_MAX = 9999 |
Maximum year for 4 digits. More... | |
static const int | YEAR_MIN = 1000 |
Minimum year for 4 digits. More... | |
|
inline |
Constructor.
|
inline |
Constructor to initialize with date.
year | 4 digit year |
month | Month of year |
day | Day of month |
|
inline |
Add days to current date, subtract if negative.
days | Number of days to add, negative to subtract |
|
inline |
Add months to current date, subtract if negative.
months | Number of months to add, negative to subtract |
|
inline |
Add years to current date, subtract if negative.
years | Number of years to add, negative to subtract |
|
inlinestatic |
Calculate Julian Day Number from date fields.
year | Year to use (1000 - 9999) |
month | Month of year to use (1 - 12) |
day | Day of month to use (1 - 31) |
|
inline |
Compare to another date.
oth | Other date to compare to |
|
inlinestatic |
Helper to get number of days per given month.
month | Month to get number of days of (1 - 12) |
leap_year | Whether this is for a leap year, which affects the result for month=2 |
month
|
inlinestatic |
Helper to get number of days per given month in given year.
month | Month to get number of days of (1 - 12) |
year | Year for month, used to determine whether a leap year applies for month=2 |
month
|
inline |
Format date to String or Stream.
YYYY-MM-DD
– with default delimiter, other delimiters may be use but aren't considered standardYYYYMMDD
– with no delimiterT | String/Stream type, inferred from argument |
out | Output String/Stream to format to |
delim | Delimiter to use between fields, 0 for none |
out
|
inline |
Format ordinal date to String or Stream.
YYYY-DDD
– ordinal date with default delimiter, other delimiters may be use but aren't considered standardYYYYDDD
– ordinal date with no delimiterOutput | String/Stream type, inferred from argument |
out | Output String/Stream to format to |
delim | Delimiter to use between fields, 0 for none |
out
|
inline |
Get Julian Day Number for current date.
|
inlinestatic |
Helper to check whether given year is a leap year.
year | Year to check |
|
inlinestatic |
Get name of given month.
month | Month to get name of (1 - 12) |
month
|
inlinestatic |
Get abbreviated name of given month.
month | Month to get name of (1 - 12) |
month
|
inline |
Compare for inequality with another date.
oth | Other date to compare to |
|
inline |
Compare whether less than another date.
oth | Other date to compare to |
|
inline |
Compare whether less than or equal to another date.
oth | Other date to compare to |
Assignment operator.
src | Source to copy |
|
inline |
Compare for equality with another date.
oth | Other date to compare to |
|
inline |
Compare whether greater than another date.
oth | Other date to compare to |
|
inline |
Compare whether greater than or equal to another date.
oth | Other date to compare to |
|
inline |
Set date from parsing standard date string (used internally).
YYYY-MM-DD
– full date with delimiterYYYYMMDD
– shorter version without delimitersYYYY-DDD
– ordinal date with delimiter, with 4 digit year (1000 - 999) and day of year (1 - 366)YYYYDDD
– ordinal date, shorter version without delimitersSPACE
, SLASH
(/
), PERIOD
(.
)str | String to parse |
|
inline |
Set date from parsing standard date string (used internally).
YYYY-MM-DD
– full date with delimiterYYYYMMDD
– shorter version without delimitersYYYY-DDD
– ordinal date with delimiter, with 4 digit year (1000 - 999) and day of year (1 - 366)YYYYDDD
– ordinal date, shorter version without delimitersSPACE
, SLASH
(/
), PERIOD
(.
)inp | Start parsing pointer (must be <= end ), set to stop position [in/out] |
end | End of string pointer, must not be NULL |
|
inline |
Set all fields to 0, which is not a valid date.
|
inline |
Set new date fields.
new_year | New year value |
new_month | New month value |
new_day | New day value |
|
inline |
Set date converted from Julian Day Number.
jdn | Julian Day Number to set |
|
inline |
Set to current date in local time zone.
|
inline |
Set to current date in UTC.
|
inline |
Validate current date.
int day |
Day of month (1 - 31)
|
static |
Max day for any month – see days_per_month()
|
static |
First day per month.
|
static |
Minimum Julian Day Number for Jan 1, 1000.
|
static |
Julian Day Number for Modified Julian Day, subtract from JDN to get MJD (smaller number), add back for normal JDN.
int month |
Month of year (1 - 12)
|
static |
Last month per year.
|
static |
First month per year.
int year |
4 digit year (1000 - 9999)
|
static |
Maximum year for 4 digits.
|
static |
Minimum year for 4 digits.