diff --git a/duration.go b/duration.go index cf9391f7..7851d103 100644 --- a/duration.go +++ b/duration.go @@ -47,8 +47,8 @@ func (d Duration) MarshalText() ([]byte, error) { const ( day = 24 * time.Hour - month = 30 * day // Assumed to be 30 days. - year = 12 * month // Assumed to be non-leap year. + month = 30 * day // Assumed to be 30 days. + year = 365 * day // Assumed to be non-leap year. ) var ( diff --git a/duration_test.go b/duration_test.go index 29ea82f4..7302ed2c 100644 --- a/duration_test.go +++ b/duration_test.go @@ -46,12 +46,12 @@ var durationUnmarshalTests = []struct { {[]byte("PT1M"), time.Minute, nil}, {[]byte("PT1H"), time.Hour, nil}, {[]byte("-PT1H"), -time.Hour, nil}, - {[]byte("P1D"), day, nil}, - {[]byte("P1M"), month, nil}, - {[]byte("P1Y"), year, nil}, - {[]byte("P2Y3M4DT5H6M7.000000008S"), 2*year + 3*month + 4*day + 5*time.Hour + 6*time.Minute + 7*time.Second + 8*time.Nanosecond, nil}, + {[]byte("P1D"), 24 * time.Hour, nil}, + {[]byte("P1M"), 720 * time.Hour, nil}, + {[]byte("P1Y"), 8760 * time.Hour, nil}, + {[]byte("P2Y3M4DT5H6M7.000000008S"), 19781*time.Hour + 6*time.Minute + 7*time.Second + 8*time.Nanosecond, nil}, {[]byte("P0Y0M0DT0H0M0S"), 0, nil}, - {[]byte("P0001Y"), year, nil}, + {[]byte("PT0001.0000S"), time.Second, nil}, {[]byte(""), 0, errors.New("invalid duration ()")}, {[]byte("12345"), 0, errors.New("invalid duration (12345)")}, {[]byte("P1D1M1Y"), 0, errors.New("invalid duration (P1D1M1Y)")},