Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
rowland66 committed Jul 23, 2023
1 parent 5401d15 commit 81a0095
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
17 changes: 13 additions & 4 deletions pkg/rtp/datetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 7 additions & 3 deletions pkg/rtp/datetime_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rtp_test

import (
"cloud.google.com/go/civil"
"encoding/xml"
"testing"
"time"
Expand All @@ -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"))

Expand All @@ -27,7 +31,7 @@ func TestISODateFormat(t *testing.T) {
var read rtp.ISODate
err = xml.Unmarshal([]byte("<ISODate>2019-03-21</ISODate>"), &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) {
Expand Down

0 comments on commit 81a0095

Please sign in to comment.