Skip to content

Commit

Permalink
Fix year const, only use time consts in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mabeyj committed May 26, 2017
1 parent 0299b2a commit 1dfacae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
10 changes: 5 additions & 5 deletions duration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)")},
Expand Down

0 comments on commit 1dfacae

Please sign in to comment.