DateTime

Date and Time module.

Adapted from the implementation of Julia language standard library. License is MIT: https://julialang.org/license

A Date value is encoded as an HUGEINT, 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*      = MIN(HUGEINT);
Year*       = 1;
Quarter*    = 2;
Month*      = 3;
Week*       = 4;
Day*        = 5;
Weekday*    = 6;
Hour*       = 7;
Min*        = 8;
Sec*        = 9;
MSec*       = 10;

Types

DATETIME* = Type.DATETIME;

Procedures

TryEncodeDate

Return TRUE if the year, month & day is successful converted to a valid DATETIME

PROCEDURE TryEncodeDate* (VAR date : DATETIME; year,month,day : INTEGER) : BOOLEAN;

EncodeDate

Return Encoded date. Return ERROR if not valid

PROCEDURE EncodeDate* (year, month, day : INTEGER): 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 : INTEGER) : BOOLEAN;

EncodeDateTime

Return encoded DATETIME. Return ERROR if not valid

PROCEDURE EncodeDateTime* (year, month, day, hour, min, sec, msec: INTEGER): DATETIME;

DecodeDate

Decode DATETIME to Year, Month & Day

PROCEDURE DecodeDate* (datetime: DATETIME; VAR year, month, day: INTEGER);

DecodeTime

Decode DATETIME to Hour, Min, Sec & MSec

PROCEDURE DecodeTime* (datetime: DATETIME; VAR hour, min, sec, msec: INTEGER);

DecodeDateTime

Decode DATETIME to Year, Month, Day, Hour, Min, Sec & MSec

PROCEDURE DecodeDateTime* (datetime: DATETIME; VAR year, month, day, hour, min, sec, msec: INTEGER);

DateTimeToDate

Remove time part of DATETIME

PROCEDURE DateTimeToDate* (datetime: DATETIME) : DATETIME;

IncYear

Increment Year of DATETIME and return modified value

PROCEDURE IncYear* (datetime: DATETIME; years : INTEGER) : DATETIME;

DecYear

Decrement Year of DATETIME and return modified value

PROCEDURE DecYear* (datetime: DATETIME; years : INTEGER) : DATETIME;

IncMonth

Increment Month of DATETIME and return modified value

PROCEDURE IncMonth* (datetime: DATETIME; months : INTEGER) : DATETIME;

DecMonth

Decrement Month of DATETIME and return modified value

PROCEDURE DecMonth*(datetime: DATETIME; months : INTEGER) : DATETIME;

Inc

Increment DATETIME with Value according to Type.

PROCEDURE Inc* (VAR datetime : DATETIME; typ : INTEGER; value : HUGEINT);

Dec

Decrement DATETIME with Value according to Type.

PROCEDURE Dec* (VAR datetime : DATETIME; typ : INTEGER; value : HUGEINT);

Now

Current DATETIME

PROCEDURE Now* (): DATETIME;

Today

Current Date

PROCEDURE Today* (): DATETIME;

Extract

Extract component of DATETIME

PROCEDURE Extract* (datetime : DATETIME; typ : INTEGER) : INTEGER;

Trunc

Trucate DATETIME value according to Type. Usefull for comparison, calculate spans or finding start of periods (week, month).

PROCEDURE Trunc* (datetime: DATETIME; typ: INTEGER): DATETIME;

Diff

Compute difference between two dates. Extract year, month, day to get difference

PROCEDURE Diff* (dtstart, dtend: DATETIME; addEndDay: BOOLEAN): DATETIME;

Span

Calculate DATETIME span between Start and End according to Type

PROCEDURE Span* (dtstart, dtend: DATETIME; typ: INTEGER): INTEGER;

Format

Format DATETIME according to format string arguments:

  • %a : Weekday abbreviated name : Mon .. Sun

  • %A : Weekday full name : Monday .. Sunday

  • %w : Weekday as number : 0 .. 6

  • %b : Month abbreviated name : Jan .. Des

  • %B : Month full name : Januar .. Desember

  • %Y : Year without century : 00 - 99

  • %y : Year with century : 0000 - 9999

  • %m : Month zero-padded : 00 - 12

  • %d : Day of the month zero-padded : 01 - XX

  • %W : Week of the year zero-padded : 01 - 53

  • %H : Hour (24-hour clock) zero-padded : 00 - 23

  • %I : Hour (12-hour clock) zero-padded : 1 - 12

  • %p : AM or PM

  • %M : Minute zero-padded : 00 - 59

  • %S : Second zero-padded : 00 - 59

  • %f : Milliseconds zero-padded : 000 - 999

  • %Z : Timezone : UTC+/-

  • %% : Literal % char

Other characters are copied to output.

PROCEDURE Format* (VAR Writer : Type.Stream; datetime : DATETIME; fmt- : ARRAY OF CHAR);

FromSubString

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.

Sets datetime to ERROR on failure.

PROCEDURE FromSubString* (VAR datetime : DATETIME; src- : ARRAY OF CHAR; fmt-: ARRAY OF CHAR; start: LENGTH);

FromString

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.

Sets datetime to ERROR on failure.

PROCEDURE FromString* (VAR datetime : DATETIME; src- : ARRAY OF CHAR; fmt-: ARRAY OF CHAR);