1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-26 15:42:21 +08:00

feat(util/time) impl RFC3339Nano UTC utility Format/Parse functions

test(time)
expose time format var

License: MIT
Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
This commit is contained in:
Brian Tiger Chow
2014-11-13 18:18:13 -08:00
committed by Juan Batiz-Benet
parent cd4e23bc2e
commit f1ee23770d
2 changed files with 33 additions and 0 deletions

17
util/time.go Normal file
View File

@ -0,0 +1,17 @@
package util
import "time"
var TimeFormatIpfs = time.RFC3339Nano
func ParseRFC3339(s string) (time.Time, error) {
t, err := time.Parse(TimeFormatIpfs, s)
if err != nil {
return time.Time{}, err
}
return t.UTC(), nil
}
func FormatRFC3339(t time.Time) string {
return t.UTC().Format(TimeFormatIpfs)
}

16
util/time_test.go Normal file
View File

@ -0,0 +1,16 @@
package util
import (
"testing"
"time"
)
func TestTimeFormatParseInversion(t *testing.T) {
v, err := ParseRFC3339(FormatRFC3339(time.Now()))
if err != nil {
t.Fatal(err)
}
if v.Location() != time.UTC {
t.Fatal("Time should be UTC")
}
}