Hi,

I usually have to work with dates and i miss a date format character
wich returns year of the week. I'm not a C developer, i could just play
with it in datetime.c, but i send the patch file, please check this and
if you are interest in it, use in the future.

About the working:
in case 01/01/2003 returns 2003
in case 31/12/2003 returns 2004

the format character is X.

thanks

zsolt banyai [bazso]
kirowski rt.
hungary

--- datetime.c.old	2003-12-16 23:52:47.000000000 +0100
+++ datetime.c	2003-12-23 14:25:36.000000000 +0100
@@ -361,6 +361,9 @@
 			case 'Y':		/* year, numeric, 4 digits */
 				size += 4;
 				break;
+			case 'X':
+				size += 4;	/* Year of The Weeek, numeric, 4 digits */
+				break;
 			case 'M':		/* month, textual, 3 letters */
 			case 'D':		/* day, textual, 3 letters */
 			case 'z':		/* day of the year, 1 to 366 */
@@ -428,6 +431,31 @@
 				sprintf(tmp_buff, "%d", ta->tm_year + YEAR_BASE);  /* SAFE */
 				strcat(Z_STRVAL_P(return_value), tmp_buff);
 				break;
+			case 'X':
+				wd = ta->tm_wday == 0 ? 6 : ta->tm_wday - 1; /* weekday */
+				yd = ta->tm_yday + 1;					/* days since January 1st */
+
+				fd = (7 + wd - yd % 7+ 1) % 7;			/* weekday (1st January) */	
+
+				/* week is a last year week (52 or 53) */
+				if ((yd <= 7 - fd) && fd > 3){			
+					wk = (fd == 4 || (fd == 5 && isleap((ta->tm_year + YEAR_BASE - 1)))) ? 53 : 52;
+					sprintf(tmp_buff, "%d", ta->tm_year + YEAR_BASE - 1 );  /* SAFE */
+				}
+				/* week is a next year week (1) */
+				else if (isleap((ta->tm_year+YEAR_BASE)) + 365 - yd < 3 - wd){
+					wk = 1;
+					sprintf(tmp_buff, "%d", ta->tm_year + YEAR_BASE + 1);  /* SAFE */
+				}
+				/* normal week */
+				else {
+					wk = (yd + 6 - wd + fd) / 7 - (fd > 3);
+					sprintf(tmp_buff, "%d", ta->tm_year + YEAR_BASE);  /* SAFE */
+				}
+
+				strcat(Z_STRVAL_P(return_value), tmp_buff);
+				break;
+	    
 			case 'M':		/* month, textual, 3 letters */
 				strcat(Z_STRVAL_P(return_value), mon_short_names[ta->tm_mon]);
 				break;

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to