datetime_rs.ijs

Script: ~addons/finance/finexec/datetime/datetime.ijs
Contributor: William Szuch/Ric Shirlock
Updated: 2023 03 21
Definitions loaded to locale base
Status: done
Script source: datetime_rs.ijs

This script is a copy of ~addons/types/datetime/datetime.ijs by:
Ric Sherlock : 2009 09 09
Modified for the Finexec addon
Some of the verbs in this script were derived from
APL+Win functions written by Davin Church.
Convert between day number and dates including times.
Custom date/time formating.
Date/time arithmetic.
Extends the dates.ijs system script in the Standard Library.

Definitions

A adjustYrMth
D daysDiff
E escaped
F fmt, fmtDate, fmtDateTime, fmtTime, fmtTimeDiff, fromJulian
G getDateFormats, getTimeFormats, getTimeZoneInfo
J J0Date
L Linux0DateTime
M MS0Date
T toDateTime, toDayNo, toJulian, tsDiff, tsMinus, tsPlus

adjustYrMth m adjust year and month
escaped v process an escaped string
fmt v format forengin
fmtDateTime v Formats combined date and time strings
fmtTimeDiff v Formated time difference
getDateFormats v returns boxed table of all formatted date components
getTimeFormats v returns boxed array of all formatted time components

daysDiff (verb)

usage: endtimestamp daysDiff starttimestamp result: Numeric array of time difference for x-y in days.fraction-of-days format. y: Numeric start date,time in Y M D h m s format. x: Numeric end date,time in Y M D h m s format.

fmtDate (verb)

eg: ‘is: DDDD, D MMM, YYYY’ fmtDate toDayNumber 6!:0’’ result: Formated date string (or array of boxed, formated date strings) y: Numeric array of dates given as Day Numbers x: Optional format string specifing format of result.

  Use the following codes to specify the date format:
  —— ——– ———- —————
  D: 1 DD: 01 DDD: Sun DDDD: Sunday
  M: 1 MM: 01 MMM: Jan MMMM: January
          YY: 09 YYYY: 2009
  —— ——– ———- —————
  To display any of the letters (DMY) that are codes,
  “escape” them with \.

fmtTime (verb)

eg: ‘Tii: hh:mm:ss’ fmtTime 86400 * 1|toDayNumber 6!:0 ’’ result: Formated time string (or array of boxed, formated time strings) y: Numeric array of times given as time in seconds since start of the day. x: Optional format string specifing format of result.

   Use the following codes to specify the date format:
   days (d), hours (h), minutes (m), seconds (s),
   fractions of a second (c), or AM/PM designator (p):
  —- – —- – —- – —- — —- — —- —
     d 1 h 1 m 1 s 1 c 1 p a
            hh 01 mm 01 ss 01 cc 01 pp am
                           sss 1.2 ccc 001
  —- – —- – —- – —- — —- — —- —
   If no p designator is present, 24 hour format is used.
   To display any of the letters (dhmscp) that are codes,
   “escape” them with \.

fromJulian (verb)

eg: fromJulian toJulian toDayNo 6!:0 ’’ note: Dates before 1800 1 1 are not supported.

getTimeZoneInfo (verb)

eg: getTimeZoneInfo ’’ result: 3-item list of boxed info:

  0{:: Daylight saving status (0 unknown, 1 standarddate, 2 daylightdate)
  1{:: Bias (offset of local zone from UTC in minutes)
  2{:: 2 by 3 boxed table: Standard,Daylight by Name,StartDate,Bias

J0Date (noun)

Add to J’s day number to get Julian day number

Note

For astronomical use, the start of a Julian day
is noon. So for an accurate representation of a Julian day/time
combination 2378496.5 should be added instead.

Linux0DateTime (noun)

Add to Linux-style date to get a J day number

MS0Date (noun)

Add to Microsoft date to get a J day number

Note

The first date supported by Microsoft Excel is 1900 1 1
but dates between 1900 1 1 and 1900 1 28 will not convert properly
because Excel incorrectly denotes 1900 as a leap year,
http://support.microsoft.com/kb/214326

toDateTime (verb)

eg: 1 toDateTime toDayNo 6!:0 ’’
result: Numeric array in date/time format specified by x.
y: Array of J day numbers.
x: Optional boolean specifying output format. Default 0.
  0 : date/time format yyyy mm dd hh mm ss.sss
  1 : date/time format yyyymmdd.hhmmss.sss

note: Dates before 1800 1 1 are not supported.

toDayNo (verb)

Extends verb todayno to handle time
eg: toDayNo 6!:0 ’’
result: Numeric array as J day numbers, decimal part represent time.
y: Numeric array in date/time format specified by x.
x: Optional boolean specifying input format. Default 0.
   0 : date/time format yyyy mm dd hh mm ss.sss
   1 : date/time format yyyymmdd.hhmmss.sss

note: Dates before 1800 1 1 are not supported.

toJulian (verb)

eg: toJulian toDayNo 6!:0 ’’
note: Dates before 1800 1 1 are not supported.
Add another 0.5 to get true Julian day number where noon is
regarded as the start of the day.

tsDiff (verb)

usage: endtimestamp tsDiff starttimestamp result: Numeric array of time difference for x-y in Y M D h m s format. y: Numeric start date,time in Y M D h m s format. x: Numeric end date,time in Y M D h m s format.

tsMinus (verb)

eg: 2009 3 1 1 30 0 tsMinus 5 0 0 NB. subtract 5 hours from timestamp result: Array of resulting numeric timestamp(s) in Y M D h m s format. y: Array of numeric time(s) to subtract from x.

  Format: [[[[[Y] M] D] h] m] s

x: Array of numeric timestamps to subtract y from.

  Format: Y [M [D [h [m [s]]]]]

tsPlus (verb)

eg: 2009 2 28 20 30 0 tsPlus 5 0 0 NB. add 5 hours to timestamp

2009 2 28 20 30 0 tsPlus 34 5 0 0 NB. add 34 days, 5 hours to timestamp

result: Array of resulting numeric timestamp(s) in Y M D h m s format y: Array of numeric time(s) to add to x.

  Format: [[[[[Y] M] D] h] m] s

x: Array of numeric timestamps to add y to.

  Format: Y [M [D [h [m [s]]]]]