Skip to content

Commit 447abe8

Browse files
authored
Merge pull request #107 from carlv-stripe/master
Adding support for short form of ISO8601
2 parents 7b5538a + f514ed1 commit 447abe8

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

format_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func TestDecodeDateTimeHook(t *testing.T) {
240240
},
241241
{
242242
"invalid non empty datetime",
243-
"2019-01-01",
243+
"2019-01-01abc",
244244
},
245245
}
246246
registry := NewFormats()

time.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ const (
7676
ISO8601TimeWithReducedPrecisionLocaltime = "2006-01-02T15:04"
7777
// ISO8601TimeUniversalSortableDateTimePattern represents a ISO8601 universal sortable date time pattern.
7878
ISO8601TimeUniversalSortableDateTimePattern = "2006-01-02 15:04:05"
79+
// short form of ISO8601TimeUniversalSortableDateTimePattern
80+
ISO8601TimeUniversalSortableDateTimePatternShortForm = "2006-01-02"
7981
// DateTimePattern pattern to match for the date-time format from http://tools.ietf.org/html/rfc3339#section-5.6
8082
DateTimePattern = `^([0-9]{2}):([0-9]{2}):([0-9]{2})(.[0-9]+)?(z|([+-][0-9]{2}:[0-9]{2}))$`
8183
)
@@ -84,7 +86,7 @@ var (
8486
rxDateTime = regexp.MustCompile(DateTimePattern)
8587

8688
// DateTimeFormats is the collection of formats used by ParseDateTime()
87-
DateTimeFormats = []string{RFC3339Micro, RFC3339MicroNoColon, RFC3339Millis, RFC3339MillisNoColon, time.RFC3339, time.RFC3339Nano, ISO8601LocalTime, ISO8601TimeWithReducedPrecision, ISO8601TimeWithReducedPrecisionLocaltime, ISO8601TimeUniversalSortableDateTimePattern}
89+
DateTimeFormats = []string{RFC3339Micro, RFC3339MicroNoColon, RFC3339Millis, RFC3339MillisNoColon, time.RFC3339, time.RFC3339Nano, ISO8601LocalTime, ISO8601TimeWithReducedPrecision, ISO8601TimeWithReducedPrecisionLocaltime, ISO8601TimeUniversalSortableDateTimePattern, ISO8601TimeUniversalSortableDateTimePatternShortForm}
8890

8991
// MarshalFormat sets the time resolution format used for marshaling time (set to milliseconds)
9092
MarshalFormat = RFC3339Millis

time_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var (
3333
str string // its marshalled representation
3434
utcStr string // the marshaled representation as utc
3535
}{
36+
{[]byte("2014-12-15"), time.Date(2014, 12, 15, 0, 0, 0, 0, time.UTC), "2014-12-15T00:00:00.000Z", "2014-12-15T00:00:00.000Z"},
3637
{[]byte("2014-12-15 08:00:00"), time.Date(2014, 12, 15, 8, 0, 0, 0, time.UTC), "2014-12-15T08:00:00.000Z", "2014-12-15T08:00:00.000Z"},
3738
{[]byte("2014-12-15T08:00:00"), time.Date(2014, 12, 15, 8, 0, 0, 0, time.UTC), "2014-12-15T08:00:00.000Z", "2014-12-15T08:00:00.000Z"},
3839
{[]byte("2014-12-15T08:00"), time.Date(2014, 12, 15, 8, 0, 0, 0, time.UTC), "2014-12-15T08:00:00.000Z", "2014-12-15T08:00:00.000Z"},

0 commit comments

Comments
 (0)