From: soletan at toxa dot de Operating system: Linux PHP version: 5CVS-2006-09-23 (snap) PHP Bug Type: Date/time related Bug description: more useful initialization for strptime
Description: ------------ Hi, in addition to bug #38524 I'd prefer initializing call to strptime in a more useful way. While it is easiest way to memset all with 0's, some fields like tm_mon can't be interpreted properly. My proposal uses 0xFF for initialization to get all values set -1. Then in addition, I add array element value NULL on every field that wasn't touched by strptime. I consider this to be quite common behaviour in PHP ... Below is my proposal for a patch on latest CVS snapshot. Best Regards, Thomas Urban *** datetime.c.orig 2006-08-24 14:30:57.000000000 +0200 --- datetime.c 2006-09-24 02:16:09.000000000 +0200 *************** *** 101,107 **** return; } ! memset(&parsed_time, 0, sizeof(parsed_time)); unparsed_part = strptime(ts, format, &parsed_time); if (unparsed_part == NULL) { --- 101,107 ---- return; } ! memset(&parsed_time, 0xFF, sizeof(parsed_time)); unparsed_part = strptime(ts, format, &parsed_time); if (unparsed_part == NULL) { *************** *** 109,122 **** } array_init(return_value); ! add_assoc_long(return_value, "tm_sec", parsed_time.tm_sec); ! add_assoc_long(return_value, "tm_min", parsed_time.tm_min); ! add_assoc_long(return_value, "tm_hour", parsed_time.tm_hour); ! add_assoc_long(return_value, "tm_mday", parsed_time.tm_mday); ! add_assoc_long(return_value, "tm_mon", parsed_time.tm_mon); ! add_assoc_long(return_value, "tm_year", parsed_time.tm_year); ! add_assoc_long(return_value, "tm_wday", parsed_time.tm_wday); ! add_assoc_long(return_value, "tm_yday", parsed_time.tm_yday); add_assoc_string(return_value, "unparsed", unparsed_part, 1); } /* }}} */ --- 109,146 ---- } array_init(return_value); ! if ( parsed_time.tm_sec < 0 ) ! add_assoc_null(return_value, "tm_sec"); ! else ! add_assoc_long(return_value, "tm_sec", parsed_time.tm_sec); ! if ( parsed_time.tm_min < 0 ) ! add_assoc_null(return_value, "tm_min"); ! else ! add_assoc_long(return_value, "tm_min", parsed_time.tm_min); ! if ( parsed_time.tm_hour < 0 ) ! add_assoc_null(return_value, "tm_hour"); ! else ! add_assoc_long(return_value, "tm_hour", parsed_time.tm_hour); ! if ( parsed_time.tm_mday < 0 ) ! add_assoc_null(return_value, "tm_mday"); ! else ! add_assoc_long(return_value, "tm_mday", parsed_time.tm_mday); ! if ( parsed_time.tm_mon < 0 ) ! add_assoc_null(return_value, "tm_mon"); ! else ! add_assoc_long(return_value, "tm_mon", parsed_time.tm_mon); ! if ( parsed_time.tm_year < 0 ) ! add_assoc_null(return_value, "tm_year"); ! else ! add_assoc_long(return_value, "tm_year", parsed_time.tm_year); ! if ( parsed_time.tm_wday < 0 ) ! add_assoc_null(return_value, "tm_wday"); ! else ! add_assoc_long(return_value, "tm_wday", parsed_time.tm_wday); ! if ( parsed_time.tm_yday < 0 ) ! add_assoc_null(return_value, "tm_yday"); ! else ! add_assoc_long(return_value, "tm_yday", parsed_time.tm_yday); add_assoc_string(return_value, "unparsed", unparsed_part, 1); } /* }}} */ -- Edit bug report at http://bugs.php.net/?id=38938&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=38938&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=38938&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=38938&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=38938&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=38938&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=38938&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=38938&r=needscript Try newer version: http://bugs.php.net/fix.php?id=38938&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=38938&r=support Expected behavior: http://bugs.php.net/fix.php?id=38938&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=38938&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=38938&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=38938&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=38938&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=38938&r=dst IIS Stability: http://bugs.php.net/fix.php?id=38938&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=38938&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=38938&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=38938&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=38938&r=mysqlcfg