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

Formatter Gives correct year for dates near start/end of Year #40410

Conversation

adam-james-v
Copy link
Contributor

Fixes: #40306

Our datetime formatter relies on the java-time.api, for which there are many different, sometimes confusing, formatter patterns: https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatterBuilder.html#appendPattern-java.lang.String-

In this case, 'YYYY' is a week-of-year style year, which calculates which week a date falls into before returning the year. Sometimes days near the start/end of a year will fall into a week in the wrong year.

For example, apparently 2023-12-31 falls into the 1st week of 2024, which probably not the year you'd expect to see. What we probably do want is 'yyyy' which calculates what day of the year the date is and then returns the year based off of that instead of the week number.

For an explanation, you can check out this SO answer: https://stackoverflow.com/a/46395342 provides an explanation.

I've opted just to do a str/replace in the post-processing of our formatter because many existing cards may have column formatting entries in their viz-settings with the 'YYYY' format.

Fixes: #40306

Our datetime formatter relies on the `java-time.api`, for which there are many different, sometimes confusing, formatter patterns: https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatterBuilder.html#appendPattern-java.lang.String-

In this case, 'YYYY' is a week-of-year style year, which calculates which week a date falls into before returning the
year. Sometimes days near the start/end of a year will fall into a week in the wrong year.

For example, apparently 2023-12-31 falls into the 1st week of 2024, which probably not the year you'd expect to
see. What we probably do want is 'yyyy' which calculates what day of the year the date is and then returns the year
based off of that instead of the week number.

For an explanation, you can check out this SO answer: https://stackoverflow.com/a/46395342 provides an explanation.
@metabase-bot metabase-bot bot added the .Team/DashViz Dashboard and Viz team label Mar 20, 2024
@adam-james-v adam-james-v added the backport Automatically create PR on current release branch on merge label Mar 20, 2024
Copy link

replay-io bot commented Mar 20, 2024

Status In Progress ↗︎ 51 / 52
Commit 3f6f298
Results
⚠️ 6 Flaky
2365 Passed

Copy link
Contributor

@bshepherdson bshepherdson left a comment

Choose a reason for hiding this comment

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

See my commentary on Slack about the long-term fate of this code.

But this specific change LGTM as a patch to the current state.

@adam-james-v adam-james-v merged commit 104f18c into master Mar 21, 2024
124 of 142 checks passed
@adam-james-v adam-james-v deleted the bugfix-40306-correct-year-for-dates-near-start-or-end-of-year branch March 21, 2024 15:09
Copy link
Contributor

@adam-james-v Did you forget to add a milestone to the issue for this PR? When and where should I add a milestone?

github-actions bot pushed a commit that referenced this pull request Mar 21, 2024
Fixes: #40306

Our datetime formatter relies on the `java-time.api`, for which there are many different, sometimes confusing, formatter patterns: https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatterBuilder.html#appendPattern-java.lang.String-

In this case, 'YYYY' is a week-of-year style year, which calculates which week a date falls into before returning the
year. Sometimes days near the start/end of a year will fall into a week in the wrong year.

For example, apparently 2023-12-31 falls into the 1st week of 2024, which probably not the year you'd expect to
see. What we probably do want is 'yyyy' which calculates what day of the year the date is and then returns the year
based off of that instead of the week number.

For an explanation, you can check out this SO answer: https://stackoverflow.com/a/46395342 provides an explanation.
metabase-bot bot added a commit that referenced this pull request Mar 21, 2024
#40450)

Fixes: #40306

Our datetime formatter relies on the `java-time.api`, for which there are many different, sometimes confusing, formatter patterns: https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatterBuilder.html#appendPattern-java.lang.String-

In this case, 'YYYY' is a week-of-year style year, which calculates which week a date falls into before returning the
year. Sometimes days near the start/end of a year will fall into a week in the wrong year.

For example, apparently 2023-12-31 falls into the 1st week of 2024, which probably not the year you'd expect to
see. What we probably do want is 'yyyy' which calculates what day of the year the date is and then returns the year
based off of that instead of the week number.

For an explanation, you can check out this SO answer: https://stackoverflow.com/a/46395342 provides an explanation.

Co-authored-by: adam-james <21064735+adam-james-v@users.noreply.github.com>
@adam-james-v adam-james-v added this to the 0.49.2 milestone Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport Automatically create PR on current release branch on merge .Team/DashViz Dashboard and Viz team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exporting date values changes the year
2 participants