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

End date becomes one day earlier after saving post. #21

Closed
krigsstev opened this issue Apr 18, 2023 · 5 comments
Closed

End date becomes one day earlier after saving post. #21

krigsstev opened this issue Apr 18, 2023 · 5 comments

Comments

@krigsstev
Copy link

Not sure why no-one else has run across this, When I set the end date witht the picker to e.g. 2023-04-23, it changes after saving to 2023-04-22. This happens even if the start_date is the same, in which case I end up with the end_date one day earlier than the start date.
The site I'm using this on has timezone set to Los Angeles, but I changed it to UTC and it still malfunctions.

doing some debugging, If I log like this:

 switch ($value['end_type']) {
                    case 'date':
                        if ($value['end_date']) {
                            $end_date = \DateTime::createFromFormat('Ymd', $value['end_date']);
                            $end_date->setTime(0, 0, 0);
                            error_log('end dateTime: ' . $end_date->format('Y-m-d H:i:s'));

                            $rule->setUntil($end_date);
                            $until = $rule->getUntil();

                            error_log('Until: ' . $until->format('Y-m-d H:i:s'));
                        }

I get
end dateTime: 2023-04-23 00:00:00
Until: 2023-04-22 17:00:00

If I change the code above like so:
$end_date->setTime(23, 0, 0);

I get
end dateTime: 2023-04-23 00:00:00
Until: 2023-04-23 15:00:00

So Maybe the problem is in simshaun/recurr, but it could be the problem is the DateTime object that's passed to recurr.

Maybe this doesn't break for people at or east of Greenwich? If you change the time to 23 hrs, will it malfunction for people further east?

@marcbelletre
Copy link
Owner

Hi @krigsstev,

This is weird indeed. I just tried setting the timezone locally to Los Angeles and could not reproduce the issue.
That being said I found out that the load_value function was not returning the correct timezone which might be causing the issue. I fixed it by setting the timezone when creating the Rule object.
Also I updated simshaun/recurr to the latest version (v5.0.1).

Could you please update ACF RRule to the latest dev version and tell me if you still get the wrong end date?

@krigsstev
Copy link
Author

Sorry, it doesn't help. The only thing that works for me is patching to change the setTime to 23 hrs.

@marcbelletre
Copy link
Owner

Ok so I figured out how to reproduce your problem and can confirm there is a bug with the recurr package. The getUntil() function converts the timezone right before returning the date.

Your patch might work for you right now but it is not reliable. It works because if you consider that April 17 is in the UTC timezone and you convert it to Los Angeles, you remove 7 hours so that makes the new datetime to April 16 17:00. If you set the end time to April 17 23:00 and you remove 7 hours the new datetime becomes April 16 16:00. So it won't work for eastern timezones.

I'll investigate a bit more today to find a solution.

@marcbelletre
Copy link
Owner

@krigsstev I think I found a workaround for now. It turns out that there are setEndDate and getEndDate functions that don't mess with timezones. Could you please update to the latest dev version and tell me if it works for you? You will have to update the posts that use the RRule field.

It looks like the recurr package have some issues with timezones for a while that have never been resolved (like this one). This has been discussed in #7. I think I will have to work on a v2 with rlanvin/php-rrule which is more actively maintained. But I don't have time right now unfortunately ;)

@krigsstev
Copy link
Author

@marcbelletre Awesome, that fixes it. Thanks for this.

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

No branches or pull requests

2 participants