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

weekly rule DST issue #551

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

larskuhnt
Copy link
Contributor

@larskuhnt larskuhnt commented Apr 24, 2024

Hi,

I added some specs for the following edge case where the calculation of the next occurrences returns faulty values.
The base of this issue is IceCube::WeeklyRule.realign when an occurrence happens within a DST time switch. For example on 26th April 2024 00:00 -> 01:00. Realign will change the start_time of e.g. 22th May 2022 00:20 to 26th April 2024 01:20 and then the starting hour is wrong. The result is occurrences with the time 01:20 instead of 00:20.

Thanks
Lars

@pacso
Copy link
Collaborator

pacso commented Apr 25, 2024

Hi @larskuhnt,

Thank you for your contribution ... this looks great! Just a couple of comments, but otherwise looks spot on. 👍🏻

@pacso
Copy link
Collaborator

pacso commented Apr 26, 2024

Don't worry about fixing the linting issues ... that is resolved on #552 which I'll merge first.

I'm just waiting on @seejohnrun updating my access so I can actually fix things.

@larskuhnt
Copy link
Contributor Author

Hi @pacso,
your comment #551 (comment) was very helpful as it showed a flaw in my approach to fix this issue. I added some more specs now and decided to realign the time to a day before the DST switch for this special case to keep the timezone information. The only issue with this approach could be when the DST switch happens on a monday/sunday so that the realigned time is in the previous week. But I am not sure about that.

@pacso
Copy link
Collaborator

pacso commented May 9, 2024

@larskuhnt - could you please pull master and see whether this fixes all of the tests?

@larskuhnt
Copy link
Contributor Author

@pacso I merged master and the specs are green on my side.

@pacso
Copy link
Collaborator

pacso commented May 13, 2024

@larskuhnt - Could you resolve the linting errors?

@larskuhnt
Copy link
Contributor Author

@pacso all checks pass now

@pacso
Copy link
Collaborator

pacso commented May 13, 2024

Amazing, thank you! I'll do a proper review either at lunch or after work and get this merged in 👍🏻

Comment on lines +38 to +47
realigned_time = time.to_time
# when the realigned time is in a different hour, it means that
# time falls to the DST switch timespan. In this case, we need to
# move the time back by one day to ensure that the hour stays the same
# WARNING: this could not work if the DST change is on a monday
# as the realigned time would be moved to the previous week.
if realigned_time.hour != start_time.hour
time.add(:day, -1)
realigned_time = time.to_time
end
Copy link
Collaborator

@pacso pacso May 13, 2024

Choose a reason for hiding this comment

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

We need to add some tests to cover the edge case you've described.

Also, what happens if the threshold for DST isn't -1 days back?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This case can only happen when the realigned time changed the hour in the internals of Time because of a DST change, so -1 day will always be a time which does not fall into the DST change time imho.

I also see that this is not the ideal solution, it would be better to somehow "fix" the hour to the start time hour of the schedule somewhere in ValidatedRule#next_time but I did not find a way to access the start time of the schedule in ValidatedRule. Maybe you have an idea to that approach.

Regarding the edge case: that was just a guess based on the documentation for the message. I don't really understand the described edge case and thought that the movement to the previous day could somehow trigger that case again.

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.

2 participants