diff options
author | Colin Viebrock <cmv@php.net> | 2001-06-20 18:07:53 +0000 |
---|---|---|
committer | Colin Viebrock <cmv@php.net> | 2001-06-20 18:07:53 +0000 |
commit | a367c39c2eb6cc53038524b477657b78aca6410d (patch) | |
tree | 750fd2c60f35f7633c1aa23f1a090ae1f99011f4 /ext/standard/datetime.c | |
parent | 1aa5b19cc9467df6ffa56ce28a527878d4d0911a (diff) | |
download | php-git-a367c39c2eb6cc53038524b477657b78aca6410d.tar.gz |
date('W') now returns week of year (ISO 8601)
Diffstat (limited to 'ext/standard/datetime.c')
-rw-r--r-- | ext/standard/datetime.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/ext/standard/datetime.c b/ext/standard/datetime.c index c0f166c48a..e94f1a3bc6 100644 --- a/ext/standard/datetime.c +++ b/ext/standard/datetime.c @@ -218,7 +218,7 @@ php_date(INTERNAL_FUNCTION_PARAMETERS, int gm) pval **format, **timestamp; time_t the_time; struct tm *ta, tmbuf; - int i, size = 0, length, h, beat; + int i, size = 0, length, h, beat, fd, wd, yd, wk; char tmp_buff[32]; switch(ZEND_NUM_ARGS()) { @@ -299,6 +299,7 @@ php_date(INTERNAL_FUNCTION_PARAMETERS, int gm) case 'a': /* am/pm */ case 'S': /* standard english suffix for the day of the month (e.g. 3rd, 2nd, etc) */ case 't': /* days in current month */ + case 'W': /* ISO-8601 week number of year, weeks starting on Monday */ size += 2; break; case '\\': @@ -505,6 +506,17 @@ php_date(INTERNAL_FUNCTION_PARAMETERS, int gm) #endif strcat(return_value->value.str.val, tmp_buff); break; + case 'W': /* ISO-8601 week number of year, weeks starting on Monday */ + wd = ta->tm_wday==0 ? 7 : ta->tm_wday; + yd = ta->tm_yday + 1; + fd = (7 + (wd - yd) % 7 ) % 7; + wk = ( (yd + fd - 1) / 7 ) + 1; + if (fd>3) { + wk--; + } + sprintf(tmp_buff, "%d", wk); /* SAFE */ + strcat(return_value->value.str.val, tmp_buff); + break; default: length = strlen(return_value->value.str.val); |