]> granicus.if.org Git - php/commitdiff
Fix backwards transition diffs.
authorDerick Rethans <github@derickrethans.nl>
Sat, 13 Apr 2013 22:47:23 +0000 (23:47 +0100)
committerDerick Rethans <github@derickrethans.nl>
Thu, 28 Nov 2013 12:02:36 +0000 (12:02 +0000)
ext/date/lib/interval.c

index ded57866c2f76a6673b19f349f7f3b4676236f0e..e765a42e93d9d15a2a8031d8c877e680e04a69a0 100644 (file)
@@ -65,10 +65,22 @@ timelib_rel_time *timelib_diff(timelib_time *one, timelib_time *two)
                rt->h += dst_h_corr;
                rt->i += dst_m_corr;
        }
+
        rt->days = abs(floor((one->sse - two->sse - (dst_h_corr * 3600) - (dst_m_corr * 60)) / 86400));
 
        timelib_do_rel_normalize(rt->invert ? one : two, rt);
 
+       /* We need to do this after normalisation otherwise we can't get "24H" */
+       if (one_backup.dst == 1 && two_backup.dst == 0 && two->sse >= one->sse + 86400) {
+               if (two->sse < one->sse + 86400 - dst_corr) {
+                       rt->d--;
+                       rt->h = 24;
+               } else {
+                       rt->h += dst_h_corr;
+                       rt->i += dst_m_corr;
+               }
+       }
+
        /* Restore old TZ info */
        memcpy(one, &one_backup, sizeof(one_backup));
        memcpy(two, &two_backup, sizeof(two_backup));