travisjeffery / timecop

A gem providing "time travel", "time freezing", and "time acceleration" capabilities, making it simple to test time-dependent code. It provides a unified method to mock Time.now, Date.today, and DateTime.now in a single call.
MIT License
3.37k stars 226 forks source link

Allow other "dates of calendar reform" in Date#strptime #389

Closed scpike closed 1 year ago

scpike commented 2 years ago

Timecop is incompatible with the newest patch version of Psych (4.0.5) because of this change.

Timecop only allows Date#strptime to be called with the default of Date::ITALY as the fourth argument. This fourth argument is the "day of calendar reform" for leap years. Dates pre-reform are Julian calendar dates, which have leap years every 4 years. Dates after reform are Gregorian calendar dates, which have more complicated leap year logic (every 4 years, except if the year is divisible by 100 and not by 400). https://en.wikipedia.org/wiki/Gregorian_calendar

Psych starts calling strptime with Date::GREGORIAN as of 4.0.5 (I'm not sure why, but it's a legal use of the standard Ruby API and so it seems like Timecop shouldn't break it).

This PR updates strptime_without_mock_date to allow passing in other values for the fourth argument by passing them along to date initialization.

hiromi2424 commented 1 year ago

Also reproduced with using psych >= 3.3.3 because changes was back-ported to psych: 3.x in https://github.com/ruby/psych/pull/573

johnnyshields commented 1 year ago

Please merge and release :)

joshuacronemeyer commented 1 year ago

I was looking at this yesterday. Meant to update but I got sidetracked, thanks for bringing this up and making a PR. Tested locally and it works. Not sure why our GitHub actions didn't run all tests. Maybe a first time contributor restriction??

scpike commented 1 year ago

Thanks @joshuacronemeyer! Appreciate you taking the time to look into this.

joshuacronemeyer commented 1 year ago

You're welcome @scpike. Hey @johnnyshields we released. Thanks for the friendly nudge.