Class Datemath
#include <Datemath.h >
A class for manipulating time to calculate new dates/times.
static const string months |
The first three letters of each month, e.g. months[0]="Jan", etc. |
static const string dow |
The first three letters of the day of the week, e.g. dow[0]="Sun", etc. |
time_t timestamp |
an Unix epoch timestamp. Not requires. Default: time(0) Default value: 0 |
Constructor. Initializes to provided timestamp. If none provided, then now.
const string& params |
Space separated list of terms. See calcItem(). |
Constructor. Takes a list of terms, which are used to calculate the desired time.
time_t timestamp |
an Unix epoch timestamp. Not requires. Default: time(0) |
const string& params |
Space separated list of terms. See calcItem(). |
Constructor. Provided a start time and terms to modify it.
Reset to beginning of time.
Determines if the current time value is valid. The beginning of time is considered invalid.
Return value: True if current time is valid.
Determines if the current time value is invalid. The beginning of time is considered invalid.
Return value: True if current time is 0, the beginning of time.
Get the calculated time as Unix epoch time.
Return value: the current calculated time as Unix epoch time.
Return the caclulated time's year.
Return value: the year, e.g. 1970+
Return the caclulated time's month.
Return value: the month, e.g. 1-12
Return the caclulated time's day.
Return value: the day, e.g. 1-31
Return the caclulated time's day of week.
Return value: the day of week, 0=Sun, 1=Mon, etc. 6=Sat
Return the caclulated time's hour.
Return value: the hour, e.g. 0-23
Return the caclulated time's minute.
Return value: the minute, e.g. 0-59
Return the caclulated time's second.
Return value: the second, e.g. 0-59
Get the current Unix epoch time for right now.
Return value: Unix epoch time for now
Get the beginning of Unix epoch time for zero time (epoch time=0, Jan 1, 1970).
Return value: Unix epoch time for zero time
time_t timestamp |
Unix epoch time |
bool defaultToNow |
if timestamp is 0, then use 0=beginning of time (if false) or to now (if true) Default value: false |
Set the current time in Datemath.
Return value: Unix epoch time of new timestamp
const string& params |
Space separated list of terms. See calcItem(). |
const string& format |
Instructions on how to convert the time to text, like date(1) command. See format(). |
Modify the current time by the parameters, then convert time to the format provided.
Return value: the current Datemat time formatted into a string
string param |
A Datemath modifier (see above) |
Modifify the calculated time by one Datemath modifier parameter:
noon - set the time of day to 12:00:00pm
midnight - set the time of day to 00:00:00am
firstday - set the day of the month to the first day in the month, e.g. 1
lastday - set the day of the month to the last day in the
Sun - set the date to the previous Sunday
Mon - set the date to the previous Sunday
Tue - set the date to the previous Sunday
Wed - set the date to the previous Sunday
Thu - set the date to the previous Sunday
Fi - set the date to the previous Sunday
Sat - set the date to the previous Sunday
now - set the date and time to the current moment, e.g. time(0)
HH:MM - set the time to the time specified for the current date
HH:MM:SS - set the time to the time specified for the current date
MM/DD/YY - set the current date to the date specified (if no century, then +2000)
YY-MM-DD - set the current date to the date specified (if no century, then +2000)
+n, -n - Modify the current time by adding ro subtracting <n > seconds
+ns, -ns - Modify the current time by adding ro subtracting <n > seconds
+nm, -nm - Modify the current time by adding ro subtracting <n > minutess
+nh, -nh - Modify the current time by adding ro subtracting <n > hours
+nd, -nd - Modify the current time by adding ro subtracting <n > days
+nw, -nw - Modify the current time by adding ro subtracting <n > weeks
+nM, -nM - Modify the current time by adding ro subtracting <n > months
+nY, -nY - Modify the current time by adding ro subtracting <n > years (Y or y allowed)
+nQ, -nQ - Modify the current time by adding ro subtracting <n > quarters
Jan - change the current month to January (year not changed)
Feb - change the current month to February (year not changed)
Mar - change the current month to March (year not changed)
Apr - change the current month to April (year not changed)
May - change the current month to May (year not changed)
Jun - change the current month to June (year not changed)
Jul - change the current month to July (year not changed)
Aug - change the current month to August (year not changed)
Sep - change the current month to September (year not changed)
Oct - change the current month to October (year not changed)
Nov - change the current month to November (year not changed)
Dec - change the current month to December (year not changed)
Return value: Unix epoch time of new timestamp
string params |
A space sparated list of Datemath modifier terms. See calcItem(). |
Modify the calculated time by the provides list of modififer paramters.
Return value: Unix epoch time of new timestamp
const string& format |
A text string containing time placeholders (see above) |
From the current time in Datemath, output the date and time in the format provided.
Just like date(1), the format may contain plain text and time placeholders. The
placeholders will be replaced with the appropriate text for the time. Placeholders are:
%s - seconds since the beginning of time (epoch time)
%D - date at MM/DD/YY
%d - day of month, e.g. 01-31
%e - day of month, e.g. 1-31
%m - month of year, e.g. 01-12
%y - year of century, e.g. 00-99
%Y - year with century, e.g. 2023
%b - name of month, e.g. Jan-Dec
%T - time of day, e.g. HH:MM:SS
%H - hour of day, e.g. 00-23
%I - hour of day, e.g. 1-12
%M - minute of hour, e.g. 00-59
%S - seconds within the current minute, e.g. 00-59
%a - the weekday name, e.g. Sun-Sat
%w - the weeday number, e.g. 0-6
%Z - the local timezone
Return value: a string with time per the format provided
const string& fmt |
A text string containing time placeholders. See format(). |
Same as format(): From the current time in Datemath, output the date and time in the format provided.
Return value: a string with time per the format provided
long n |
the number of seconds to add |
Add seconds to the time in Datemath, returns a new Datemath value.
Return value: a new Datemath value, modified
long n |
the number of seconds to add |
Add seconds to the current time in Datemath, returns the new/modified Datemath value.
Return value: the modified Datemath value
const string& params |
a string with Datemath modifiers. See calcItem(). |
Modifies the time in Datemath by the parameters given, returns a new Datemath value.
Return value: a new Datemath value, modified
const string& params |
a string with Datemath modifiers separated by spaces. See calcItem(). |
Modifies the time in Datemath by the parameters given, returns the new/modified Datemath value.
Return value: the modified Datemath value
time_t starttime |
Unix epoch time |
const string& params |
a string with Datemath modifies separated by spaces. See calcItem(). |
const string& format |
A text string containing time placeholders. See format(). |
Given a time, modifiers, and format, output the newly calculated time in the format provided.
Return value: a formated time string
time_t starttime |
Unix epoch time |
const string& param |
a Datemath modifier. See other calcItem(). |
From the current time provided, calculate a new time based on modifier provided.
Return value: the modified Unix epoch time
time_t starttime |
Unix epoch time |
const string& params |
a string with Datemath modifiers separated by spaces. See calcItem(). |
From the current time provided, calculate a new time based on the list of modifiers provided.
Return value: the modified Unix epoch time
time_t starttime |
Unix epoch time |
const string& fmt |
A text string containing time placeholders. See format(). |
Given a time and format, output the time in the format provided.
Return value: a formated time string
time_t t |
Unix epoch time |
const string& fmt |
A text string containing time placeholders. See format(). |
Same as format(). Given a time and format, output the time in the format provided.
Return value: a formated time string
Convert the current time to epoch time as a string.
Return value: epoch time as a string (not as time_t)
time_t t |
time last processed |
time_t t |
starting Unix epoch time |
int month |
the number of months to turn back |
Go back in time the specified number of months
Return value: epoch time