snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
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
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
This commit is contained in:
101
server/pkg/gvalfnc/time.go
Normal file
101
server/pkg/gvalfnc/time.go
Normal file
@@ -0,0 +1,101 @@
|
||||
package gvalfnc
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/lestrrat-go/strftime"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
func Now() time.Time {
|
||||
return time.Now()
|
||||
}
|
||||
|
||||
func Quarter(in any) (int, error) {
|
||||
t, _, err := PrepMod(in, 0)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return int(t.Month() / 4), nil
|
||||
}
|
||||
|
||||
func Year(in any) (int, error) {
|
||||
t, _, err := PrepMod(in, 0)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return t.Year(), nil
|
||||
}
|
||||
|
||||
func Month(in any) (int, error) {
|
||||
t, _, err := PrepMod(in, 0)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return int(t.Month()), nil
|
||||
}
|
||||
|
||||
func Date(in any) (time.Time, error) {
|
||||
t, _, err := PrepMod(in, 0)
|
||||
return time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location()), err
|
||||
}
|
||||
|
||||
func Day(in any) (int, error) {
|
||||
t, _, err := PrepMod(in, 0)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return t.Day(), nil
|
||||
}
|
||||
|
||||
func PrepMod(base interface{}, mod interface{}) (*time.Time, int, error) {
|
||||
var (
|
||||
t *time.Time
|
||||
)
|
||||
|
||||
switch auxt := base.(type) {
|
||||
case time.Time:
|
||||
t = &auxt
|
||||
case *time.Time:
|
||||
t = auxt
|
||||
case string:
|
||||
tt, err := cast.ToTimeE(auxt)
|
||||
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
t = &tt
|
||||
default:
|
||||
return nil, 0, errors.New("unexpected input type")
|
||||
}
|
||||
|
||||
m, err := cast.ToIntE(mod)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return t, m, nil
|
||||
}
|
||||
|
||||
// Strftime formats time with POSIX standard format
|
||||
// More details here:
|
||||
// https://github.com/lestrrat-go/strftime#supported-conversion-specifications
|
||||
func StrfTime(base interface{}, f string) (string, error) {
|
||||
t, _, err := PrepMod(base, 0)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
o, _ := strftime.Format(f, *t,
|
||||
strftime.WithMilliseconds('b'),
|
||||
strftime.WithUnixSeconds('L'))
|
||||
|
||||
return o, nil
|
||||
}
|
||||
Reference in New Issue
Block a user