Script:
~addons/finexec/datetime/edatetime_tools.ijs
Contributor: William Szuch
Updated: 2022 6 26
Depend: Foreigns: 6!:14, 6!:15, 6!:16 and 6!:17
Definitions loaded to locale: base
Status: dev
Script source:
edatetime.ijs
This script has definitions that are useful for
handling edatetimes.
For more detailed information see:
<href “https://code.jsoftware.com/wiki/Vocabulary/Foreigns#m6”
_blank>Foreigns 6!:
note:
Leap Year:
Every year that is exactly divisible by four is a leap year,
except for years that are exactly divisible by 100;
The centurial years that are exactly divisible by 400 are still leap
years.
For example, the years 1800,1900,2100,2200 are not leap years;
The year 2000 is leap year.
Nano second = 1e_9
Milli second = 1e_3
edateimes are measured in nanoseconds from
1/1/2000.
edatetimes are in the range:
1800-01-01 to 2200-12-31
If the edatetime is outside the range the result is the error:
_9223372036854775808.
digit time integer: YYYYMMDDhhmmss
Expanded digit dateime: Year, Month, Day, Hours, Minutes, Seconds,
nanoseconds
Definitions
ageLastBD (dyad)
Depend: Foreign 6!:17
Age last birthday - edatetime
Syntax
(ED) ageLatBD(BD)
ED = date of calculation
BD = date of birth
ageNearestBD (dyad)
Depend: Foreign 6!:17
Age nearest birthday - edatetime
Syntax
(ED) ageNearestBD(BD)
ED = date of calculation
BD = date of birth
ageNextBD (dyad)
Depend: Foreign 6!:17
Age next birthday - edatetime
Syntax
(ED) ageNextBD(BD)
ED = date of calculation
BD = date of birth
cDateTime (monad)
Form tacit
Depend: Foreign 6!:0
Current date time format: yyyy MM DD hh mm ss
Seconds to 1/1000
Syntax
cDateTime ''
cDigitTime (monad)
Form tacit
Depend: Foreign 6!:0
Current digit time format as integer: YYYYMMDDhhmmss
Syntax
cDigitTime ''
cISO_8601DateTime (monad)
Form tacit
Depend: Foreign 6!:0, 6!:14,6!:16
Current ISO-8601 date time
cISO_8601DateTime ''
cNanoDateTime (monad)
Form tacit
Depend: Foreign 6!:0, 6!:14
Current nano date time
cNanoDateTime ''
ddtn (monad)
Form tacit
Depend: Foreign 6!:15
Convert nanosecond datetime to expanded digit time
Expanded digit time: Year, Month, Day, Hours, Minutes, Seconds,
nanoseconds
Syntax
ddtn(N)
N = nanoseconds
Example
ddtn(0)
2000 1 1 0 0 0 0
ddtn(315619200000000000)
2010 1 1 0 0 0 0
ddtn(_315532800000000000)
1990 1 1 0 0 0 0
dtn (monad)
Form tacit
Depend: Foreign 6!:16
Convert nanoseconds to ISO 8601 datetime
Syntax
dtn(N)
N = nanoseconds
Example
dtn(0)
2000-01-01T00:00:00.000000000
dtn(315619200000000000)
2010-01-01T00:00:00.000000000
dtn(_315532800000000000)
1990-01-01T00:00:00.000000000
dtn(315619210001000000)
2010-01-01T00:00:10.001000000
dtn(7311433600000000000) NB. Outside range
?
dtn0 (monad)
Form tacit
Depend: Foreign 6!:17
Convert nanoseconds to ISO 8601 datetime
Syntax
dtn0(N)
N = nanoseconds
Example
dtn0(0)
2000-01-01T00:00:00
dtn0(315619200000000000)
2010-01-01T00:00:00
dtn0(_315532800000000000)
1990-01-01T00:00:00
dtn0(315619210001000000)
2010-01-01T00:00:10
dtn0(6311433600000000000)
2200-01-01T00:00:00
dtn0(7311433600000000000) NB. Outside range
?
nddt (monad)
Form tacit
Depend: Foreign 6!:14
Convert digit time to nanoseconds
Syntax
ndft(D)
D = digit date time: YYYYMMDDhhmmss
Example
nddt(20000101000000)
0
nddt(20100101000000)
315619200000000000
nddt(19900101000000)
_315532800000000000
ndt (monad)
Form tacit
Depend: Foreign 6!:17
Convert ISO 8601 edatetime to nanoseconds
edatetime ‘YYYY-MM-DDTHH:MM:SS’
Syntax
dtn0(D)
D = ISO 8601 datetime
Example
ndt '2000'
0
ndt '2200'
6311433600000000000
ndt '2201'
_9223372036854775808 NB. Outside range
Further examples ISO 8601 formats to try:
ndt '2000-01'
ndt '2000-01-01'
ndt '2000-01-01T'
ndt '2000-01-01T00'
ndt '2000-01-01T00:00'
ndt '2000-01-01T00:00:00'
ndt '2000-01-01T00:00:00.00'
tndiff (dyad)
Form tacit
Depend: Foreign 6!:17
Difference between pairs of edatetimes in nano seconds
edates in ISO 8601 format: ’yyyy-MM-DDTHH:MM:SS
Syntax
(ED) tndiff(BD)
ED = end date
BD = begin datre