March Docs

DateTime

DateTime module: date/time types and arithmetic.

Types: Date(year, month, day) -- Gregorian calendar, month 1-12, day 1-31 Time(hour, min, sec) -- 24-hour clock, all zero-based except day DateTime(date, time) -- combined date and time

Timestamps are Unix timestamps: integer seconds since 1970-01-01 00:00:00 UTC. now() returns the current time as a Unix timestamp (Int).

Calendar arithmetic assumes the proleptic Gregorian calendar throughout. Day-of-week encoding: 0 = Sunday, 1 = Monday, ..., 6 = Saturday.

Types

typeDateDate = Date(Int, Int, Int) -- year, month (1-12), day (1-31)#
typeTimeTime = Time(Int, Int, Int) -- hour (0-23), min (0-59), sec (0-59)#
typeDateTimeDateTime = DateTime(Date, Time)#

Functions

fnnownow()#

Return the current Unix timestamp as an Int (seconds since 1970-01-01 UTC).

fnfrom_timestampfrom_timestamp(ts)#

Convert a Unix timestamp (Int seconds) to a DateTime.

DateTime.from_timestamp(0) -- DateTime(Date(1970, 1, 1), Time(0, 0, 0)) DateTime.from_timestamp(86400) -- DateTime(Date(1970, 1, 2), Time(0, 0, 0))

fnto_timestampto_timestamp(dt)#

Convert a DateTime to a Unix timestamp (Int seconds since 1970-01-01 UTC).

DateTime.to_timestamp(DateTime(Date(1970, 1, 1), Time(0, 0, 0))) -- 0

fnadd_daysadd_days(dt, n)#

Add n days to a DateTime. n may be negative.

fnadd_hoursadd_hours(dt, n)#

Add n hours to a DateTime. n may be negative.

fnadd_secondsadd_seconds(dt, n)#

Add n seconds to a DateTime. n may be negative.

fnadd_msadd_ms(dt : DateTime, n : Int) : DateTime#

Add n milliseconds to a DateTime. n may be negative.

fnaddadd(dt : DateTime, dur : Int) : DateTime#

Add a Duration (stored in milliseconds) to a DateTime.

fndiff_secondsdiff_seconds(a, b)#

Difference between two DateTimes in seconds. diff_seconds(a, b) = to_timestamp(a) - to_timestamp(b).

fncomparecompare(a, b)#

Compare two DateTimes. Returns -1 if a < b, 0 if a == b, 1 if a > b.

fnday_of_weekday_of_week(dt)#

Return the day of the week for the date component of a DateTime. 0 = Sunday, 1 = Monday, ..., 6 = Saturday. (January 1, 1970 was a Thursday = 4.)

fnformatformat(dt, fmt)#

Format a DateTime as a string. Supported specifiers: %Y %m %d %H %M %S %%

Example: DateTime.format(dt, "%Y-%m-%d %H:%M:%S")

fnparseparse(s)#

Parse a DateTime from a string. Supports: "YYYY-MM-DD" and "YYYY-MM-DD HH:MM:SS". Returns Ok(DateTime) or Err(message).