From: Derick Rethans Date: Fri, 2 Sep 2005 09:41:08 +0000 (+0000) Subject: - MF51: Fixed bug #34304 (date() doesn't have a modifier for ISO Week Day). X-Git-Tag: PRE_NEW_OCI8_EXTENSION~24 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=31f3f81c82af72b05047d677654b7416e98166c7;p=php - MF51: Fixed bug #34304 (date() doesn't have a modifier for ISO Week Day). --- diff --git a/ext/date/lib/dow.c b/ext/date/lib/dow.c index 4b51cf5daf..0c71c2dc6a 100644 --- a/ext/date/lib/dow.c +++ b/ext/date/lib/dow.c @@ -31,9 +31,9 @@ static timelib_sll century_value(timelib_sll j) return c < 0 ? c + 7 : c; } -timelib_sll timelib_day_of_week(timelib_sll y, timelib_sll m, timelib_sll d) +static timelib_sll timelib_day_of_week_ex(timelib_sll y, timelib_sll m, timelib_sll d, int iso) { - timelib_sll c1, y1, m1; + timelib_sll c1, y1, m1, dow; /* Only valid for Gregorian calendar */ if (y < 1753) { @@ -42,7 +42,23 @@ timelib_sll timelib_day_of_week(timelib_sll y, timelib_sll m, timelib_sll d) c1 = century_value(y / 100); y1 = (y % 100); m1 = timelib_is_leap(y) ? m_table_leap[m] : m_table_common[m]; - return (c1 + y1 + m1 + (y1 / 4) + d) % 7; + dow = (c1 + y1 + m1 + (y1 / 4) + d) % 7; + if (iso) { + if (dow == 0) { + dow = 7; + } + } + return dow; +} + +timelib_sll timelib_day_of_week(timelib_sll y, timelib_sll m, timelib_sll d) +{ + return timelib_day_of_week_ex(y, m, d, 0); +} + +timelib_sll timelib_iso_day_of_week(timelib_sll y, timelib_sll m, timelib_sll d) +{ + return timelib_day_of_week_ex(y, m, d, 1); } /* jan feb mar apr may jun jul aug sep oct nov dec */ diff --git a/ext/date/lib/timelib.h b/ext/date/lib/timelib.h index 02c8e4542d..ab3507f97b 100644 --- a/ext/date/lib/timelib.h +++ b/ext/date/lib/timelib.h @@ -40,6 +40,7 @@ /* From dow.c */ timelib_sll timelib_day_of_week(timelib_sll y, timelib_sll m, timelib_sll d); +timelib_sll timelib_iso_day_of_week(timelib_sll y, timelib_sll m, timelib_sll d); timelib_sll timelib_day_of_year(timelib_sll y, timelib_sll m, timelib_sll d); timelib_sll timelib_daynr_from_weeknr(timelib_sll y, timelib_sll w, timelib_sll d); timelib_sll timelib_days_in_month(timelib_sll y, timelib_sll m); diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 92be9ecf04..719f017177 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -489,6 +489,7 @@ static char *date_format(char *format, int format_len, int *return_len, timelib_ case 'l': length = date_spprintf(&buffer, 32 TSRMLS_CC, "%R", localized ? IS_UNICODE : IS_STRING, dayname_full(timelib_day_of_week(t->y, t->m, t->d), localized)); break; case 'S': length = date_spprintf(&buffer, 32 TSRMLS_CC, "%s", english_suffix(t->d)); break; case 'w': length = date_spprintf(&buffer, 32 TSRMLS_CC, "%d", (int) timelib_day_of_week(t->y, t->m, t->d)); break; + case 'N': length = date_spprintf(&buffer, 32 TSRMLS_CC, "%d", (int) timelib_iso_day_of_week(t->y, t->m, t->d)); break; case 'z': length = date_spprintf(&buffer, 32 TSRMLS_CC, "%d", (int) timelib_day_of_year(t->y, t->m, t->d)); break; /* week */