All Date functions
Name | Function header | Example | Result | Description | Errorhandling |
---|---|---|---|---|---|
ago | func(date interface{}) string | [[ $result := ago (dateModify now "-15m") ]] |
$result = “15m0s” | returns the duration time between a specific timestamp and now. | |
date | func(date interface{}, fmt string) string | [[ $result := date 1638860002 "02.01.2006 03:04" ]] |
$result = “07.12.2021 07:53” | converts a date to the string specific output format. Date can be time, int, int32 or int64. | |
dateInZone | func(date interface{}, fmt string, zone string) string | [[ $result := dateInZone ( toDate "2021-12-12T12:12:12+0100" "2006-01-02T15:04:05-0700" ) "02.01.2006 15:04" "Europe/Zurich" ]] |
$result = “12.12.2021 12:12” | zone can be “”, “UTC” or location name corresponding to a file in the IANA Time Zone database, such as “America/New_York” or “Europe/Zurich”. | |
dateModify | func(date Time, duration string) Time | [[ $result := dateModify ( toDate "2021-12-12T12:12:12+0100" "2006-01-02T15:04:05-0700" ) "+01h30m20s" ]] |
$result = “2021-12-12 13:42:32 +0100 CET” | changes the output time with the entered duration time. You can add or substract time. | |
htmlDate | func(date interface{}) string | [[ $result := htmlDate ( toDate "2021-12-12T12:12:12+0100" "2006-01-02T15:04:05-0700" ) ]] |
$result = “2021-12-12” | converts a date into a string for html. Output format is fix to YYYY-MM-DD, localtime. (HTML5 RFC 3339) | |
htmlDateInZone | func(date Time, zone string) Time | [[ $result := htmlDateInZone ( toDate "2021-12-12T17:12:12+0100" "2006-01-02T15:04:05-0700" ) "Asia/Shanghai" ]] |
$result = “2021-12-13” | converts a date into a string for html for a specific timezone. Output format is fix to YYYY-MM-DD in the specific timezone. (HTML5 RFC 3339) | |
now | func() time.Time | [[ $result := now ]] |
$result = “2021-12-06 10:59:00.1744468 +0100 CET m=+160.128715901” | returns the actual date and time. | |
toDate | func(str string, fmt string) Time | [[ $result := toString (toDate "2021-12-07T12:12:12+0100" "2006-01-02T15:04:05-0700") ]] |
$result = “2021-12-07 12:12:12 +0100 CET” | converts a string to a date. The first argument is the date layout and the second the date string. | |
unixEpoch | func(date Time) string | [[ $result := unixEpoch (toDate (date now "2006-01-02T15:04:05-0700") "2006-01-02T15:04:05-0700" ) ]] |
$result = “1638903549” | converts a date to a string in unix epoch format. |
func(date interface{}) string
The ago
function returns the duration time between a specific timestamp and now.
Examples
[[ $result := ago (dateModify now "-15m") ]]
$result = "15m0s"
[[ $result := ago ( toDate "2021-12-07T12:12:12+0100" "2006-01-02T15:04:05-0700" ) ]]
$result = "3h0m19s" {{ /* value is dynamic because of now*/}}
func(date interface{}, fmt string) string
The date
function converts a date to the string specific output format. The input date can be time, int, int32 or int64. In the integer cases (int,int32,int64), it is treated as seconds since UNIX epoch.
Examples
[[ $result := date ( toDate "2021-12-12T12:12:12+0100" "2006-01-02T15:04:05-0700" ) "02.01.2006 04:05" ]]
$result = "12.12.2021 12:12"
[[ $result := date ( toDate "2021-09-01T12:12:12+0100" "2006-01-02T15:04:05-0700" ) "2.1.2006 04:05" ]]
$result = "12.12.2021 12:12"
[[ $result := date 1638860002 "02.01.2006 03:04" ]]
$result = "1.9.2021 07:53"
[[ $result := date 1638860002 "2006-01-02T15:04:05-0700" ]]
$result = "2021-12-07T07:53:22+0100"
References
func(date interface{}, fmt string, zone string) string
The dateInZone
function is equal to function date, but here you can set the timezone in a string. zone can be “”, “UTC” or location name corresponding to a file in the IANA Time Zone database, such as “America/New_York” or “Europe/Zurich”.
Examples
[[ $result := dateInZone now "2006-01-02T15:04:05-0700" "UTC" ]]
$result = "2021-12-07T14:58:13+0000"
[[ $result := dateInZone ( toDate "2021-12-12T12:12:12+0100" "2006-01-02T15:04:05-0700" ) "02.01.2006 15:04" "Europe/Zurich" ]]
$result = "12.12.2021 12:12"
func(date Time, duration string) Time
The dateModify
function changes the output time with the entered duration time. You can add or substract time.
Application notes / Limits:
Examples
[[ $result := toString (dateModify ( toDate "2021-12-12T12:12:12+0100" "2006-01-02T15:04:05-0700" ) "+01h30m20s") ]]
$result = "2021-12-12 13:42:32 +0100 CET"
result is an object of time.Time.
[[ $result := dateModify ( toDate "2021-12-12T12:12:12+0100" "2006-01-02T15:04:05-0700" ) "+01h30m20s" ]]
$result = time.Time{"2021-12-12 13:42:32 +0100 CET"}
now minus 15 minutes. now: this result changes in each test, because of "now"
[[ $result := toString (dateModify now "-15m") ]]
$result = "2021-12-07 18:04:18.1344825 +0100 CET m=+15867.925608201"
result is an object of time.Time.
[[ $result := dateModify now "-15m" ]]
$result = "2021-12-07 18:04:18.1344825 +0100 CET m=+15867.925608201"
func(date interface{}) string
The htmlDate
function converts a date into a string for html. The HTML5 date input specification refers to the RFC 3339 specification, which specifies a full-date format equal to: yyyy-mm-dd.
Examples
Date Input String
[[ $result := htmlDate ( toDate "2021-12-12T12:12:12+0100" "2006-01-02T15:04:05-0700" ) ]]
$result = "2021-12-12"
Date Integer
[[ $result := htmlDate 1638860002 ]]
$result = "2021-12-07"
References
func(date Time, zone string) Time
The htmlDateInZone
function converts a date into a string for html for a specific timezone. Output format is fix to YYYY-MM-DD in the specific timezone.
The HTML5 date input specification refers to the RFC 3339 specification, which specifies a full-date format equal to: yyyy-mm-dd.
Examples
htmlDateInZone now
[[ $result := htmlDateInZone now "UTC" ]]
$result = "2021-12-07"
Date Input String "Asia/Shanghai"
[[ $result := htmlDateInZone ( toDate "2021-12-12T17:12:12+0100" "2006-01-02T15:04:05-0700" ) "Asia/Shanghai" ]]
$result = "2021-12-13"
References
func() time.Time { return time.Now() }
The now
function returns the actual date and time.
Application notes / Limits:
Examples
now: this result changes in each test, because of "now"
[[ $result := date now "2006-01-02T15:04:05-0700" ]]
$result = "2021-12-07T10:40:07+0100"
[[ $result := toString now ]]
$result = "2021-12-07 10:44:36.2676731 +0100 CET m=+1109.893927001"
func(str string, fmt string) Time
The toDate
function converts a string to a date. The first argument is the date string and the second the date layout.
Application notes / Limits:
Examples
now: this result changes in each test, because of "now"
[[ $result := toString (toDate (date now "2006-01-02T15:04:05-0700") "2006-01-02T15:04:05-0700") ]]
$result = "2021-12-07 19:42:10 +0100 CET"
result is an object of time.Time.
[[ $result := toDate (date now "2006-01-02T15:04:05-0700") "2006-01-02T15:04:05-0700" ]]
$result = time.Time{"2021-12-07 19:42:10 +0100 CET"}
example with input date
[[ $result := toString (toDate "2021-12-07T12:12:12+0100" "2006-01-02T15:04:05-0700") ]]
$result = "2021-12-07 12:12:12 +0100 CET"
result is an object of time.Time.
[[ $result := toDate "2021-12-07T12:12:12+0100" "2006-01-02T15:04:05-0700" ]]
$result = time.Time{"2021-12-07 12:12:12 +0100 CET"}
example with suppressed leading in day and month.
[[ $result := toString (date (toDate "2021-12-07T03:12:12PM" "2006-01-02T03:04:05PM") "2.1.2006 15:04:05" ) ]]
$result = "7.12.2021 15:12:12"
result is an object of time.Time.
[[ $result := date (toDate "2021-12-07T03:12:12PM" "2006-01-02T03:04:05PM") "2.1.2006 15:04:05" ]]
$result = time.Time{"7.12.2021 15:12:12"}
func(date Time) string
The unixEpoch
function converts a date to a string in unix epoch format.
Examples
Simple direct now example
now: this result changes in each test, because of "now"
[[ $result := unixEpoch now ]]
$result = "1638903549"
now: this result changes in each test, because of "now"
[[ $result := unixEpoch (toDate (date now "2006-01-02T15:04:05-0700") "2006-01-02T15:04:05-0700" ) ]]
$result = "1638903549"
[[ $result := unixEpoch (toDate "2021-12-07T12:12:12+0100" "2006-01-02T15:04:05-0700") ]]
$result = "1638875532"