Skip to content

Commit

Permalink
changed the default to truncate
Browse files Browse the repository at this point in the history
that’s probably the more common case
  • Loading branch information
ansel1 committed Dec 12, 2018
1 parent c71d002 commit d38402f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions map.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,22 +191,22 @@ func EmptyMapValuesMatchAny() ContainsOption {
// to parse any string values back into time.Time values. This allows correct processing of
// the time.Time zero values.
//
// If rounding is > 0, times will be rounded. If ignoreTimeZone is true, the location data will
// If truncation is > 0, times will be truncation. If ignoreTimeZone is true, the location data will
// be stripped off the time values before comparison.
func ParseDates(rounding time.Duration, ignoreTimeZone bool) ContainsOption {
func ParseDates(truncation time.Duration, ignoreTimeZone bool) ContainsOption {
return func(o *containsOptions) {
o.parseDates = true
o.roundDates = rounding
o.truncateDates = truncation
o.stripTimeZone = ignoreTimeZone
}
}

// TruncateDates is like ParseDates, but truncates time values rather than rounding them.
// RoundDates is like ParseDates, but rounds time values rather than truncating them.
// If both options are specified, truncation will be applied first.
func TruncateDates(truncation time.Duration, ignoreTimeZone bool) ContainsOption {
func RoundDates(rounding time.Duration, ignoreTimeZone bool) ContainsOption {
return func(o *containsOptions) {
o.parseDates = true
o.truncateDates = truncation
o.roundDates = rounding
o.stripTimeZone = ignoreTimeZone
}
}
Expand Down
16 changes: 8 additions & 8 deletions maps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,24 +336,24 @@ func TestContains(t *testing.T) {
expected: false,
},
{
name: "rounddates",
v1: map[string]interface{}{"t": t1},
v2: map[string]interface{}{"t": t1.Add(time.Nanosecond)},
name: "truncatedates",
v1: map[string]interface{}{"t": t1.Truncate(time.Microsecond).Add(900 * time.Nanosecond)},
v2: map[string]interface{}{"t": t1.Truncate(time.Microsecond).Add(100 * time.Nanosecond)},
options: []ContainsOption{EmptyMapValuesMatchAny(), ParseDates(time.Microsecond, true)},
expected: true,
},
{
name: "rounddoesnttruncatedates",
name: "rounddates",
v1: map[string]interface{}{"t": t1.Truncate(time.Microsecond).Add(900 * time.Nanosecond)},
v2: map[string]interface{}{"t": t1.Truncate(time.Microsecond).Add(100 * time.Nanosecond)},
options: []ContainsOption{EmptyMapValuesMatchAny(), ParseDates(time.Microsecond, true)},
options: []ContainsOption{EmptyMapValuesMatchAny(), RoundDates(time.Microsecond, true)},
expected: false,
},
{
name: "truncatedates",
name: "rounddates",
v1: map[string]interface{}{"t": t1.Truncate(time.Microsecond).Add(900 * time.Nanosecond)},
v2: map[string]interface{}{"t": t1.Truncate(time.Microsecond).Add(100 * time.Nanosecond)},
options: []ContainsOption{EmptyMapValuesMatchAny(), TruncateDates(time.Microsecond, true)},
v2: map[string]interface{}{"t": t1.Truncate(time.Microsecond).Add(700 * time.Nanosecond)},
options: []ContainsOption{EmptyMapValuesMatchAny(), RoundDates(time.Microsecond, true)},
expected: true,
},
{
Expand Down

0 comments on commit d38402f

Please sign in to comment.