From bacc9b5ce36f2e65cb5b867e72748d2be4e548f8 Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Wed, 8 Dec 2021 11:06:02 +0100 Subject: [PATCH] removed unused argument and added fractional seconds tests --- types/core_time.go | 4 ++-- types/core_time_test.go | 21 +++++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/types/core_time.go b/types/core_time.go index 3d47d72d01200..64820f98aaf79 100644 --- a/types/core_time.go +++ b/types/core_time.go @@ -187,7 +187,7 @@ func (t CoreTime) GoTime(loc *gotime.Location) (gotime.Time, error) { // FindZoneTransition check for one Time Zone transition within +/- 4h // Currently the needed functions are not exported, if gotime.Location.lookup would be exported // then it would be easy to use that directly -func FindZoneTransition(tIn gotime.Time, loc *gotime.Location) (gotime.Time, error) { +func FindZoneTransition(tIn gotime.Time) (gotime.Time, error) { // Check most common case first, DST transition on full hour. // round truncates away from zero! t2 := tIn.Round(gotime.Hour).Add(-1 * gotime.Hour) @@ -230,7 +230,7 @@ func (t CoreTime) AdjustedGoTime(loc *gotime.Location) (gotime.Time, error) { return tm, nil } - tAdj, err2 := FindZoneTransition(tm, loc) + tAdj, err2 := FindZoneTransition(tm) if err2 == nil { return tAdj, nil } diff --git a/types/core_time_test.go b/types/core_time_test.go index 3331cc93799cd..07e4d040a5c2c 100644 --- a/types/core_time_test.go +++ b/types/core_time_test.go @@ -327,11 +327,19 @@ func TestFindZoneTransition(t *testing.T) { }{ {"Australia/Lord_Howe", "2020-06-29 03:45:00", "", false}, {"Australia/Lord_Howe", "2020-10-04 02:15:00", "2020-10-04 02:30:00 +11 +1100", true}, + {"Australia/Lord_Howe", "2020-10-04 02:29:59", "2020-10-04 02:30:00 +11 +1100", true}, + {"Australia/Lord_Howe", "2020-10-04 02:29:59.99", "2020-10-04 02:30:00 +11 +1100", true}, + {"Australia/Lord_Howe", "2020-10-04 02:30:00.0001", "2020-10-04 02:30:00 +11 +1100", true}, + {"Australia/Lord_Howe", "2020-10-04 02:30:00", "2020-10-04 02:30:00 +11 +1100", true}, + {"Australia/Lord_Howe", "2020-10-04 02:30:01", "2020-10-04 02:30:00 +11 +1100", true}, {"Europe/Vilnius", "2020-03-29 03:45:00", "2020-03-29 04:00:00 EEST +0300", true}, {"Europe/Vilnius", "2020-10-25 03:45:00", "2020-10-25 03:00:00 EET +0200", true}, {"Europe/Vilnius", "2020-06-29 03:45:00", "", false}, {"Europe/Amsterdam", "2020-03-29 02:45:00", "2020-03-29 03:00:00 CEST +0200", true}, {"Europe/Amsterdam", "2020-10-25 02:35:00", "2020-10-25 02:00:00 CET +0100", true}, + {"Europe/Amsterdam", "2020-03-29 02:59:59", "2020-03-29 03:00:00 CEST +0200", true}, + {"Europe/Amsterdam", "2020-03-29 02:59:59.999999999", "2020-03-29 03:00:00 CEST +0200", true}, + {"Europe/Amsterdam", "2020-03-29 03:00:00.000000001", "2020-03-29 03:00:00 CEST +0200", true}, } for _, tt := range tests { @@ -339,12 +347,12 @@ func TestFindZoneTransition(t *testing.T) { require.NoError(t, err) tm, err := time.ParseInLocation("2006-01-02 15:04:05", tt.dt, loc) require.NoError(t, err) - tp, err := FindZoneTransition(tm, loc) + tp, err := FindZoneTransition(tm) if !tt.Success { require.Error(t, err) } else { require.NoError(t, err) - require.Equal(t, tt.Expect, tp.Format("2006-01-02 15:04:05 MST -0700")) + require.Equal(t, tt.Expect, tp.Format("2006-01-02 15:04:05.999999999 MST -0700")) } } } @@ -357,16 +365,21 @@ func TestAdjustedGoTime(t *testing.T) { Expect string Success bool }{ + {"Australia/Lord_Howe", FromDate(2020, 10, 04, 01, 59, 59, 997), "2020-10-04 01:59:59.000997 +1030 +1030", true}, + {"Australia/Lord_Howe", FromDate(2020, 10, 04, 02, 00, 00, 0), "2020-10-04 02:30:00 +11 +1100", true}, {"Australia/Lord_Howe", FromDate(2020, 10, 04, 02, 15, 00, 0), "2020-10-04 02:30:00 +11 +1100", true}, + {"Australia/Lord_Howe", FromDate(2020, 10, 04, 02, 29, 59, 999999), "2020-10-04 02:30:00 +11 +1100", true}, + {"Australia/Lord_Howe", FromDate(2020, 10, 04, 02, 30, 00, 1), "2020-10-04 02:30:00.000001 +11 +1100", true}, {"Australia/Lord_Howe", FromDate(2020, 06, 29, 03, 45, 00, 0), "2020-06-29 03:45:00 +1030 +1030", true}, {"Australia/Lord_Howe", FromDate(2020, 04, 04, 01, 45, 00, 0), "2020-04-04 01:45:00 +11 +1100", true}, {"Europe/Vilnius", FromDate(2020, 03, 29, 03, 45, 00, 0), "2020-03-29 04:00:00 EEST +0300", true}, + {"Europe/Vilnius", FromDate(2020, 03, 29, 03, 59, 59, 456789), "2020-03-29 04:00:00 EEST +0300", true}, + {"Europe/Vilnius", FromDate(2020, 03, 29, 04, 00, 01, 130000), "2020-03-29 04:00:01.13 EEST +0300", true}, {"Europe/Vilnius", FromDate(2020, 10, 25, 03, 45, 00, 0), "2020-10-25 03:45:00 EET +0200", true}, {"Europe/Vilnius", FromDate(2020, 06, 29, 03, 45, 00, 0), "2020-06-29 03:45:00 EEST +0300", true}, {"Europe/Amsterdam", FromDate(2020, 03, 29, 02, 45, 00, 0), "2020-03-29 03:00:00 CEST +0200", true}, {"Europe/Amsterdam", FromDate(2020, 10, 25, 02, 35, 00, 0), "2020-10-25 02:35:00 CET +0100", true}, {"UTC", FromDate(2020, 2, 31, 02, 35, 00, 0), "", false}, - // TODO: Test out-of-range values? } for _, tt := range tests { @@ -377,7 +390,7 @@ func TestAdjustedGoTime(t *testing.T) { require.Error(t, err) } else { require.NoError(t, err) - require.Equal(t, tt.Expect, tp.Format("2006-01-02 15:04:05 MST -0700")) + require.Equal(t, tt.Expect, tp.Format("2006-01-02 15:04:05.999999999 MST -0700")) } } }