DateTime
Date and Time module.
Adapted from Julia. License is MIT: https://julialang.org/license
A Date value is encoded as an LONGLONGINT, counting milliseconds from an epoch. The epoch is 0000-12-31T00:00:00.
Days are adjusted accoring to Rata Die approch to simplify date calculations.
Const
ERROR* = -1;
Types
DATETIME* = LONGLONGINT;
TType* = (Year, Quarter, Month, Week, Day, Weekday, Hour, Min, Sec, MSec);
Procedures
TryEncodeDate
Return TRUE if the year, month & day is successful converted to a valid DATETIME
PROCEDURE TryEncodeDate* (VAR date : DATETIME; year,month,day : LONGINT) : BOOLEAN;
EncodeDate
Return Encoded date. Return ERROR if not valid
PROCEDURE EncodeDate* (year, month, day : LONGINT): DATETIME;
TryEncodeDateTime
Return TRUE if Year, Month, Day, Hour, Min, Sec & MSec is successful converted to a valid DATETIME
PROCEDURE TryEncodeDateTime* (VAR datetime : DATETIME; year, month, day, hour, min, sec, msec : LONGINT) : BOOLEAN;
EncodeDateTime
Return encoded DATETIME. Return ERROR if not valid
PROCEDURE EncodeDateTime* (year, month, day, hour, min, sec : LONGINT; msec := 0 : LONGINT): DATETIME;
DecodeDate
Decode DATETIME to Year, Month & Day
PROCEDURE DecodeDate* (datetime: DATETIME; VAR year, month, day: LONGINT);
DecodeTime
Decode DATETIME to Hour, Min, Sec & MSec
PROCEDURE DecodeTime* (datetime: DATETIME; VAR hour, min, sec, msec: LONGINT);
DecodeDateTime
Decode DATETIME to Year, Month, Day, Hour, Min, Sec & MSec
PROCEDURE DecodeDateTime* (VAR year, month, day, hour, min, sec, msec: LONGINT; datetime: DATETIME);
DateTimeToDate
Remove time part of DATETIME
PROCEDURE DateTimeToDate* (datetime: DATETIME) : DATETIME;
Now
Current DATETIME
PROCEDURE Now* (): DATETIME;
Today
Current Date
PROCEDURE Today* (): DATETIME;
IncYear
Increment Year of DATETIME and return modified value
PROCEDURE IncYear* (datetime: DATETIME; years : LONGINT) : DATETIME;
DecYear
Decrement Year of DATETIME and return modified value
PROCEDURE DecYear* (datetime: DATETIME; years : LONGINT) : DATETIME;
IncMonth
Increment Month of DATETIME and return modified value
PROCEDURE IncMonth* (datetime: DATETIME; months : LONGINT) : DATETIME;
DecMonth
Deccrement Month of DATETIME and return modified value
PROCEDURE DecMonth*(datetime: DATETIME; months : LONGINT) : DATETIME;
Inc
Increment DATETIME with Value according to Type.
PROCEDURE Inc* (VAR datetime : DATETIME; typ : TType; value : LONGLONGINT);
Dec
Decrement DATETIME with Value according to Type.
PROCEDURE Dec* (VAR datetime : DATETIME; typ : TType; value : LONGLONGINT);
Extract
Extract component of DATETIME
PROCEDURE Extract* (datetime : DATETIME; typ : TType) : LONGINT;
Trunc
Trucate DATETIME value according to Type. Usefull for comparison, calculate spans or finding start of periods (week, month).
PROCEDURE Trunc* (datetime : DATETIME; typ : TType) : DATETIME;
Diff
Compute difference between two dates. Extract year, month, day to get difference
PROCEDURE Diff* (dtstart, dtend: DATETIME; addEndDay := FALSE : BOOLEAN) : DATETIME;
Span
Calculate DATETIME span between Start and End according to Type
PROCEDURE Span* (dtstart, dtend: DATETIME; typ : TType) : LONGINT;
FromString
Try to parse string to a DATETIME according to format string:
%y : Year with century : 0 - 9999
%m : Month : 1 - 12
%d : Day of the month : 1 - XX
%H : Hour (24-hour clock) : 0 - 23
%M : Minute : 0 - 59
%S : Second : 0 - 59
%f : Milliseconds : 0 - 999
%t : One or more TAB or SPC characters
%% : Literal % char
Numbers can be zero padded. Other characters must match exactly.
Return -1 on failure or number of characters converted.
PROCEDURE FromString* (VAR datetime : DATETIME; src- : ARRAY OF CHAR; fmt- : ARRAY OF CHAR; start := 0 : LONGINT): LONGINT;