gdDocumentation0.8.0

API reference

GD.time

Entry for converting and computing Unix time, ISO 8601, and HTTP dates. parse_iso accepts RFC 3339, and add and diff clamp at the 64-bit integer ends.

Methods

now

now() -> int

Return the current Unix timestamp.

Parameters

No parameters.

Return value

int

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

to_parts

to_parts(unix: int) -> Dictionary

Split a Unix timestamp into date-time components.

Parameters

NameTypeDefaultDescription
unixintRequiredUnix timestamp measured in seconds.

Return value

Dictionary

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

from_parts

from_parts(parts: Dictionary) -> int

Convert date-time components into a Unix timestamp.

Parameters

NameTypeDefaultDescription
partsDictionaryRequiredComponents assembled by the operation, in the representation shown by the type.

Return value

int

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

to_iso

to_iso(unix: int) -> String

Format a Unix timestamp as ISO 8601 text.

Parameters

NameTypeDefaultDescription
unixintRequiredUnix timestamp measured in seconds.

Return value

String

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

to_http

to_http(unix: int) -> String

Format a Unix timestamp as an HTTP date.

Parameters

NameTypeDefaultDescription
unixintRequiredUnix timestamp measured in seconds.

Return value

String

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

parse_iso

parse_iso(text: String) -> int, Err

Parse ISO 8601 text into a Unix timestamp.

Parameters

NameTypeDefaultDescription
textStringRequiredText to inspect, decode or transform; the input is not modified in place.

Return value

int, Err

Errors

The result carries a value and an Err. Check the error before using the value; a failure may retain partial progress. In a function returning value, Err, use ? to propagate failure to the caller. The ! operator terminates the program on failure; in serve it fails the current handler.

add

add(unix: int, amount: int, unit: String = "second") -> int

Add an amount in the specified unit to a Unix timestamp.

Parameters

NameTypeDefaultDescription
unixintRequiredUnix timestamp measured in seconds.
amountintRequiredSigned number of the requested time units to add.
unitString"second"Time unit used for addition or comparison.

Return value

int

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

diff

diff(a: int, b: int, unit: String = "second") -> int

Return the difference between timestamps in the specified unit.

Parameters

NameTypeDefaultDescription
aintRequiredFirst Unix timestamp in seconds.
bintRequiredSecond Unix timestamp in seconds.
unitString"second"Time unit used for addition or comparison.

Return value

int

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

start_of_day

start_of_day(unix: int) -> int

Return the start of the same UTC day.

Parameters

NameTypeDefaultDescription
unixintRequiredUnix timestamp measured in seconds.

Return value

int

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

weekday

weekday(unix: int) -> int

Return the weekday number for a Unix timestamp.

Parameters

NameTypeDefaultDescription
unixintRequiredUnix timestamp measured in seconds.

Return value

int

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

is_leap

is_leap(year: int) -> bool

Check whether a year is a leap year.

Parameters

NameTypeDefaultDescription
yearintRequiredCalendar year used for date calculations.

Return value

bool

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

days_in_month

days_in_month(year: int, month: int) -> int

Return the number of days in a month.

Parameters

NameTypeDefaultDescription
yearintRequiredCalendar year used for date calculations.
monthintRequiredCalendar month numbered from 1 through 12.

Return value

int

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

ago

ago(unix: int, base: int = -1) -> String

Format a timestamp relative to a reference time.

Parameters

NameTypeDefaultDescription
unixintRequiredUnix timestamp measured in seconds.
baseint-1Reference Unix timestamp in seconds.

Return value

String

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

format

format(unix: int, pattern: String) -> String

Format a Unix timestamp with the specified pattern.

Parameters

NameTypeDefaultDescription
unixintRequiredUnix timestamp measured in seconds.
patternStringRequiredDate/time formatting pattern.

Return value

String

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.