PHP 4.0 Bug #8828 Updated: mktime using mday<=0

From: Date: Wed, 14 Mar 2001 20:56:42 +0000
Subject: PHP 4.0 Bug #8828 Updated: mktime using mday<=0
Groups: php.dev 
Request: Send a blank email to php-dev+get-48946@lists.php.net to get a copy of this message
ID: 8828 Updated by: jason Reported By: dieter@fiebelkorn.net Status: Open Bug Type: Date/time related Assigned To: Comments: I was incorrect, This is not a part of C99(ANSI/ISO/IEC9899-1999) this is just implemented in Solaris, Linux, Irix, and possibly a few others. -Jason Previous Comments: --------------------------------------------------------------------------- [2001-03-14 13:34:47] jason@php.net This actually is part of the Ansi C standard. Solaris 8 manpage ----------------------- The original values of the components may be either greater than or less than the specified range. For example, a tm_hour of -1 means 1 hour before midnight, tm_mday of 0 means the day preceding the current month, and tm_mon of -2 means 2 months before January of tm_year --------------------------------------- Alg from c standard ---------------------------------------- #define QUOT(a,b) ((a)>0 ? (a)/(b) : -(((b)-(a)-1)/(b))) #define REM(a,b) ((a)-(b)*QUOT(a,b)) SS = tm_hour*3600 + tm_min*60 + tm_sec + (tm_leapsecs == _NO_LEAP_SECONDS ? X1 : tm_leapsecs) - (tm_zone == _LOCALTIME ? X2 : tm_zone) * 60; // X1 is the appropriate number of leap seconds, determined by // the implementation, or 0 if it cannot be determined. // X2 is the appropriate offset from local time to UTC, // determined by the implementation, or // (tm_isdst >= 0 ? tm_isdst : 0) // if the offset cannot be determined M = REM(tm_mon, 12); Y = tm_year + 1900 + QUOT(tm_mon, 12); Z = Y - (M < 2 ? 1 : 0); D = Y*365 + (Z/400)*97 + (Z%400)/4 + M[(int []){0,31,59,90,120,151,181,212,243,273, 304,335}] + tm_mday + QUOT(SS, 86400); S = REM(SS, 86400); ------------------------------------------------------ Mac OS X is not following this standard -Jason --------------------------------------------------------------------------- [2001-01-27 07:26:19] dieter@fiebelkorn.net I have send a bug report to darwin-developers and apple, too, but 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. 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! --------------------------------------------------------------------------- [2001-01-22 22:32:57] jimw@php.net macos x is behaving in a non-standard way. we just use the underlying mktime() function. you might try reporting it to the darwin developers. http://www.opensource.apple.com/projects/bugs.html --------------------------------------------------------------------------- [2001-01-21 08:06:36] dieter@fiebelkorn.net 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'. See the test: [aragorn:~/Downloads] dieter% cat A.c #include <stdio.h> #include <time.h> main() { struct tm mytm; int i; mytm.tm_sec = 0; mytm.tm_min = 0; mytm.tm_hour = 0; mytm.tm_year = 101; mytm.tm_wday = 0; mytm.tm_yday = 0; mytm.tm_isdst = 0; mytm.tm_gmtoff = 0; mytm.tm_zone = 0; for (i = 2; i >= -2; i--) { mytm.tm_mday = i; mytm.tm_mon = 2; printf ("%02d.%02d ", mytm.tm_mday, mytm.tm_mon+1); printf (" --> %ld", mktime(&mytm)); printf (" --> %02d.%02dn", mytm.tm_mday, mytm.tm_mon+1); } } [aragorn:~/Downloads] dieter% cc -o A A.c [aragorn:~/Downloads] dieter% ./A 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 [aragorn:~/Downloads] dieter% --------------------------------------------------------------------------- ATTENTION! Do NOT reply to this email! To reply, use the web interface found at http://bugs.php.net/?id=8828&edit=2

« previous php.dev (#48946) next »