![]() |
Time diff NOT WORKING - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Time diff NOT WORKING (/showthread.php?tid=90472) Pages:
1
2
|
Time diff NOT WORKING - pablo.hernandez - 03-23-2024 Hello, PHP 8.2.12 CodeIgniter v 4.4.6 PHP Code: use \CodeIgniter\I18n\Time; What is most strange: it actually works well for most other dates, I can't find why but this behavior makes this function useless... many thanks for this excelent framework! RE: Time diff NOT WORKING - kenjis - 03-23-2024 Cannot reproduce. PHP 8.2.16 PHP 7.4.33 PHP Code: $date1 = new Time("2024-03-31"); RE: Time diff NOT WORKING - pablo.hernandez - 03-24-2024 (03-24-2024, 02:07 AM)pablo.hernandez Wrote:(03-23-2024, 07:25 PM)kenjis Wrote: Cannot reproduce. RE: Time diff NOT WORKING - kenjis - 03-24-2024 Oh yes, Europe/Madrid makes the value 0! PHP Code: public string $appTimezone = 'Europe/Madrid'; RE: Time diff NOT WORKING - kenjis - 03-24-2024 (03-24-2024, 02:23 AM)pablo.hernandez Wrote: The problem is not just Madrid, it appears with any "Europe/X" city that I've tried (Amsterdam, Paris...) In Europe, are 2024-03-31 and 2024-04-01 the same day!? RE: Time diff NOT WORKING - pablo.hernandez - 03-24-2024 (03-24-2024, 02:38 AM)kenjis Wrote:(03-24-2024, 02:23 AM)pablo.hernandez Wrote: The problem is not just Madrid, it appears with any "Europe/X" city that I've tried (Amsterdam, Paris...) Of course not! :-D Mi guess is that this has to do with the damned daylight savings: European governments mess with the time since the oil crisis back in the 70s (1 hour back and forth on specific days of the year), theoretically in order to save some energy (?), and this year this change (2am becomes 3am) is due to happen precisely on 2024-03-31... RE: Time diff NOT WORKING - MaxWho17 - 03-24-2024 I think this is because we have Daylight Saving Time (DST) in Europe, last week of march, and this year is on 2024-03-31 RE: Time diff NOT WORKING - bobw - 03-24-2024 Looking at the dates, my first thought was DST. DST in Europe originated in the First World War to aid in munitions manufacturing. In Europe DST changes on the last Sunday in March and the last Sunday in October. It just so happens that this year the last Sunday is the 31st. The EU member states have voted to cease using DST but have yet to decide when this will happen - maybe on the last Sunday of October then they've an hour to decide if they like it and can switch it back again! RE: Time diff NOT WORKING - kenjis - 03-24-2024 It is recommended to always use UTC in your app, and use local timezone only when displaying date/time. After all, the current implementation is correct, because the difference is 23 hours, less than 1 day. testTime: 2024-03-31 22:00:00.000000 (UTC) ourTime: 2024-03-30 23:00:00.000000 (UTC) RE: Time diff NOT WORKING - pablo.hernandez - 03-25-2024 (03-24-2024, 04:11 PM)kenjis Wrote: It is recommended to always use UTC in your app, and use local timezone only when displaying date/time. Well, IMHO this implementation is only "correct" if the unit of difference needed is hours (or smaller); the case here is that our unfathomably wise politicians have decided that one specific day has 23 hours (and October 27th will have 25 hours to balance things out for the year). That is, they have redefined what a "day" is (Big Brother style :-). The CI method is CORRECTLY calculating 23 h for this particular interval, what is missing is that it should count as a FULL DAY Any CI user interested in the day difference (which I guess is pretty common, e.g. in my project I just need to show the number of nights spent in a hotel given the arrival and departure dates) is going to be surprised to get a 0 (or a 2) when plugging in two consecutive calendar dates (in fact the glitch will bite you for every date interval that includes one of these 2 special days)... so I believe this should be patched, or at least mentioned in the documentation. Your suggestion to always use UTC project-wise, if my understanding is correct, would render useless some otherwise very convenient functions (https://codeigniter.com/user_guide/libraries/time.html) that are timezone-sensitive... Many thanks |