Commit f1ee2377 authored by Brian Tiger Chow's avatar Brian Tiger Chow Committed by Juan Batiz-Benet

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

test(time)
expose time format var

License: MIT
Signed-off-by: default avatarBrian Tiger Chow <brian@perfmode.com>
parent cd4e23bc
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)
}
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")
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment