Skip to content

Commit

Permalink
enhance date formatting support in CSV and stream processing
Browse files Browse the repository at this point in the history
- Added support for 'DDD' (abbreviated day of the week) in GetISO8601DateMap function.
- Updated Iso8601ToGoLayout to handle 'DDD' and 'TZD' (time zone designator) formats.
- Included new date format "Mon, 02 Jan 2006 15:04:05 -0700" in stream processor initialization.
- Modified DateTimeState struct to include 'DDD' for JSON serialization and updated the Update method accordingly.
  • Loading branch information
flarco committed Jan 6, 2025
1 parent dea9175 commit d8dae23
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/dbio/iop/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ func detectDelimiter(delimiter string, testBytes []byte) (bestDeli rune, numCols
// GetISO8601DateMap return a map of date parts for string formatting
func GetISO8601DateMap(t time.Time) map[string]interface{} {
m := map[string]interface{}{}
for _, v := range []string{"YYYY", "YY", "MMM", "MM", "DD", "HH", "hh", "mm", "ss"} {
for _, v := range []string{"YYYY", "YY", "MMM", "MM", "DD", "DDD", "HH", "hh", "mm", "ss"} {
m[v] = t.Format(Iso8601ToGoLayout(v))
}
return m
Expand All @@ -607,11 +607,13 @@ func GetISO8601DateMap(t time.Time) map[string]interface{} {
// https://www.iso.org/iso-8601-date-and-time-format.html
func Iso8601ToGoLayout(dateFormat string) (goDateFormat string) {
goDateFormat = strings.TrimSpace(dateFormat)
goDateFormat = strings.ReplaceAll(goDateFormat, "TZD", "-07:00")
goDateFormat = strings.ReplaceAll(goDateFormat, "YYYY", "2006")
goDateFormat = strings.ReplaceAll(goDateFormat, "YY", "06")
goDateFormat = strings.ReplaceAll(goDateFormat, "MMM", "Jan")
goDateFormat = strings.ReplaceAll(goDateFormat, "MM", "01")
goDateFormat = strings.ReplaceAll(goDateFormat, "DD", "02")
goDateFormat = strings.ReplaceAll(goDateFormat, "DDD", "Mon")
goDateFormat = strings.ReplaceAll(goDateFormat, "HH", "15")
goDateFormat = strings.ReplaceAll(goDateFormat, "hh", "03")
goDateFormat = strings.ReplaceAll(goDateFormat, "mm", "04")
Expand Down
1 change: 1 addition & 0 deletions core/dbio/iop/stream_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ func NewStreamProcessor() *StreamProcessor {
"2006/01/02 15:04:05",
"02-01-2006",
"02-01-2006 15:04:05",
"Mon, 02 Jan 2006 15:04:05 -0700",
}

// up to 90 digits. This is done for CastToStringSafeMask
Expand Down
2 changes: 2 additions & 0 deletions core/sling/task_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type DateTimeState struct {
MMM string `json:"MMM,omitempty"`
MM string `json:"MM,omitempty"`
DD string `json:"DD,omitempty"`
DDD string `json:"DDD,omitempty"`
HH string `json:"HH,omitempty"`
}

Expand All @@ -50,6 +51,7 @@ func (dts *DateTimeState) Update() {
dts.MM = now.Format("01")
dts.DD = now.Format("02")
dts.HH = now.Format("15")
dts.DDD = now.Format("Mon")
}

type RunState struct {
Expand Down

0 comments on commit d8dae23

Please sign in to comment.