php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #63666
Patch date.patch revision 2012-12-02 00:50 UTC by njaguar at gmail dot com

Patch date.patch for Performance problem Bug #63666

Patch version 2012-12-02 00:50 UTC

Return to Bug #63666 | Download this patch
Patch Revisions:

Developer: njaguar@gmail.com

--- php-5.4.9_orig/ext/date/php_date.c	2012-11-20 23:12:20.000000000 -0600
+++ php-5.4.9/ext/date/php_date.c	2012-12-01 05:38:22.136264276 -0600
@@ -948,6 +948,7 @@
 	timelib_time_offset *offset = NULL;
 	timelib_sll          isoweek, isoyear;
 	int                  rfc_colon;
+	char		     weekYearSet = 0;
 
 	if (!format_len) {
 		return estrdup("");
@@ -974,7 +975,6 @@
 			offset = timelib_get_time_zone_info(t->sse, t->tz_info);
 		}
 	}
-	timelib_isoweek_from_date(t->y, t->m, t->d, &isoweek, &isoyear);
 
 	for (i = 0; i < format_len; i++) {
 		rfc_colon = 0;
@@ -990,8 +990,12 @@
 			case 'z': length = slprintf(buffer, 32, "%d", (int) timelib_day_of_year(t->y, t->m, t->d)); break;
 
 			/* week */
-			case 'W': length = slprintf(buffer, 32, "%02d", (int) isoweek); break; /* iso weeknr */
-			case 'o': length = slprintf(buffer, 32, "%d", (int) isoyear); break; /* iso year */
+			case 'W':
+				if(!weekYearSet) { timelib_isoweek_from_date(t->y, t->m, t->d, &isoweek, &isoyear); weekYearSet = 1; }
+				length = slprintf(buffer, 32, "%02d", (int) isoweek); break; /* iso weeknr */
+			case 'o':
+				if(!weekYearSet) { timelib_isoweek_from_date(t->y, t->m, t->d, &isoweek, &isoyear); weekYearSet = 1; }
+				length = slprintf(buffer, 32, "%d", (int) isoyear); break; /* iso year */
 
 			/* month */
 			case 'F': length = slprintf(buffer, 32, "%s", mon_full_names[t->m - 1]); break;
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Nov 24 13:01:32 2024 UTC