From d38402f4b62b69051558b039bffd1820db35ff8e Mon Sep 17 00:00:00 2001 From: Russ Egan Date: Wed, 12 Dec 2018 16:03:44 -0600 Subject: [PATCH] changed the default to truncate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit that’s probably the more common case --- map.go | 12 ++++++------ maps_test.go | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/map.go b/map.go index 5298e9a..1bac515 100644 --- a/map.go +++ b/map.go @@ -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 } } diff --git a/maps_test.go b/maps_test.go index 24b4ce2..d4d3c93 100644 --- a/maps_test.go +++ b/maps_test.go @@ -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, }, {