Skip to content

Commit

Permalink
adds csvDateReplacer
Browse files Browse the repository at this point in the history
  • Loading branch information
ivoputzer committed Oct 11, 2023
1 parent f12302a commit 61e3a1e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/date.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,15 @@ export function jsonDateReviver (_, value, iso8601Regex = /^\d{4}-\d{2}-\d{2}T\d
? new Date(value)
: value
}

export function csvDateReplacer (_, value) {
return Array.isArray(value)
? value.map(replaceIfDate)
: replaceIfDate(value)

function replaceIfDate (date) {
return date instanceof Date
? date.toISOString().slice(0, 16).replace('T', ' ')
: date
}
}

0 comments on commit 61e3a1e

Please sign in to comment.