Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions ext/date/lib/interval.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,35 @@ timelib_rel_time *timelib_diff(timelib_time *one, timelib_time *two)
rt->invert = 1;
}

/* Calculate correction for DST change over, but only if the TZ type is ID
* and it's the same */
int flag_apply_localtime=0;

if (one->zone_type == 3 && two->zone_type == 3
&& (strcmp(one->tz_info->name, two->tz_info->name) == 0)
&& (one->z != two->z))
{
dst_corr = two->z - one->z;
dst_h_corr = dst_corr / 3600;
dst_m_corr = (dst_corr % 3600) / 60;
&& (strcmp(one->tz_info->name, two->tz_info->name) == 0))
{
/* Calculate correction for DST change over, but only if the TZ type is ID
* and it's the same */
if ((one->z != two->z))
{
dst_corr = two->z - one->z;
dst_h_corr = dst_corr / 3600;
dst_m_corr = (dst_corr % 3600) / 60;
memcpy(&one_backup, one, sizeof(one_backup));
memcpy(&two_backup, two, sizeof(two_backup));
flag_apply_localtime = 1;
}
}else{
flag_apply_localtime = 1;
}

/* Save old TZ info */
memcpy(&one_backup, one, sizeof(one_backup));
memcpy(&two_backup, two, sizeof(two_backup));

timelib_apply_localtime(one, 0);
timelib_apply_localtime(two, 0);
if (flag_apply_localtime==1)
{
timelib_apply_localtime(one, 0);
timelib_apply_localtime(two, 0);
}

rt->y = two->y - one->y;
rt->m = two->m - one->m;
Expand Down Expand Up @@ -111,8 +123,7 @@ timelib_time *timelib_add(timelib_time *old_time, timelib_rel_time *interval)
t->sse_uptodate = 0;

timelib_update_ts(t, NULL);

// printf("%lld %lld %d\n", old_time->dst, t->dst, (t->sse - old_time->sse));

/* Adjust for backwards DST changeover */
if (old_time->dst == 1 && t->dst == 0 && !interval->y && !interval->m && !interval->d) {
t->sse -= old_time->z;
Expand Down
23 changes: 23 additions & 0 deletions ext/date/tests/bug65003.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
Fix bug 65003
--FILE--
<?php

date_default_timezone_set('Europe/Moscow');

$datetime1 = new DateTime('13-03-01');
$datetime2 = new DateTime('13-04-01');

$datetime3 = new DateTime('13-03-02');
$datetime4 = new DateTime('13-04-02');

$interval = $datetime2->diff($datetime1);
echo $interval->format('%m month, %d days')."\n"; //1 month, 3 days

$interval = $datetime4->diff($datetime3);
echo $interval->format('%m month, %d days')."\n"; //1 month, 0 days

?>
--EXPECT--
1 month, 0 days
1 month, 0 days