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() -> intto_parts(unix: int) -> Dictionaryfrom_parts(parts: Dictionary) -> intto_iso(unix: int) -> Stringto_http(unix: int) -> Stringparse_iso(text: String) -> int, Erradd(unix: int, amount: int, unit: String = "second") -> intdiff(a: int, b: int, unit: String = "second") -> intstart_of_day(unix: int) -> intweekday(unix: int) -> intis_leap(year: int) -> booldays_in_month(year: int, month: int) -> intago(unix: int, base: int = -1) -> Stringformat(unix: int, pattern: String) -> String
now
now() -> intReturn 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) -> DictionarySplit a Unix timestamp into date-time components.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
unix | int | Required | Unix 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) -> intConvert date-time components into a Unix timestamp.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
parts | Dictionary | Required | Components 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) -> StringFormat a Unix timestamp as ISO 8601 text.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
unix | int | Required | Unix 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) -> StringFormat a Unix timestamp as an HTTP date.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
unix | int | Required | Unix 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, ErrParse ISO 8601 text into a Unix timestamp.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
text | String | Required | Text 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") -> intAdd an amount in the specified unit to a Unix timestamp.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
unix | int | Required | Unix timestamp measured in seconds. |
amount | int | Required | Signed number of the requested time units to add. |
unit | String | "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") -> intReturn the difference between timestamps in the specified unit.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
a | int | Required | First Unix timestamp in seconds. |
b | int | Required | Second Unix timestamp in seconds. |
unit | String | "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) -> intReturn the start of the same UTC day.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
unix | int | Required | Unix 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) -> intReturn the weekday number for a Unix timestamp.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
unix | int | Required | Unix 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) -> boolCheck whether a year is a leap year.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
year | int | Required | Calendar 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) -> intReturn the number of days in a month.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
year | int | Required | Calendar year used for date calculations. |
month | int | Required | Calendar 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) -> StringFormat a timestamp relative to a reference time.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
unix | int | Required | Unix timestamp measured in seconds. |
base | int | -1 | Reference 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) -> StringFormat a Unix timestamp with the specified pattern.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
unix | int | Required | Unix timestamp measured in seconds. |
pattern | String | Required | Date/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.