php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #38938 more useful initialization for strptime
Submitted: 2006-09-24 00:21 UTC Modified: 2013-10-11 02:44 UTC
From: soletan at toxa dot de Assigned:
Status: Open Package: *General Issues
PHP Version: 5CVS-2006-09-23 (snap) OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: soletan at toxa dot de
New email:
PHP Version: OS:

 

 [2006-09-24 00:21 UTC] soletan at toxa dot de
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);
  }
  /* }}} */



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-11 02:44 UTC] datibbaw@php.net
-Package: Feature/Change Request +Package: *General Issues
 [2013-10-11 02:44 UTC] datibbaw@php.net
Doing this would cause a regression in test case ext/standard/tests/time/strptime_basic.phpt
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC