From 6fa4ef4cf40215699e1f60378049f1ad7747da4f Mon Sep 17 00:00:00 2001 From: surdeus Date: Thu, 18 Jan 2024 21:35:58 +0300 Subject: [PATCH] feat: added jsons.Timestamp. --- cmd/hook/main.go | 4 ++++ jsons/main.go | 18 ++++++++++++++++-- jsons/timestamp_test.go | 14 ++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 jsons/timestamp_test.go diff --git a/cmd/hook/main.go b/cmd/hook/main.go index a5af35e..5d01d7b 100644 --- a/cmd/hook/main.go +++ b/cmd/hook/main.go @@ -81,6 +81,10 @@ Def( c.SetStatus(statuses.OK) }), //), +).Def( + "auth", + bond.Func(func(c *bond.Context){ + }) )) func main() { diff --git a/jsons/main.go b/jsons/main.go index 54f795c..b805e30 100644 --- a/jsons/main.go +++ b/jsons/main.go @@ -3,10 +3,10 @@ package jsons import ( "strconv" "encoding/json" + //"errors" + "time" ) - - // The package implements basic types // to be used in structures that can be parsed // from the poorly structured JSON. (Like ones that make IDs strings) @@ -86,3 +86,17 @@ func (jam *ArrayMap[V]) UnmarshalJSON(bts []byte) error { return nil } + +type Timestamp int64 +func (ts *Timestamp) UnmarshalJSON(bts []byte) error { + i, err := parseInt(string(bts), 64) + if err != nil { + return err + } + *ts = Timestamp(i) + return nil +} + +func (ts Timestamp) Time() time.Time { + return time.Unix(int64(ts), 0) +} diff --git a/jsons/timestamp_test.go b/jsons/timestamp_test.go new file mode 100644 index 0000000..a2151ba --- /dev/null +++ b/jsons/timestamp_test.go @@ -0,0 +1,14 @@ +package jsons + +//import "time" +import "testing" + +func TestTimestampJson(t *testing.T) { + //wantStr := "Thu Jan 18 2024 17:33:01 GMT+0300" + gotStr := "1705588381" + got := Timestamp(0) + err := got.UnmarshalJSON([]byte(gotStr)) + if err != nil { + t.Errorf("JSON unmarshalling error: %s", err) + } +}