Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: csv: new timezone rule; convert zoned date-times to local dates #1936

Merged
merged 1 commit into from Oct 2, 2022

Conversation

simonmichael
Copy link
Owner

Previously, CSV date-times with a different time zone from yours (with or without explicit timezones in the CSV) could give off-by-one dates, because the CSV timezone was ignored.

Now,

  1. you can use the timezone rule to indicate which other timezone a CSV is implicitly using

  2. CSV date-times with a timezone - whether declared by rule or parsed with %Z - are localised to the system time zone (or another set with the TZ environment variable).

@simonmichael simonmichael added the csv The csv file format, csv output format, or generally CSV-related. label Sep 30, 2022
@crocodile-code-review
Copy link

Review on Crocodile

@simonmichael
Copy link
Owner Author

Mail list discussion: https://groups.google.com/g/hledger/c/P3tYKCfjKfA/m/AfGUGuJFBQAJ

Docs:

timezone

timezone TIMEZONE

When CSV contains date-times that are implicitly in some time zone
other than yours, but containing no explicit time zone information,
you can use this rule to declare the CSV's native time zone,
which helps prevent off-by-one dates.

When the CSV date-times do contain time zone information,
you don't need this rule; instead, use %Z in date-format
(or %z, %EZ, %Ez; see the formatTime link above).

In either of these cases, hledger will do a time-zone-aware conversion,
localising the CSV date-times to your current system time zone.
If you prefer to localise to some other time zone, eg for reproducibility,
you can (on unix at least) set the output timezone with the TZ environment variable, eg:

$ TZ=HST hledger print -f foo.csv  # or TZ=HST hledger import foo.csv

Previously, CSV date-times with a different time zone from yours
(with or without explicit timezones in the CSV) could give off-by-one
dates, because the CSV timezone was ignored.

Now,

1. you can use the `timezone` rule to indicate which other
   timezone a CSV is implicitly using

2. CSV date-times with a timezone - whether declared by rule or
   parsed with %Z - are localised to the system time zone
   (or another set with the TZ environment variable).
@simonmichael simonmichael merged commit 4831299 into master Oct 2, 2022
@simonmichael simonmichael deleted the simon branch October 2, 2022 00:44
@simonmichael simonmichael restored the simon branch October 2, 2022 00:51
simonmichael added a commit that referenced this pull request Oct 2, 2022
…1936)

Previously, CSV date-times with a different time zone from yours
(with or without explicit timezones in the CSV) could give off-by-one
dates, because the CSV timezone was ignored.

Now,

1. you can use the `timezone` rule to indicate which other
   timezone a CSV is implicitly using

2. CSV date-times with a timezone - whether declared by rule or
   parsed with %Z - are localised to the system time zone
   (or another set with the TZ environment variable).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
csv The csv file format, csv output format, or generally CSV-related.
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

1 participant