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

fix(date): use available timezone if any #94

Merged
merged 9 commits into from
Dec 18, 2024
Merged

fix(date): use available timezone if any #94

merged 9 commits into from
Dec 18, 2024

Conversation

ccoVeille
Copy link
Contributor

@ccoVeille ccoVeille commented Nov 29, 2024

Description

It's important to use the date timezone if it has any.

Changes

Do not switch back to Local timezone if not needed

Fixes #81

Checklist

  • I have read the CONTRIBUTING.md document.
  • My code follows the code style of this project.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have updated the documentation accordingly.
  • This change requires a change to the documentation on the website.

Additional Information

Timezones are always fun

Copy link
Member

@42atomys 42atomys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, my turn for require package ! 😄

The catch of TZ in Date has something desired for future so nice addition

registry/time/functions_test.go Outdated Show resolved Hide resolved
registry/time/functions_test.go Outdated Show resolved Hide resolved
registry/time/functions_test.go Outdated Show resolved Hide resolved
registry/time/functions.go Outdated Show resolved Hide resolved
@42atomys 42atomys force-pushed the main branch 9 times, most recently from 8158f69 to d42c82a Compare November 30, 2024 03:23
@42atomys 42atomys added the priority/medium 🟨 Priority 3 - Not blocking but should be fixed soon label Nov 30, 2024
@ccoVeille ccoVeille marked this pull request as draft November 30, 2024 09:38
@ccoVeille
Copy link
Contributor Author

There are more work to do. toDate is also affected by the "implicit" timezone conversion.

I started fixing locally, but now I'm busy IRL

@42atomys
Copy link
Member

No problem @ccoVeille IRL > all
takes your time ! If you need help don't hesitate to ask me

@ccoVeille ccoVeille requested a review from 42atomys December 2, 2024 20:55
@ccoVeille ccoVeille marked this pull request as ready for review December 2, 2024 20:55
@ccoVeille
Copy link
Contributor Author

Added tests, fixed code, refactored a bit things that frustrated me

@42atomys
Copy link
Member

42atomys commented Dec 3, 2024

@ccoVeille fyi : some issues on tests on CI

@ccoVeille
Copy link
Contributor Author

I'm still able to learn things about how timezones are handled after a few decades 😓

And apparently, I'm not the only one
golang/go#56528

https://pkg.go.dev/time#Parse

When parsing a time with a zone offset like -0700, if the offset corresponds to a time zone used by the current location (Local), then Parse uses that location and zone in the returned time. Otherwise it records the time as being in a fabricated location with time fixed at the given zone offset.

When parsing a time with a zone abbreviation like MST, if the zone abbreviation has a defined offset in the current location, then that offset is used. The zone abbreviation "UTC" is recognized as UTC regardless of location. If the zone abbreviation is unknown, Parse records the time as being in a fabricated location with the given zone abbreviation and a zero offset. This choice means that such a time can be parsed and reformatted with the same layout losslessly, but the exact instant used in the representation will differ by the actual zone offset. To avoid such problems, prefer time layouts that use a numeric zone offset, or use ParseInLocation.

Said otherwise, the format displaying a zone in addition of the format causes troubles, the result varies between the timezone, and only the one matching the time.Local one will have a zone. So to test this, we must temporarily force the time.Local, and handle all the use cases.

Another solution could be rewritten the test to avoid using a format including the zone, the time offset could be enough.

registry/time/helpers.go Outdated Show resolved Hide resolved
registry/time/helpers.go Outdated Show resolved Hide resolved
registry/time/functions_test.go Show resolved Hide resolved
registry/time/helpers_test.go Outdated Show resolved Hide resolved
@42atomys
Copy link
Member

42atomys commented Dec 5, 2024

This kind of discovery are always interesting, discover something when dig deeper is a really good feeling

@ccoVeille ccoVeille force-pushed the fix-timezone branch 2 times, most recently from 78b7e8e to 5945298 Compare December 12, 2024 23:01
@ccoVeille ccoVeille requested a review from 42atomys December 12, 2024 23:07
.golangci.yaml Outdated Show resolved Hide resolved
registry/time/functions.go Outdated Show resolved Hide resolved
@42atomys 42atomys linked an issue Dec 12, 2024 that may be closed by this pull request
@ccoVeille
Copy link
Contributor Author

@42atomys is there anything you wait from me?

@42atomys
Copy link
Member

@ccoVeille No I don't, I just wait the "request review" but I assume you have just forgot, I will review now and go forward if all are good 🏁

Copy link
Member

@42atomys 42atomys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ✅

@42atomys 42atomys merged commit 5f8850e into main Dec 18, 2024
16 checks passed
@42atomys 42atomys deleted the fix-timezone branch December 18, 2024 14:53
Copy link

codecov bot commented Dec 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Files with missing lines Coverage Δ
handler.go 100.0% <100.0%> (ø)
pesticide/time_test_helpers.go 100.0% <100.0%> (ø)
registry/conversion/functions.go 100.0% <100.0%> (ø)
registry/time/functions.go 100.0% <100.0%> (ø)
registry/time/helpers.go 100.0% <100.0%> (ø)
sprigin/sprig_backward_compatibility.go 100.0% <100.0%> (ø)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority/medium 🟨 Priority 3 - Not blocking but should be fixed soon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

chore: adding importas linter bug: Tests fail locally if local timezone != UTC
2 participants