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

DateTime parse without date not working properly #413

Closed
ilyakuzmin opened this issue Nov 2, 2023 · 5 comments · Fixed by #415
Closed

DateTime parse without date not working properly #413

ilyakuzmin opened this issue Nov 2, 2023 · 5 comments · Fixed by #415

Comments

@ilyakuzmin
Copy link

> DateTime.current
Mon, 16 May 2022 16:00:00 +0300

> DateTime.now_without_mock_time
Thu, 02 Nov 2023 03:04:10 +0300

> DateTime.parse('15:00:00')
Tue, 17 May 2022 15:00:00 +0000

I assume it's about round for TimeStackItem#travel_offset_days

Or need one more case for parse_with_mock_date

> DateTime._parse('15:00:00')
{:hour=>15, :min=>0, :sec=>0}
@joshuacronemeyer
Copy link
Collaborator

Seems like you have a good handle on this. Can you create a PR?

@joshuacronemeyer
Copy link
Collaborator

joshuacronemeyer commented Nov 2, 2023

Was thinking about this and wanted to see more test cases. Seems like the correct behavior is to keep the Date part and only change the time

3.0.1 :002 > Time.now
 => 2023-11-02 07:30:29.518102 -0700
3.0.1 :003 > DateTime.parse('06:00:00')
 => Thu, 02 Nov 2023 06:00:00 +0000
3.0.1 :004 > DateTime.parse('01:00:00')
 => Thu, 02 Nov 2023 01:00:00 +0000
3.0.1 :005 > DateTime.parse('15:00:00')
 => Thu, 02 Nov 2023 15:00:00 +0000

@ilyakuzmin
Copy link
Author

It depends on frozen time you use. Not sure what we can do with all this case in parse_with_mock_date, too much variations

case 1 correct

> Time.now
2022-08-02 09:50:00 +0300

> DateTime.parse("15:00:00")
Tue, 02 Aug 2022 15:00:00 +0000

> Timecop.top_stack_item
#<Timecop::TimeStackItem:... @travel_offset=-39521870.819318704

> 39521870.0 / 60 / 60 / 24
457.429050925926

> Timecop.top_stack_item.travel_offset_days
-457

case 2 incorrect

> Time.now
2022-08-02 05:50:00 +0300

> DateTime.parse("15:00:00")
Mon, 01 Aug 2022 15:00:00 +0000

> Timecop.top_stack_item
#<Timecop::TimeStackItem:... @travel_offset=-39536896.712171

> 39536896.0 / 60 / 60 / 24
457.602962962963

> Timecop.top_stack_item.travel_offset_days
-458

@joshuacronemeyer joshuacronemeyer linked a pull request Dec 29, 2023 that will close this issue
@joshuacronemeyer
Copy link
Collaborator

@ilyakuzmin does this fix it?

#415

@joshuacronemeyer
Copy link
Collaborator

I am going to merge that fix. Please reopen @ilyakuzmin if this issue is not fixed on main

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 a pull request may close this issue.

2 participants