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

Use isoFormat() instead of format() for placeholder dates #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jk-oster
Copy link

@jk-oster jk-oster commented Oct 3, 2024

What

This PR fixes an issue with incorrect year numbers on placeholder dates formatted in weeks belonging to the previous year.

Why

By default, using format("Y-W") will return the year of the current date, even if the week is technically part of the previous year. To fix this and to account for the ISO-8601 year, which can differ from the calendar year. Carbon provides the isoFormat method, which respects the ISO-8601 standard for both the year and the week.

E.g. "2022-01-02" is actually "2021-52", however the currently used method would incorrectly output "2022-52".

How

Using isoFormat() instead of format() methods of Carbon Date object together with the ISO date formatting string "GGGG-WW" solves this issue

Fixing the issue that Cardon format() does not format the date for weeks "Y-W" correctly with dates that belong to the last week of the previous year. E.g. "2022-01-02" is actually "2021-52", however usual format method would incorrectly output "2022-52"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant