Req #38938 [Opn->Wfx]: more useful initialization for strptime

From: Date: Wed, 20 Oct 2021 12:13:34 +0000
Subject: Req #38938 [Opn->Wfx]: more useful initialization for strptime
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237300@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=38938&edit=1

 ID:                 38938
 Updated by:         cmb@php.net
 Reported by:        soletan at toxa dot de
 Summary:            more useful initialization for strptime
-Status:             Open
+Status:             Wont fix
 Type:               Feature/Change Request
 Package:            Date/time related
 Operating System:   Linux
 PHP Version:        5CVS-2006-09-23 (snap)
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

Given that strptime() is deprecated as of PHP 8.1.0 anyway, I
don't see the point in changing the behavior now.


Previous Comments:
------------------------------------------------------------------------
[2013-10-11 02:44:58] datibbaw@php.net

Doing this would cause a regression in test case ext/standard/tests/time/strptime_basic.phpt

------------------------------------------------------------------------
[2006-09-24 00:21:16] 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);
  }
  /* }}} */




------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=38938&edit=1


Thread (3 messages)

« previous php.bugs (#237300) next »