Files
upstream-corteza/server/pkg/expr/func_time_test.go
upstream-mirror 7e385fc126
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
2026-09-18 01:22:23 +05:00

151 lines
2.6 KiB
Go

package expr
import (
"time"
)
var (
// human genome project end
hgp = time.Date(2003, 4, 14, 0, 0, 0, 0, time.UTC)
// world's first antibiotic
wfa = time.Date(1928, 9, 128, 0, 0, 0, 0, time.UTC)
// groundhog day
ghd = time.Date(1993, 2, 2, 6, 0, 0, 0, time.FixedZone("", -5*60*60))
exampleTimeParams = map[string]interface{}{
"hgp": hgp,
"wfa": wfa,
"ghd": ghd,
"now": now,
}
)
func Example_strftime() {
eval(`strftime(ghd, "%Y-%m-%dT%H:%M:%S")`, exampleTimeParams)
// output:
// 1993-02-02T06:00:00
}
func Example_strftimeWithModTime() {
eval(`strftime(modTime(ghd, "+30m"), "%Y-%m-%dT%H:%M:%S")`, exampleTimeParams)
// output:
// 1993-02-02T06:30:00
}
func Example_strftimeWithStringValue() {
eval(`strftime("1993-02-02T06:30:00", "%Y-%m-%dT%H:%M:%S")`, exampleTimeParams)
// output:
// 1993-02-02T06:30:00
}
func Example_parseISODate() {
eval(`date("1993-02-02T06:00:00-05:00")`, nil)
// output:
// 1993-02-02 06:00:00 -0500 -0500
}
func Example_parseDate() {
eval(`date("1993-02-02 06:00:00+01:10")`, nil)
// output:
// 1993-02-02 06:00:00 +0110 +0110
}
func Example_parseDuration() {
eval(`parseDuration("2h")`, nil)
// output:
// 2h0m0s
}
func Example_earliest() {
eval(`earliest(hgp, wfa)`, exampleTimeParams)
// output:
// 1929-01-06 00:00:00 +0000 UTC
}
func Example_latest() {
eval(`latest(ghd, wfa)`, exampleTimeParams)
// output:
// 1993-02-02 06:00:00 -0500 -0500
}
func Example_isLeapYear() {
eval(`isLeapYear(ghd)`, exampleTimeParams)
// output:
// false
}
func Example_isWeekDay() {
eval(`isWeekDay(ghd)`, exampleTimeParams)
// output:
// true
}
func Example_modTime() {
eval(`modTime(ghd, "+30m")`, exampleTimeParams)
// output:
// 1993-02-02 06:30:00 -0500 -0500
}
func Example_modWeek() {
eval(`modWeek(ghd, "1")`, exampleTimeParams)
// output:
// 1993-02-09 06:00:00 -0500 -0500
}
func Example_modDate() {
eval(`modDate(ghd, "5")`, exampleTimeParams)
// output:
// 1993-02-07 06:00:00 -0500 -0500
}
func Example_modMonth() {
eval(`modMonth(ghd, "1")`, exampleTimeParams)
// output:
// 1993-03-02 06:00:00 -0500 -0500
}
func Example_modYear() {
eval(`modYear(ghd, "5")`, exampleTimeParams)
// output:
// 1998-02-02 06:00:00 -0500 -0500
}
func Example_sub() {
eval(`sub(hgp, ghd)`, exampleTimeParams)
// output:
// 321627600000
}
func Example_subErrorCheck() {
eval(`sub(ghd, hgp)`, exampleTimeParams)
// output:
// error: can not evaluate sub(ghd, hgp): expecting 2nd input to be less than 1st input
}
func Example_unix() {
eval(`strftime(ghd, "%L")`, exampleTimeParams)
// output:
// 728650800
}