Skip to content

Commit

Permalink
fix bug - 000 end to timestamp (#33)
Browse files Browse the repository at this point in the history
* remove the 000 timestmp

* remove wednesday checking

---------

Co-authored-by: tbal999 <[email protected]>
  • Loading branch information
tbal999 and tbal999 authored Mar 20, 2024
1 parent 353b4d4 commit 98098e0
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 32 deletions.
18 changes: 9 additions & 9 deletions jlib/timeparse/testdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
{
"testDesc": "/* source explicit UTC, Local = 2023-08-06T00:23:41.454Z+01:00 */",
"input_srcTs": "2023-08-06T00:23:41.454Z",
"input_srcFormat": "2006-01-02T15:04:05Z",
"input_srcFormat": "2006-01-02T15:04:05.000Z",
"input_srcTz": "UTC",
"output_srcTz": "Europe/London",
"DateDim": {
Expand All @@ -42,7 +42,7 @@
"YearDay": 2023218,
"DateId": "Dates_20230806",
"DateKey": 20230806,
"DateTimeKey": 20230806012341000,
"DateTimeKey": 20230806012341454,
"HourId": "Hours_2023080601",
"HourKey": 2023080601,
"Millis": 1691281421454,
Expand Down Expand Up @@ -70,7 +70,7 @@
"YearDay": 2023218,
"DateId": "Dates_20230806",
"DateKey": 20230806,
"DateTimeKey": 20230806002341000,
"DateTimeKey": 20230806002341454,
"HourId": "Hours_2023080600",
"HourKey": 2023080600,
"Millis": 1691277821454,
Expand Down Expand Up @@ -98,7 +98,7 @@
"YearDay": 2023218,
"DateId": "Dates_20230806",
"DateKey": 20230806,
"DateTimeKey": 20230806002341000,
"DateTimeKey": 20230806002341454,
"HourId": "Hours_2023080600",
"HourKey": 2023080600,
"Millis": 1691277821454,
Expand All @@ -121,12 +121,12 @@
"TimeZone": "America/New_York",
"TimeZoneOffset": "-04:00",
"YearMonth": 202308,
"YearWeek": 202330,
"YearWeek": 202331,
"YearIsoWeek": 202331,
"YearDay": 2023217,
"DateId": "Dates_20230805",
"DateKey": 20230805,
"DateTimeKey": 20230805192341000,
"DateTimeKey": 20230805192341454,
"HourId": "Hours_2023080519",
"HourKey": 2023080519,
"Millis": 1691277821454,
Expand Down Expand Up @@ -154,7 +154,7 @@
"YearDay": 2023218,
"DateId": "Dates_20230806",
"DateKey": 20230806,
"DateTimeKey": 20230806002341000,
"DateTimeKey": 20230806002341454,
"HourId": "Hours_2023080600",
"HourKey": 2023080600,
"Millis": 1691277821454,
Expand All @@ -177,12 +177,12 @@
"TimeZone": "Europe/London",
"TimeZoneOffset": "+00:00",
"YearMonth": 202301,
"YearWeek": 202300,
"YearWeek": 202301,
"YearIsoWeek": 202301,
"YearDay": 2023006,
"DateId": "Dates_20230106",
"DateKey": 20230106,
"DateTimeKey": 20230106002341000,
"DateTimeKey": 20230106002341454,
"HourId": "Hours_2023010600",
"HourKey": 2023010600,
"Millis": 1672964621454,
Expand Down
84 changes: 70 additions & 14 deletions jlib/timeparse/testdata_lite.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,51 @@
"DateDim": {
"TimeZone": "UTC",
"TimeZoneOffset": "+00:00",
"YearMonth": 202308,
"YearWeek": 202330,
"YearIsoWeek": 202331,
"YearDay": 2023218,
"DateId": "Dates_20230806",
"DateKey": 20230806,
"DateTimeKey": 20230806002341000,
"HourId": "Hours_2023080600",
"HourKey": 2023080600,
"Millis": 1691281421000,
"RawValue": "2023-08-06T00:23:41Z",
"UTC": "2023-08-06T00:23:41.000Z",
"DateUTC": "2023-08-06",
"HourUTC": 0,
"Local": "2023-08-06T00:23:41.000+00:00",
"DateLocal": "2023-08-06"
"DateLocal": "2023-08-06",
"HourLocal": 0
}
},
{
"testDesc": "/* source explicit UTC, Local = 2023-08-06T00:23:41.454Z+01:00 */",
"input_srcTs": "2023-08-06T00:23:41.454Z",
"input_srcFormat": "2006-01-02T15:04:05Z",
"input_srcFormat": "2006-01-02T15:04:05.000Z",
"input_srcTz": "UTC",
"output_srcTz": "Europe/London",
"DateDim": {
"TimeZone": "Europe/London",
"TimeZoneOffset": "+01:00",
"YearMonth": 202308,
"YearWeek": 202330,
"YearIsoWeek": 202331,
"YearDay": 2023218,
"DateId": "Dates_20230806",
"DateKey": 20230806,
"DateTimeKey": 20230806012341000,
"DateTimeKey": 20230806012341454,
"HourId": "Hours_2023080601",
"HourKey": 2023080601,
"Millis": 1691281421454,
"RawValue": "2023-08-06T00:23:41.454Z",
"UTC": "2023-08-06T00:23:41.454Z",
"DateUTC": "2023-08-06",
"HourUTC": 0,
"Local": "2023-08-06T01:23:41.454+01:00",
"DateLocal": "2023-08-06"
"DateLocal": "2023-08-06",
"HourLocal": 1
}
},
{
Expand All @@ -48,15 +64,23 @@
"DateDim": {
"TimeZone": "Europe/London",
"TimeZoneOffset": "+01:00",
"YearMonth": 202308,
"YearWeek": 202330,
"YearIsoWeek": 202331,
"YearDay": 2023218,
"DateId": "Dates_20230806",
"DateKey": 20230806,
"DateTimeKey": 20230806002341000,
"DateTimeKey": 20230806002341454,
"HourId": "Hours_2023080600",
"HourKey": 2023080600,
"Millis": 1691277821454,
"RawValue": "2023-08-06T00:23:41.454+01:00",
"UTC": "2023-08-05T23:23:41.454Z",
"DateUTC": "2023-08-05",
"HourUTC": 23,
"Local": "2023-08-06T00:23:41.454+01:00",
"DateLocal": "2023-08-06"
"DateLocal": "2023-08-06",
"HourLocal": 0
}
},
{
Expand All @@ -68,15 +92,23 @@
"DateDim": {
"TimeZone": "Europe/London",
"TimeZoneOffset": "+01:00",
"YearMonth": 202308,
"YearWeek": 202330,
"YearIsoWeek": 202331,
"YearDay": 2023218,
"DateId": "Dates_20230806",
"DateKey": 20230806,
"DateTimeKey": 20230806002341000,
"DateTimeKey": 20230806002341454,
"HourId": "Hours_2023080600",
"HourKey": 2023080600,
"Millis": 1691277821454,
"RawValue": "2023-08-06T00:23:41.454Z",
"UTC": "2023-08-05T23:23:41.454Z",
"DateUTC": "2023-08-05",
"HourUTC": 23,
"Local": "2023-08-06T00:23:41.454+01:00",
"DateLocal": "2023-08-06"
"DateLocal": "2023-08-06",
"HourLocal": 0
}
},
{
Expand All @@ -88,15 +120,23 @@
"DateDim": {
"TimeZone": "America/New_York",
"TimeZoneOffset": "-04:00",
"YearMonth": 202308,
"YearWeek": 202331,
"YearIsoWeek": 202331,
"YearDay": 2023217,
"DateId": "Dates_20230805",
"DateKey": 20230805,
"DateTimeKey": 20230805192341000,
"DateTimeKey": 20230805192341454,
"HourId": "Hours_2023080519",
"HourKey": 2023080519,
"Millis": 1691277821454,
"RawValue": "2023-08-06T00:23:41.454Z",
"UTC": "2023-08-05T23:23:41.454Z",
"DateUTC": "2023-08-05",
"HourUTC": 23,
"Local": "2023-08-05T19:23:41.454-04:00",
"DateLocal": "2023-08-05"
"DateLocal": "2023-08-05",
"HourLocal": 19
}
},
{
Expand All @@ -108,15 +148,23 @@
"DateDim": {
"TimeZone": "Europe/London",
"TimeZoneOffset": "+01:00",
"YearMonth": 202308,
"YearWeek": 202330,
"YearIsoWeek": 202331,
"YearDay": 2023218,
"DateId": "Dates_20230806",
"DateKey": 20230806,
"DateTimeKey": 20230806002341000,
"DateTimeKey": 20230806002341454,
"HourId": "Hours_2023080600",
"HourKey": 2023080600,
"Millis": 1691277821454,
"RawValue": "2023-08-06T00:23:41.454",
"UTC": "2023-08-05T23:23:41.454Z",
"DateUTC": "2023-08-05",
"HourUTC": 23,
"Local": "2023-08-06T00:23:41.454+01:00",
"DateLocal": "2023-08-06"
"DateLocal": "2023-08-06",
"HourLocal": 0
}
},
{
Expand All @@ -128,15 +176,23 @@
"DateDim": {
"TimeZone": "Europe/London",
"TimeZoneOffset": "+00:00",
"YearMonth": 202301,
"YearWeek": 202301,
"YearIsoWeek": 202301,
"YearDay": 2023006,
"DateId": "Dates_20230106",
"DateKey": 20230106,
"DateTimeKey": 20230106002341000,
"DateTimeKey": 20230106002341454,
"HourId": "Hours_2023010600",
"HourKey": 2023010600,
"Millis": 1672964621454,
"RawValue": "2023-01-06T00:23:41.454",
"UTC": "2023-01-06T00:23:41.454Z",
"DateUTC": "2023-01-06",
"HourUTC": 0,
"Local": "2023-01-06T00:23:41.454+00:00",
"DateLocal": "2023-01-06"
"DateLocal": "2023-01-06",
"HourLocal": 0
}
}
]
12 changes: 5 additions & 7 deletions jlib/timeparse/timeparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package timeparse
import (
"fmt"
"strconv"
"strings"
"time"
)

Expand Down Expand Up @@ -95,7 +96,9 @@ func TimeDateDimensions(inputSrcTs, inputSrcFormat, inputSrcTz, requiredTz strin
return nil, err
}

dateTimeID := localTime.Format("20060102150405000")
dateTimeID := localTime.Format("20060102150405.000")

dateTimeID = strings.ReplaceAll(dateTimeID, ".", "")

dateTimeKeyInt, err := strconv.Atoi(dateTimeID)
if err != nil {
Expand Down Expand Up @@ -138,12 +141,7 @@ func TimeDateDimensions(inputSrcTs, inputSrcFormat, inputSrcTz, requiredTz strin
func getWeekOfYearString(date time.Time) (int, error) {
_, week := date.ISOWeek()

firstWednesday := date.AddDate(0, 0, -int(date.Weekday())+1)
if firstWednesday.Weekday() != time.Wednesday {
firstWednesday = firstWednesday.AddDate(0, 0, 7-int(firstWednesday.Weekday())+int(time.Wednesday))
}

if date.Weekday() == time.Sunday || date.Before(firstWednesday) {
if date.Weekday() == time.Sunday {
week--
}

Expand Down
3 changes: 2 additions & 1 deletion jlib/timeparse/timeparse_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package timeparse_test

import (
"github.com/goccy/go-json"
"os"
"testing"

"github.com/goccy/go-json"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
jsonatatime "github.com/xiatechs/jsonata-go/jlib/timeparse"
Expand Down
5 changes: 4 additions & 1 deletion jlib/timeparse/timeparselite.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package timeparse

import (
"strconv"
"strings"
"time"
)

Expand Down Expand Up @@ -76,7 +77,9 @@ func TimeDateDimensionsLite(inputSrcTs, inputSrcFormat, inputSrcTz, requiredTz s
}

// Input time stamp TIME values (we confirmed there need to be a seperate set of UTC values)
dateTimeID := localTime.Format("20060102150405000")
dateTimeID := localTime.Format("20060102150405.000")

dateTimeID = strings.ReplaceAll(dateTimeID, ".", "")

dateTimeKeyInt, err := strconv.Atoi(dateTimeID)
if err != nil {
Expand Down

0 comments on commit 98098e0

Please sign in to comment.