-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
modify after timezone issue #883
Comments
This behavior isn't expected for me too. And i founded that it was introduced while solving #88. Actually, as i can see, all relative modifications was broken excluded "unit" stuff: |
I figured that the problem, raised in #88 relates only to units <= hour. For example we have the date So, in the end, i surely suppose, that fix implemented for #88 should be used only for seconds, minutes and hours modifications (i dont know, is there another modifications less then hour?). All other modifications should work like before. |
All relative modifications, except seconds, minutes and hours was broken because modifications was forced processed in UTC timezone. Now only seconds, minutes and hours modifications processing in UTC. For example i have the date 2014-03-30 00:00:00 in Europe/London (new Carbon('2014-03-30 00:00:00, 'Europe/London')), then if i want to increase date by 1 day, i expect 2014-03-31 00:00:00, but if want to increase date by 24 hours, then i expect 2014-03-31 01:00:00, because in this timezone there will be that time after 24 hours (timezone offset changes because of Daylight correction). The same for minutes and seconds.
Can you state your systems timezone? date_default_timezone_get |
I can, but why you want to know ours timezones? |
It's only interesting if one of the used timezone is your default one or not because the Carbon::modify method behaves differently if the calculation is done in your timezone. |
I can answer the question myself. If you execute it with your local timezone it gives the correct result. So both are not your local timezone. ;-) |
Yes, you are mostly right. But there steel be a problem with adding (sec,min,hour) in local timezone. The problem described in #88 wasnt solved complitely and tests dont cover cases in the right way. Mixing there the logic depending on "local / not local" timezone was wrong. |
Btw, i think we should talk here now about how it should works (i described my vision, but didnt get any feedback) and my implementation of introducing that. |
The way you propose is the same as it is done in Java java.time.ZonedDateTime.
|
It is cool, because now i see, that not only me thinks in that way =) |
All relative modifications, except seconds, minutes and hours was broken because modifications was forced processed in UTC timezone. Now only seconds, minutes and hours modifications processing in UTC. For example i have the date 2014-03-30 00:00:00 in Europe/London (new Carbon('2014-03-30 00:00:00, 'Europe/London')), then if i want to increase date by 1 day, i expect 2014-03-31 00:00:00, but if want to increase date by 24 hours, then i expect 2014-03-31 01:00:00, because in this timezone there will be that time after 24 hours (timezone offset changes because of Daylight correction). The same for minutes and seconds.
When is this - or a similar - fix going to be merged? We are struggling because of this issue 🙁 |
All relative modifications, except seconds, minutes and hours was broken because modifications was forced processed in UTC timezone. Now only seconds, minutes and hours modifications processing in UTC. For example i have the date 2014-03-30 00:00:00 in Europe/London (new Carbon('2014-03-30 00:00:00, 'Europe/London')), then if i want to increase date by 1 day, i expect 2014-03-31 00:00:00, but if want to increase date by 24 hours, then i expect 2014-03-31 01:00:00, because in this timezone there will be that time after 24 hours (timezone offset changes because of Daylight correction). The same for minutes and seconds.
I investigated related issue about other units (Before I thought, that the issue relates only to units <= hour). If initial date have such time, that becomes "unexisted" after modification - it always increasing not matter what was initial offset. And it is wrong I think in case of negative changing. I will show you in this example:
The result is:
I think, that logic should be like that: What do you think about that? Should I change this at the same time as initial issue? |
And more: if you remove and then add the same period - the date will be different. It is not good sign:
result is:
|
I tried your examples and they work here. I guess there may be something related to the PHP configuration. (tried Carbon 1.22.1 and master) |
I am sorry. Most likely it because |
It seems I agree:
A good illustration it's sensible is that the change can be made back and forth without degradation. |
This comment will be changed when new details appears.
All my examples will be in 'Europe/London' timezone. And i will use 2014 year. When local standard time was about to reach Examples:
|
I am not sure now about all the idea to change the Maybe it will be better to let PHP do his work as is when In that approach we will not do redundant and complicated checking job on each Plase, react with |
The situation when removing and then adding the same period leads to time changing is quite separate issue and I think it really wrong and should be fixed. update: I founded the PHP bug 74274 about this with the link to suggested rfc Plase, react with |
I would argue that additions/subtractions should be done using UTC and then back to the timezone to avoid loosing added/subtracted time and that for clarity the behaviour should be consistent in the whole library. |
@klarkent, thank you for your opinion. It is important to speak in common language so I want to clarify terms. What do you mean "respect DST changes"? Am I right that in this example DST changes was "respected"
and in this "ignored"?
|
How it works: For example i have the date 2014-03-30 00:00:00 in Europe/London (new Carbon('2014-03-30 00:00:00, 'Europe/London')), then if i want to increase date by 1 day, i expect 2014-03-31 00:00:00, but if want to increase date by 24 hours, then i expect 2014-03-31 01:00:00, because in this timezone there will be that time after 24 hours (timezone offset changes because of Daylight correction). The same for minutes and seconds.
Sorry my post was not that clear in that regard. So yes respecting DST is the first of your examples, ignoring it is the second one. But what I want to point out is that the developer should have a choice and that the behaviour should be consistent and not change just because you're using another unit of time. It does not matter what's the default to me but I want to know it and know how to use the other one if I need to. |
I am completely agree with you at this point. And in my proposal there is possibility to use default PHP handling by calling
Here I personally don't agree. But is it questionable. Here is my arguments:
I agree, that consistent is important. In that case I think it is worth to sacrifice it for convinience sake. But it still the root question. It is why I started a discussion. As I see you suppose the second argument to add|sub functions. If the community will support your choise - we will stand on that. |
I will give you a concrete example that will explain the problem with the solution of having different behaviour:
I understand that, I also am giving my opinion. I just hope that this doesn't hang for another year |
Actually it not explains "different behavior" (inconsistence) problem. But it is a good example when people could expect "respects" handling. It is not so simple, though. For example, you talking about months, but there is days in your code. Why? I think because a month != 30 days and in fact that company offers days and not months. Same for day. Day != 24 hours (you can read about it in the wiki - there is not only DST changes, but in addition there is the leap second and maybe something else.
The same could happens with "respects" handling too. For example: Subscription from When I was thinking about that all I realised, that in my approach there is no way to handle >= day modifications in the "respects" mode. And, as I said before, I agree with you, that developer should have a choice. I can suggest different methods for that, like addDaysRespectDst, etc. But I don't like this function name and can't imagine the better one. By now I see two realistic ways:
|
I got new thoughts. The third way:
Why? Because I realise (why I didn't do it before?) that PHP DateTime already have the way to not bothering about DST influence. By using the UTC timezone. So if you want to timestamp corrections when DST changes - you should use some local timezone. If you don't - use UTC. That is it. And first two ways just add more complecity, but they didn't really offer anything in exchange because you still have to think about what do you want in particular case and how you can achieve this. And now I stand on that, third variant. I have some other arguments in the hand, but don't think they needed. |
In the end I suggest to:
|
This sounds like the cleanest option to me and the developer would have a choice which would be to use UTC to avoid DST to be taken into account in date operations. It will also be consistent if the bugs that PHP has are fixed in the library, so I'll vote for it! |
For all peoples, who interested in this: fixing can take a few time, especially because I am quite confusing about is that project alive or not. So when I will make the fixes - quite expecting that they will not be merged. But you already could just revert the 253f381 commit and you will be just with the php bug that arises quite rarely I think, but without #88 implemented errors, that is the main problem. @klarkent, thanks for the useful discussion. I glad we came to agreement =) |
…about issue briannesbitt#88 The realisation of initial issue briannesbitt#88 is wrong. The problem does not relies to `local` / `not local` timezone. Php handles date changes similar for both cases. So in fact changes was made 'fixes' non-local dates but local dates works same as before. And it 'fixes' the problem and not actually fixes it because in fact the PHP handling of DST changing in non-UTC dates is quite right. If developer don't want to adjusting timestamp to DST change he should use UTC timezone. Next commits reverted by hand because conflicts in automatic revert. * Commit 2cc6988 Fix CS 07.12.2015 13:04 Lucas Michot * Commit 5394301 Fix issue 88 07.12.2015 12:55 Lucas Michot
I created 2 pull-requests:
|
…about issue briannesbitt#88 The realisation of initial issue briannesbitt#88 is wrong. The problem does not relies to `local` / `not local` timezone. Php handles date changes similar for both cases. So in fact changes was made 'fixes' non-local dates but local dates works same as before. And it 'fixes' the problem and not actually fixes it because in fact the PHP handling of DST changing in non-UTC dates is quite right. If developer don't want to adjusting timestamp to DST change he should use UTC timezone. Next commits reverted by hand because conflicts in automatic revert. * Commit 2cc6988 Fix CS 07.12.2015 13:04 Lucas Michot * Commit 5394301 Fix issue 88 07.12.2015 12:55 Lucas Michot
…about issue briannesbitt#88 The realisation of initial issue briannesbitt#88 is wrong. The problem does not relies to `local` / `not local` timezone. Php handles date changes similar for both cases. So in fact changes was made 'fixes' non-local dates but local dates works same as before. And it 'fixes' the problem and not actually fixes it because in fact the PHP handling of DST changing in non-UTC dates is quite right. If developer don't want to adjusting timestamp to DST change he should use UTC timezone. The unit tests added to assure default php behavior. Next commits reverted by hand because conflicts in automatic revert. * Commit 2cc6988 Fix CS 07.12.2015 13:04 Lucas Michot * Commit 5394301 Fix issue 88 07.12.2015 12:55 Lucas Michot
…about issue briannesbitt#88 The realisation of initial issue briannesbitt#88 is wrong. The problem does not relies to `local` / `not local` timezone. Php handles date changes similar for both cases. So in fact changes was made 'fixes' non-local dates but local dates works same as before. And it 'fixes' the problem and not actually fixes it because in fact the PHP handling of DST changing in non-UTC dates is quite right. If developer don't want to adjusting timestamp to DST change he should use UTC timezone. The unit tests added to assure default php behavior. Next commits reverted by hand because conflicts in automatic revert. * Commit 2cc6988 Fix CS 07.12.2015 13:04 Lucas Michot * Commit 5394301 Fix issue 88 07.12.2015 12:55 Lucas Michot
Working on solution in #1070 PR. TY |
…about issue briannesbitt#88 The realisation of initial issue briannesbitt#88 is wrong. The problem does not relies to `local` / `not local` timezone. Php handles date changes similar for both cases. So in fact changes was made 'fixes' non-local dates but local dates works same as before. And it 'fixes' the problem and not actually fixes it because in fact the PHP handling of DST changing in non-UTC dates is quite right. If developer don't want to adjusting timestamp to DST change he should use UTC timezone. Next commits reverted by hand because conflicts in automatic revert. * Commit 2cc6988 Fix CS 07.12.2015 13:04 Lucas Michot * Commit 5394301 Fix issue 88 07.12.2015 12:55 Lucas Michot
…about issue briannesbitt#88 The realisation of initial issue briannesbitt#88 is wrong. The problem does not relies to `local` / `not local` timezone. Php handles date changes similar for both cases. So in fact changes was made 'fixes' non-local dates but local dates works same as before. And it 'fixes' the problem and not actually fixes it because in fact the PHP handling of DST changing in non-UTC dates is quite right. If developer don't want to adjusting timestamp to DST change he should use UTC timezone. The unit tests added to assure default php behavior. Next commits reverted by hand because conflicts in automatic revert. * Commit 2cc6988 Fix CS 07.12.2015 13:04 Lucas Michot * Commit 5394301 Fix issue 88 07.12.2015 12:55 Lucas Michot
…about issue briannesbitt#88 The realisation of initial issue briannesbitt#88 is wrong. The problem does not relies to `local` / `not local` timezone. Php handles date changes similar for both cases. So in fact changes was made 'fixes' non-local dates but local dates works same as before. And it 'fixes' the problem and not actually fixes it because in fact the PHP handling of DST changing in non-UTC dates is quite right. If developer don't want to adjusting timestamp to DST change he should use UTC timezone. The unit tests added to assure default php behavior. Next commits reverted by hand because conflicts in automatic revert. * Commit 2cc6988 Fix CS 07.12.2015 13:04 Lucas Michot * Commit 5394301 Fix issue 88 07.12.2015 12:55 Lucas Michot
If I want to get midnight time for different timezones with initial time I got this problem. For example with timestamp
1485943200
I need to know midnight time for Europe/Moscow and Europe/Samara.I do this:
And got:
This is midnight time for
GMT 0
for that day not for those timezones.The text was updated successfully, but these errors were encountered: