Skip to content

Commit

Permalink
fix offset (#26)
Browse files Browse the repository at this point in the history
Co-authored-by: tbal999 <[email protected]>
  • Loading branch information
tbal999 and tbal999 authored Nov 29, 2023
1 parent 11a33a1 commit 834811c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 27 deletions.
10 changes: 5 additions & 5 deletions jlib/timeparse/testdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"output_srcTz": "Europe/London",
"DateDim": {
"TimeZone": "Europe/London",
"TimeZoneOffset": "+00:00",
"TimeZoneOffset": "+01:00",
"YearMonth": 202308,
"YearWeek": 202330,
"YearIsoWeek": 202331,
Expand Down Expand Up @@ -63,7 +63,7 @@
"output_srcTz": "Europe/London",
"DateDim": {
"TimeZone": "Europe/London",
"TimeZoneOffset": "+00:00",
"TimeZoneOffset": "+01:00",
"YearMonth": 202308,
"YearWeek": 202330,
"YearIsoWeek": 202331,
Expand Down Expand Up @@ -91,7 +91,7 @@
"output_srcTz": "Europe/London",
"DateDim": {
"TimeZone": "Europe/London",
"TimeZoneOffset": "+00:00",
"TimeZoneOffset": "+01:00",
"YearMonth": 202308,
"YearWeek": 202330,
"YearIsoWeek": 202331,
Expand Down Expand Up @@ -119,7 +119,7 @@
"output_srcTz": "America/New_York",
"DateDim": {
"TimeZone": "America/New_York",
"TimeZoneOffset": "+00:00",
"TimeZoneOffset": "-04:00",
"YearMonth": 202308,
"YearWeek": 202330,
"YearIsoWeek": 202331,
Expand Down Expand Up @@ -147,7 +147,7 @@
"output_srcTz": "Europe/London",
"DateDim": {
"TimeZone": "Europe/London",
"TimeZoneOffset": "+00:00",
"TimeZoneOffset": "+01:00",
"YearMonth": 202308,
"YearWeek": 202330,
"YearIsoWeek": 202331,
Expand Down
10 changes: 5 additions & 5 deletions jlib/timeparse/testdata_lite.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"output_srcTz": "Europe/London",
"DateDim": {
"TimeZone": "Europe/London",
"TimeZoneOffset": "+00:00",
"TimeZoneOffset": "+01:00",
"DateId": "Dates_20230806",
"DateKey": 20230806,
"DateTimeKey": 20230806012341000,
Expand All @@ -47,7 +47,7 @@
"output_srcTz": "Europe/London",
"DateDim": {
"TimeZone": "Europe/London",
"TimeZoneOffset": "+00:00",
"TimeZoneOffset": "+01:00",
"DateId": "Dates_20230806",
"DateKey": 20230806,
"DateTimeKey": 20230806002341000,
Expand All @@ -67,7 +67,7 @@
"output_srcTz": "Europe/London",
"DateDim": {
"TimeZone": "Europe/London",
"TimeZoneOffset": "+00:00",
"TimeZoneOffset": "+01:00",
"DateId": "Dates_20230806",
"DateKey": 20230806,
"DateTimeKey": 20230806002341000,
Expand All @@ -87,7 +87,7 @@
"output_srcTz": "America/New_York",
"DateDim": {
"TimeZone": "America/New_York",
"TimeZoneOffset": "+00:00",
"TimeZoneOffset": "-04:00",
"DateId": "Dates_20230805",
"DateKey": 20230805,
"DateTimeKey": 20230805192341000,
Expand All @@ -107,7 +107,7 @@
"output_srcTz": "Europe/London",
"DateDim": {
"TimeZone": "Europe/London",
"TimeZoneOffset": "+00:00",
"TimeZoneOffset": "+01:00",
"DateId": "Dates_20230806",
"DateKey": 20230806,
"DateTimeKey": 20230806002341000,
Expand Down
18 changes: 2 additions & 16 deletions jlib/timeparse/timeparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package timeparse
import (
"fmt"
"strconv"
"strings"
"time"
)

Expand Down Expand Up @@ -109,10 +108,11 @@ func TimeDateDimensions(inputSrcTs, inputSrcFormat, inputSrcTz, requiredTz strin
}

localTimeStamp := localTime.Format("2006-01-02T15:04:05.000-07:00")
offsetStr := localTime.Format("-07:00")
// construct the date dimension structure
dateDim := &DateDim{
RawValue: inputSrcTs,
TimeZoneOffset: getOffsetString(localTimeStamp),
TimeZoneOffset: offsetStr,
YearWeek: mondayWeek,
YearDay: yearDay,
YearIsoWeek: yearIsoWeekInt,
Expand All @@ -135,20 +135,6 @@ func TimeDateDimensions(inputSrcTs, inputSrcFormat, inputSrcTz, requiredTz strin
return dateDim, nil
}

func getOffsetString(input string) string {
znegArr := strings.Split(input, "Z-")
if len(znegArr) == 2 {
return "-" + znegArr[1]
}

zposArr := strings.Split(input, "Z+")
if len(zposArr) == 2 {
return "+" + zposArr[1]
}

return "+00:00"
}

func getWeekOfYearString(date time.Time) (int, error) {
_, week := date.ISOWeek()

Expand Down
3 changes: 2 additions & 1 deletion jlib/timeparse/timeparselite.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ func TimeDateDimensionsLite(inputSrcTs, inputSrcFormat, inputSrcTz, requiredTz s
}

localTimeStamp := localTime.Format("2006-01-02T15:04:05.000-07:00")
offsetStr := localTime.Format("-07:00")
// construct the date dimension structure
dateDim := &DateDimLite{
RawValue: inputSrcTs,
TimeZoneOffset: getOffsetString(localTimeStamp),
TimeZoneOffset: offsetStr,
Millis: int(localTime.UnixMilli()),
DateLocal: localTime.Format("2006-01-02"),
TimeZone: localTime.Location().String(),
Expand Down

0 comments on commit 834811c

Please sign in to comment.