Skip to content

Commit

Permalink
add adjustments (#23)
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 20, 2023
1 parent bfdb0aa commit 48c87cf
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 120 deletions.
3 changes: 2 additions & 1 deletion jlib/jlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,6 @@ func TypeOf(x interface{}) (string, error) {
}

xType := reflect.TypeOf(x).String()
return "", fmt.Errorf("unknown type %s", xType)

return xType, nil
}
35 changes: 21 additions & 14 deletions jlib/timeparse/testdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
"YearIsoWeek": 202331,
"YearDay": 2023218,
"DateId": "Dates_20230806",
"DateKey": "20230806",
"DateKey": 20230806,
"DateTimeKey": 20230806002341000,
"HourId": "Hours_2023080600",
"HourKey": "2023080600",
"HourKey": 2023080600,
"Millis": 1691281421000,
"RawValue": "2023-08-06T00:23:41Z",
"UTC": "2023-08-06T00:23:41.000Z",
Expand All @@ -40,9 +41,10 @@
"YearIsoWeek": 202331,
"YearDay": 2023218,
"DateId": "Dates_20230806",
"DateKey": "20230806",
"DateKey": 20230806,
"DateTimeKey": 20230806012341000,
"HourId": "Hours_2023080601",
"HourKey": "2023080601",
"HourKey": 2023080601,
"Millis": 1691281421454,
"RawValue": "2023-08-06T00:23:41.454Z",
"UTC": "2023-08-06T00:23:41.454Z",
Expand All @@ -67,9 +69,10 @@
"YearIsoWeek": 202331,
"YearDay": 2023218,
"DateId": "Dates_20230806",
"DateKey": "20230806",
"DateKey": 20230806,
"DateTimeKey": 20230806002341000,
"HourId": "Hours_2023080600",
"HourKey": "2023080600",
"HourKey": 2023080600,
"Millis": 1691277821454,
"RawValue": "2023-08-06T00:23:41.454+01:00",
"UTC": "2023-08-05T23:23:41.454Z",
Expand All @@ -94,9 +97,10 @@
"YearIsoWeek": 202331,
"YearDay": 2023218,
"DateId": "Dates_20230806",
"DateKey": "20230806",
"DateKey": 20230806,
"DateTimeKey": 20230806002341000,
"HourId": "Hours_2023080600",
"HourKey": "2023080600",
"HourKey": 2023080600,
"Millis": 1691277821454,
"RawValue": "2023-08-06T00:23:41.454Z",
"UTC": "2023-08-05T23:23:41.454Z",
Expand All @@ -121,9 +125,10 @@
"YearIsoWeek": 202331,
"YearDay": 2023217,
"DateId": "Dates_20230805",
"DateKey": "20230805",
"DateKey": 20230805,
"DateTimeKey": 20230805192341000,
"HourId": "Hours_2023080519",
"HourKey": "2023080519",
"HourKey": 2023080519,
"Millis": 1691277821454,
"RawValue": "2023-08-06T00:23:41.454Z",
"UTC": "2023-08-05T23:23:41.454Z",
Expand All @@ -148,9 +153,10 @@
"YearIsoWeek": 202331,
"YearDay": 2023218,
"DateId": "Dates_20230806",
"DateKey": "20230806",
"DateKey": 20230806,
"DateTimeKey": 20230806002341000,
"HourId": "Hours_2023080600",
"HourKey": "2023080600",
"HourKey": 2023080600,
"Millis": 1691277821454,
"RawValue": "2023-08-06T00:23:41.454",
"UTC": "2023-08-05T23:23:41.454Z",
Expand All @@ -175,9 +181,10 @@
"YearIsoWeek": 202301,
"YearDay": 2023006,
"DateId": "Dates_20230106",
"DateKey": "20230106",
"DateKey": 20230106,
"DateTimeKey": 20230106002341000,
"HourId": "Hours_2023010600",
"HourKey": "2023010600",
"HourKey": 2023010600,
"Millis": 1672964621454,
"RawValue": "2023-01-06T00:23:41.454",
"UTC": "2023-01-06T00:23:41.454Z",
Expand Down
91 changes: 21 additions & 70 deletions jlib/timeparse/testdata_lite.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,15 @@
"DateDim": {
"TimeZone": "UTC",
"TimeZoneOffset": "+00:00",
"YearMonth": 0,
"YearWeek": 0,
"YearIsoWeek": 0,
"YearDay": 0,
"DateId": "Dates_20230806",
"DateKey": "20230806",
"HourId": "",
"HourKey": "",
"DateKey": 20230806,
"DateTimeKey": 20230806002341000,
"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",
"HourLocal": 0
"DateLocal": "2023-08-06"
}
},
{
Expand All @@ -35,22 +28,15 @@
"DateDim": {
"TimeZone": "Europe/London",
"TimeZoneOffset": "+00:00",
"YearMonth": 0,
"YearWeek": 0,
"YearIsoWeek": 0,
"YearDay": 0,
"DateId": "Dates_20230806",
"DateKey": "20230806",
"HourId": "",
"HourKey": "",
"DateKey": 20230806,
"DateTimeKey": 20230806012341000,
"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",
"HourLocal": 0
"DateLocal": "2023-08-06"
}
},
{
Expand All @@ -62,22 +48,15 @@
"DateDim": {
"TimeZone": "Europe/London",
"TimeZoneOffset": "+00:00",
"YearMonth": 0,
"YearWeek": 0,
"YearIsoWeek": 0,
"YearDay": 0,
"DateId": "Dates_20230806",
"DateKey": "20230806",
"HourId": "",
"HourKey": "",
"DateKey": 20230806,
"DateTimeKey": 20230806002341000,
"Millis": 1691277821454,
"RawValue": "2023-08-06T00:23:41.454+01:00",
"UTC": "2023-08-05T23:23:41.454Z",
"DateUTC": "2023-08-05",
"HourUTC": 0,
"Local": "2023-08-06T00:23:41.454+01:00",
"DateLocal": "2023-08-06",
"HourLocal": 0
"DateLocal": "2023-08-06"
}
},
{
Expand All @@ -89,22 +68,15 @@
"DateDim": {
"TimeZone": "Europe/London",
"TimeZoneOffset": "+00:00",
"YearMonth": 0,
"YearWeek": 0,
"YearIsoWeek": 0,
"YearDay": 0,
"DateId": "Dates_20230806",
"DateKey": "20230806",
"HourId": "",
"HourKey": "",
"DateKey": 20230806,
"DateTimeKey": 20230806002341000,
"Millis": 1691277821454,
"RawValue": "2023-08-06T00:23:41.454Z",
"UTC": "2023-08-05T23:23:41.454Z",
"DateUTC": "2023-08-05",
"HourUTC": 0,
"Local": "2023-08-06T00:23:41.454+01:00",
"DateLocal": "2023-08-06",
"HourLocal": 0
"DateLocal": "2023-08-06"
}
},
{
Expand All @@ -116,22 +88,15 @@
"DateDim": {
"TimeZone": "America/New_York",
"TimeZoneOffset": "+00:00",
"YearMonth": 0,
"YearWeek": 0,
"YearIsoWeek": 0,
"YearDay": 0,
"DateId": "Dates_20230805",
"DateKey": "20230805",
"HourId": "",
"HourKey": "",
"DateKey": 20230805,
"DateTimeKey": 20230805192341000,
"Millis": 1691277821454,
"RawValue": "2023-08-06T00:23:41.454Z",
"UTC": "2023-08-05T23:23:41.454Z",
"DateUTC": "2023-08-05",
"HourUTC": 0,
"Local": "2023-08-05T19:23:41.454-04:00",
"DateLocal": "2023-08-05",
"HourLocal": 0
"DateLocal": "2023-08-05"
}
},
{
Expand All @@ -143,22 +108,15 @@
"DateDim": {
"TimeZone": "Europe/London",
"TimeZoneOffset": "+00:00",
"YearMonth": 0,
"YearWeek": 0,
"YearIsoWeek": 0,
"YearDay": 0,
"DateId": "Dates_20230806",
"DateKey": "20230806",
"HourId": "",
"HourKey": "",
"DateKey": 20230806,
"DateTimeKey": 20230806002341000,
"Millis": 1691277821454,
"RawValue": "2023-08-06T00:23:41.454",
"UTC": "2023-08-05T23:23:41.454Z",
"DateUTC": "2023-08-05",
"HourUTC": 0,
"Local": "2023-08-06T00:23:41.454+01:00",
"DateLocal": "2023-08-06",
"HourLocal": 0
"DateLocal": "2023-08-06"
}
},
{
Expand All @@ -170,22 +128,15 @@
"DateDim": {
"TimeZone": "Europe/London",
"TimeZoneOffset": "+00:00",
"YearMonth": 0,
"YearWeek": 0,
"YearIsoWeek": 0,
"YearDay": 0,
"DateId": "Dates_20230106",
"DateKey": "20230106",
"HourId": "",
"HourKey": "",
"DateKey": 20230106,
"DateTimeKey": 20230106002341000,
"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",
"HourLocal": 0
"DateLocal": "2023-01-06"
}
}
]
27 changes: 23 additions & 4 deletions jlib/timeparse/timeparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ type DateDim struct {
YearIsoWeek int `json:"YearIsoWeek"` // int
YearDay int `json:"YearDay"` // int
DateID string `json:"DateId"` // lite
DateKey string `json:"DateKey"` // lite
DateKey int `json:"DateKey"` // lite
DateTimeKey int `json:"DateTimeKey"` // lite
HourID string `json:"HourId"`
HourKey string `json:"HourKey"`
HourKey int `json:"HourKey"`
Millis int `json:"Millis"` // lite
RawValue string `json:"RawValue"` // lite

Expand Down Expand Up @@ -90,6 +91,23 @@ func TimeDateDimensions(inputSrcTs, inputSrcFormat, inputSrcTz, requiredTz strin
return nil, err
}

dateKeyInt, err := strconv.Atoi(dateID)
if err != nil {
return nil, err
}

dateTimeID := localTime.Format("20060102150405000")

dateTimeKeyInt, err := strconv.Atoi(dateTimeID)
if err != nil {
return nil, err
}

hourKeyInt, err := strconv.Atoi(hourKeyStr)
if err != nil {
return nil, err
}

localTimeStamp := localTime.Format("2006-01-02T15:04:05.000-07:00")
// construct the date dimension structure
dateDim := &DateDim{
Expand All @@ -101,12 +119,13 @@ func TimeDateDimensions(inputSrcTs, inputSrcFormat, inputSrcTz, requiredTz strin
YearMonth: yearMonthInt,
Millis: int(localTime.UnixMilli()),
HourLocal: localTime.Hour(),
HourKey: hourKeyStr,
HourKey: hourKeyInt,
HourID: "Hours_" + hourKeyStr,
DateLocal: localTime.Format("2006-01-02"),
TimeZone: localTime.Location().String(),
Local: localTimeStamp,
DateKey: dateID,
DateKey: dateKeyInt,
DateTimeKey: dateTimeKeyInt,
DateID: "Dates_" + dateID,
DateUTC: utcAsYearMonthDay,
UTC: utcTime.Format("2006-01-02T15:04:05.000Z"),
Expand Down
Loading

0 comments on commit 48c87cf

Please sign in to comment.