Skip to content

Commit 1dfacae

Browse files
committed
Fix year const, only use time consts in tests
1 parent 0299b2a commit 1dfacae

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

duration.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ func (d Duration) MarshalText() ([]byte, error) {
4747

4848
const (
4949
day = 24 * time.Hour
50-
month = 30 * day // Assumed to be 30 days.
51-
year = 12 * month // Assumed to be non-leap year.
50+
month = 30 * day // Assumed to be 30 days.
51+
year = 365 * day // Assumed to be non-leap year.
5252
)
5353

5454
var (

duration_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ var durationUnmarshalTests = []struct {
4646
{[]byte("PT1M"), time.Minute, nil},
4747
{[]byte("PT1H"), time.Hour, nil},
4848
{[]byte("-PT1H"), -time.Hour, nil},
49-
{[]byte("P1D"), day, nil},
50-
{[]byte("P1M"), month, nil},
51-
{[]byte("P1Y"), year, nil},
52-
{[]byte("P2Y3M4DT5H6M7.000000008S"), 2*year + 3*month + 4*day + 5*time.Hour + 6*time.Minute + 7*time.Second + 8*time.Nanosecond, nil},
49+
{[]byte("P1D"), 24 * time.Hour, nil},
50+
{[]byte("P1M"), 720 * time.Hour, nil},
51+
{[]byte("P1Y"), 8760 * time.Hour, nil},
52+
{[]byte("P2Y3M4DT5H6M7.000000008S"), 19781*time.Hour + 6*time.Minute + 7*time.Second + 8*time.Nanosecond, nil},
5353
{[]byte("P0Y0M0DT0H0M0S"), 0, nil},
54-
{[]byte("P0001Y"), year, nil},
54+
{[]byte("PT0001.0000S"), time.Second, nil},
5555
{[]byte(""), 0, errors.New("invalid duration ()")},
5656
{[]byte("12345"), 0, errors.New("invalid duration (12345)")},
5757
{[]byte("P1D1M1Y"), 0, errors.New("invalid duration (P1D1M1Y)")},

0 commit comments

Comments
 (0)