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:
119
server/pkg/envoy/resource/timestamps.go
Normal file
119
server/pkg/envoy/resource/timestamps.go
Normal file
@@ -0,0 +1,119 @@
|
||||
package resource
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
Timestamp struct {
|
||||
// S is a stringified representation of the timestamp
|
||||
S string
|
||||
// T is a time representation of the timestamp
|
||||
T *time.Time
|
||||
// Tz is the timezone the timestamp will be encoded into
|
||||
Tz string
|
||||
// Tpl is the template the timestamp will be encoded into
|
||||
Tpl string
|
||||
}
|
||||
Timestamps struct {
|
||||
CreatedAt *Timestamp
|
||||
UpdatedAt *Timestamp
|
||||
DeletedAt *Timestamp
|
||||
ArchivedAt *Timestamp
|
||||
SuspendedAt *Timestamp
|
||||
}
|
||||
)
|
||||
|
||||
func (ts *Timestamp) MarshalYAML() (interface{}, error) {
|
||||
return ts.S, nil
|
||||
}
|
||||
|
||||
func (ts *Timestamp) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(ts.S)
|
||||
}
|
||||
|
||||
// MakeTimestamp initializes a Timestamp from the passed timestamp
|
||||
func MakeTimestamp(ts string) *Timestamp {
|
||||
t := toTime(ts)
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &Timestamp{
|
||||
S: ts,
|
||||
T: t,
|
||||
}
|
||||
}
|
||||
|
||||
// MakeTimestampsCUDA initializes timestamps for createdAt, updatedAt, deletedAt and archivedAt
|
||||
func MakeTimestampsCUDA(c, u, d, a *time.Time) *Timestamps {
|
||||
t := &Timestamps{}
|
||||
|
||||
if c != nil && !c.IsZero() {
|
||||
t.CreatedAt = &Timestamp{T: c}
|
||||
}
|
||||
if u != nil && !u.IsZero() {
|
||||
t.UpdatedAt = &Timestamp{T: u}
|
||||
}
|
||||
if d != nil && !d.IsZero() {
|
||||
t.DeletedAt = &Timestamp{T: d}
|
||||
}
|
||||
if a != nil && !a.IsZero() {
|
||||
t.ArchivedAt = &Timestamp{T: a}
|
||||
}
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
// MakeTimestampsCUDAS initializes timestamps for createdAt, updatedAt, deletedAt, archivedAt and suspendedAt
|
||||
func MakeTimestampsCUDAS(c, u, d, a, s *time.Time) *Timestamps {
|
||||
t := MakeTimestampsCUDA(c, u, d, a)
|
||||
|
||||
if s != nil && !s.IsZero() {
|
||||
t.SuspendedAt = &Timestamp{T: s}
|
||||
}
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
// Model stringifies the timestamps based on the passed template and timezone
|
||||
func (tt *Timestamps) Model(tpl string, tz string) (*Timestamps, error) {
|
||||
var err error
|
||||
if tt.CreatedAt != nil {
|
||||
tt.CreatedAt, err = tt.CreatedAt.Model(tpl, tz)
|
||||
}
|
||||
if tt.UpdatedAt != nil {
|
||||
tt.UpdatedAt, err = tt.UpdatedAt.Model(tpl, tz)
|
||||
}
|
||||
if tt.DeletedAt != nil {
|
||||
tt.DeletedAt, err = tt.DeletedAt.Model(tpl, tz)
|
||||
}
|
||||
if tt.ArchivedAt != nil {
|
||||
tt.ArchivedAt, err = tt.ArchivedAt.Model(tpl, tz)
|
||||
}
|
||||
if tt.SuspendedAt != nil {
|
||||
tt.SuspendedAt, err = tt.SuspendedAt.Model(tpl, tz)
|
||||
}
|
||||
|
||||
return tt, err
|
||||
}
|
||||
|
||||
// Model stringifies the timestamp based on the passed template and timezone
|
||||
func (ts *Timestamp) Model(tpl string, tz string) (*Timestamp, error) {
|
||||
if tz != "" {
|
||||
tzL, err := time.LoadLocation(tz)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
t := ts.T.In(tzL)
|
||||
ts.T = &t
|
||||
}
|
||||
|
||||
if tpl == "" {
|
||||
tpl = time.RFC3339
|
||||
}
|
||||
|
||||
ts.S = ts.T.Format(tpl)
|
||||
return ts, nil
|
||||
}
|
||||
Reference in New Issue
Block a user