|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2001-05-05 17:19 UTC] dieter at fiebelkorn dot net
see Bug id #8828, too!
On PHP documantation:
mktime(hour,min,sec, year,0,mon) refers the last day of month 'mon-1'. On MacOS X this failed, there it refers the first day of month 'mon' and mktime(hour,min,sec,
year,-1,mon) refers the last day of month 'mon-1'.
On MacOS X 10.0.2 (Darwin 1.3):
02.03 --> 983487600 --> 02.03
01.03 --> 983401200 --> 01.03
00.03 --> 983401200 --> 01.03
-1.03 --> 983314800 --> 28.02
-2.03 --> 983228400 --> 27.02
i have check some UNIX-systems and i haven't found any man-page, where is describe what should be happend on "tm_mday" <= 0. The problem is happend on all values out of bounds, when using mktime()!
IMHO this is a undocumented feature, which is used by PHP.
man mktime (Linux 2.2.13)
tm_mday The day of the month, in the range 1 to 31.
Sun Release 4.1
int tm_mday; /* day of month (1 - 31) */
SunOS 5.5
int tm_mday; /* day of the month - [1, 31] */
HP-UX Release 10.20
int tm_mday; /* day of month - [1,31] */
HP-UX Release 11.00
int tm_mday; /* day of month - [1,31] */
AIX 4.3.2
int tm_mday; /* Day of month (1 - 31) */
Darwin 1.0.2
int tm_mday; /* day of month (1 - 31) */
I think i should by much better to check mktime() on configure and set a #define for compilation. Only on "datetime.c" must be made a patch to support MacOS X's / Darwin's mktime()-systemcall, i think!
Patch to make php_mktime() more compatible [i think it is not complete for the whole PHP4-project]. It includes a time correction for values less then 1 on "mday",
"hour", "min", "sec", "mon"!!
*** ext/standard/datetime.c.orig Fri Dec 8 12:38:02 2000
--- ext/standard/datetime.c Sun Apr 15 17:28:46 2001
***************
*** 81,87 ****
struct tm *ta, tmbuf;
time_t t;
int i, gmadjust, seconds, arg_count = ZEND_NUM_ARGS();
! int is_dst = -1;
if (arg_count > 7 ||
zend_get_parameters_array_ex(arg_count,arguments) ==
FAILURE) {
WRONG_PARAM_COUNT;
--- 81,87 ----
struct tm *ta, tmbuf;
time_t t;
int i, gmadjust, seconds, arg_count = ZEND_NUM_ARGS();
! int is_dst = -1, val, chgsecs = 0;
if (arg_count > 7 ||
zend_get_parameters_array_ex(arg_count,arguments) ==
FAILURE) {
WRONG_PARAM_COUNT;
***************
*** 148,172 ****
- (((*arguments[5])->value.lval > 1000) ? 1900 : 0);
/* fall-through */
case 5:
! ta->tm_mday = (*arguments[4])->value.lval;
/* fall-through */
case 4:
! ta->tm_mon = (*arguments[3])->value.lval - 1;
/* fall-through */
case 3:
! ta->tm_sec = (*arguments[2])->value.lval;
/* fall-through */
case 2:
! ta->tm_min = (*arguments[1])->value.lval;
/* fall-through */
case 1:
! ta->tm_hour = (*arguments[0])->value.lval;
/* fall-through */
case 0:
break;
}
! seconds = mktime(ta);
if (is_dst == -1)
is_dst = ta->tm_isdst;
--- 148,182 ----
- (((*arguments[5])->value.lval > 1000) ? 1900 : 0);
/* fall-through */
case 5:
! val = (*arguments[4])->value.lval;
! if (val < 1) { chgsecs += (1-val) * 60*60*24; val = 1;
}
! ta->tm_mday = val;
/* fall-through */
case 4:
! val = (*arguments[3])->value.lval - 1;
! while (val < 0) { val += 12; ta->tm_year--; }
! ta->tm_mon = val;
/* fall-through */
case 3:
! val = (*arguments[2])->value.lval;
! if (val < 1) { chgsecs += (1-val); val = 1; }
! ta->tm_sec = val;
/* fall-through */
case 2:
! val = (*arguments[1])->value.lval;
! if (val < 1) { chgsecs += (1-val) * 60; val = 1; }
! ta->tm_min = val;
/* fall-through */
case 1:
! val = (*arguments[0])->value.lval;
! if (val < 1) { chgsecs += (1-val) * 60*60; val = 1; }
! ta->tm_hour = val;
/* fall-through */
case 0:
break;
}
! seconds = mktime(ta) - chgsecs;
if (is_dst == -1)
is_dst = ta->tm_isdst;
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 07:00:01 2025 UTC |
I cannot see it fixed in 4.1.2. Try my fix ... that works! 01.02.2000 --> 949402800 --> 01.02.2000 12:00:00 00.02.2000 --> 949316400 --> 31.01.2000 12:00:00 -1.02.2000 --> 949230000 --> 30.01.2000 12:00:00 01.03.2000 --> 951908400 --> 01.03.2000 12:00:00 00.03.2000 --> 951735600 --> 28.02.2000 12:00:00 -1.03.2000 --> 951649200 --> 27.02.2000 12:00:00 01.04.2000 --> 954583200 --> 01.04.2000 12:00:00 00.04.2000 --> 954410400 --> 30.03.2000 12:00:00 -1.04.2000 --> 954324000 --> 29.03.2000 12:00:00 01.05.2000 --> 957175200 --> 01.05.2000 12:00:00 00.05.2000 --> 957002400 --> 29.04.2000 12:00:00 -1.05.2000 --> 956916000 --> 28.04.2000 12:00:00 01.06.2000 --> 959853600 --> 01.06.2000 12:00:00 00.06.2000 --> 959680800 --> 30.05.2000 12:00:00 -1.06.2000 --> 959594400 --> 29.05.2000 12:00:00 <? $tm_sec=0; $tm_min=0; $tm_hour=0; $tm_year=100; $tm_wday=0; $tm_yday=0; $tm_isdst=0; $tm_gmtoff=0; $tm_zone=0; for ($j=2; $j<=6; $j++) { for ($i=1; $i>=-1; $i--) { $tm_mday=$i; $tm_mon=$j; printf ("%02d.%02d.%04d", $tm_mday, $tm_mon,1900+$tm_year); $tm = mktime(12,0,0,$tm_mon,$tm_mday,1900+ $tm_year); echo " --> $tm"; echo " --> ".date("d.m.Y H:i:s", $tm); echo "<br>"; } } ?>