From 81a00957afc889e61297161c78c5a11de69ead83 Mon Sep 17 00:00:00 2001 From: rowland Date: Sun, 23 Jul 2023 13:21:59 -0400 Subject: [PATCH] Initial commit. --- go.mod | 1 + go.sum | 5 +++-- pkg/rtp/datetime.go | 17 +++++++++++++---- pkg/rtp/datetime_test.go | 10 +++++++--- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 4da77a9..9612e33 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/moov-io/rtp20022 go 1.20 require ( + cloud.google.com/go v0.110.6 github.com/moov-io/base v0.45.1 github.com/stretchr/testify v1.8.4 ) diff --git a/go.sum b/go.sum index fdae98e..18d3d40 100644 --- a/go.sum +++ b/go.sum @@ -1,17 +1,18 @@ +cloud.google.com/go v0.110.6 h1:8uYAkj3YHTP/1iwReuHPxLSbdcyc+dSBbzFMrVwDR6Q= +cloud.google.com/go v0.110.6/go.mod h1:+EYjdK8e5RME/VY/qLCAtuyALQ9q67dvuum8i+H5xsI= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU= github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0= github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4= github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/moov-io/base v0.45.0 h1:Z95U5bjLngLxPpCL/9WjJSKaEQRm5jEacRo22BsGSHI= -github.com/moov-io/base v0.45.0/go.mod h1:RsjFv2fkxJvQZ02IGT0LdrSE/89ds9TKBPjaV1CYqbY= github.com/moov-io/base v0.45.1 h1:1gZuINLBAw+HS78NLcKjSd8cH8fmA2qIHZwgYP+N/WU= github.com/moov-io/base v0.45.1/go.mod h1:F2hLIojBgQJxRWTFLRTYuta/w+z2BBgDcd5k0BSifGA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/pkg/rtp/datetime.go b/pkg/rtp/datetime.go index 516ae7c..a920f97 100644 --- a/pkg/rtp/datetime.go +++ b/pkg/rtp/datetime.go @@ -2,10 +2,11 @@ package rtp import ( "bytes" + "cloud.google.com/go/civil" "time" ) -type ISODate time.Time +type ISODate civil.Date func UnmarshalISODate(text string) ISODate { dateTime := ISODate{} @@ -109,14 +110,22 @@ func (t ISOTime) Validate() error { return err } -type xsdDate time.Time +type xsdDate civil.Date func (t *xsdDate) UnmarshalText(text []byte) error { - return _unmarshalTime(text, (*time.Time)(t), "2006-01-02") + s := string(bytes.TrimSpace(text)) + d := (*civil.Date)(t) + var err error + *d, err = civil.ParseDate(s) + if err != nil { + return err + } + return nil } func (t xsdDate) MarshalText() ([]byte, error) { - return _marshalTime((time.Time)(t), "2006-01-02") + d := (civil.Date)(t) + return d.MarshalText() } func _unmarshalTime(text []byte, t *time.Time, format string) (err error) { diff --git a/pkg/rtp/datetime_test.go b/pkg/rtp/datetime_test.go index f491cec..2fe8a02 100644 --- a/pkg/rtp/datetime_test.go +++ b/pkg/rtp/datetime_test.go @@ -1,6 +1,7 @@ package rtp_test import ( + "cloud.google.com/go/civil" "encoding/xml" "testing" "time" @@ -11,8 +12,11 @@ import ( ) func TestISODateFormat(t *testing.T) { - loc, _ := time.LoadLocation("America/New_York") - when := time.Date(2019, time.March, 21, 0, 0, 0, 0, loc) + when := civil.Date{ + Year: 2019, + Month: time.March, + Day: 21, + } require.Equal(t, rtp.ISODate(when), rtp.UnmarshalISODate("2019-03-21")) @@ -27,7 +31,7 @@ func TestISODateFormat(t *testing.T) { var read rtp.ISODate err = xml.Unmarshal([]byte("2019-03-21"), &read) require.NoError(t, err) - require.True(t, when.Equal(time.Time(read))) + require.True(t, when == (civil.Date)(read)) } func TestISODateTimeFormat(t *testing.T) {