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

Date.strptime doesn't work correctly today. #434

Open
mikdiet opened this issue Dec 30, 2024 · 6 comments
Open

Date.strptime doesn't work correctly today. #434

mikdiet opened this issue Dec 30, 2024 · 6 comments

Comments

@mikdiet
Copy link

mikdiet commented Dec 30, 2024

In my test I have a line (added just 2 month ago) that used to work, but fails today.

It's not wrapped in any timecop helpers. Actually I could reproduce it in irb:

> Date.strptime('wednesday', '%A')
(irb):2:in `<main>': invalid date (Date::Error)

            Date.strptime_without_mock_date("#{year} #{week} #{d[:wday]}", '%Y %W %w', start)
                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

but original method works.

> Date.strptime_without_mock_date('wednesday', '%A')
Wed, 01 Jan 2025

UPD: the actual string it tries to parse is "2024 53 3" - which corresponds to 32 December 🤣

@joshuacronemeyer
Copy link
Collaborator

@mikdiet nice catch. This is a bug.

@joshuacronemeyer
Copy link
Collaborator

@mikdiet are you interested in submitting a PR for this?

The problem looks to be that at the end of the year we might need to return a date from next year but our code is always calling Date.strptime_without_mock_date with the current mocked year.

I think the fix is going to be getting the year from the un-mocked method, computing the year offset of the mocked date and then adding it to the result of the un-mocked method.

@joshuacronemeyer
Copy link
Collaborator

joshuacronemeyer commented Dec 30, 2024

here is what i was thinking but I am not sure how to write a test for it. I think I need to mock the result of the unmocked time so that we can simulate what we're seeing today (last week of the year) #436

@joshuacronemeyer
Copy link
Collaborator

Ok, never mind that solution isn't quite right... I'll wait to hear if you are going to make a PR. If not I'll figure out how to write a test for this and go for there.

@mikdiet
Copy link
Author

mikdiet commented Dec 31, 2024

@mikdiet are you interested in submitting a PR for this?

hello @joshuacronemeyer - no, I wasn't intending to fix this myself.

@jchapa
Copy link

jchapa commented Jan 3, 2025

@joshuacronemeyer - first commit to this project, but I think I found a way to test / fix this scenario.

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

When branches are created from issues, their pull requests are automatically linked.

3 participants