]> granicus.if.org Git - php/commitdiff
- Fixed bug #34304 (date() doesn't have a modifier for ISO Week Day).
authorDerick Rethans <derick@php.net>
Fri, 2 Sep 2005 09:33:08 +0000 (09:33 +0000)
committerDerick Rethans <derick@php.net>
Fri, 2 Sep 2005 09:33:08 +0000 (09:33 +0000)
NEWS
ext/date/lib/dow.c
ext/date/lib/timelib.h
ext/date/php_date.c
ext/date/tests/bug34304.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 2a460f1fe07cbc90ebd1a3f8c0478a7c978306b7..e17d64638498b5d0fe9d75d89fc652825481bc1a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,7 @@ PHP                                                                        NEWS
 - Fixed bug #34310 (foreach($arr as $c->d => $x) crashes). (Dmitry)
 - Fixed bug #34307 (OnUpdateStringUnempty INI options can be set empty). (Jani)
 - Fixed bug #34306 (wddx_serialize_value() crashes with long array keys). (Jani)
+- Fixed bug #34304 (date() doesn't have a modifier for ISO Week Day). (Derick)
 - Fixed bug #34302 (date('W') do not return leading zeros for week 1 to 9).
   (Derick)
 - Fixed bug #34299 (ReflectionClass::isInstantiable() returns true for abstract
index 4b51cf5dafad21ec1250cd92deb988ec442c4cdd..0c71c2dc6ab835515cb5d2bdf64b776fd4754d05 100644 (file)
@@ -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 */
index 02c8e4542d52e216effbe651dd742541924d3f80..ab3507f97b86dc5b8cbf0b1cfc62fe8c2a36190d 100644 (file)
@@ -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);
index 05eb26f58836f3c70cec65d46672a34ae18b8291..2cbac27478adec804940081d9c626555fe0478bd 100644 (file)
@@ -389,6 +389,7 @@ static char *date_format(char *format, int format_len, timelib_time *t, int loca
                        case 'l': snprintf(buffer, 32, "%s", day_full_names[timelib_day_of_week(t->y, t->m, t->d)]); break;
                        case 'S': snprintf(buffer, 32, "%s", english_suffix(t->d)); break;
                        case 'w': snprintf(buffer, 32, "%d", (int) timelib_day_of_week(t->y, t->m, t->d)); break;
+                       case 'N': snprintf(buffer, 32, "%d", (int) timelib_iso_day_of_week(t->y, t->m, t->d)); break;
                        case 'z': snprintf(buffer, 32, "%d", (int) timelib_day_of_year(t->y, t->m, t->d)); break;
 
                        /* week */
diff --git a/ext/date/tests/bug34304.phpt b/ext/date/tests/bug34304.phpt
new file mode 100644 (file)
index 0000000..a2b26a1
--- /dev/null
@@ -0,0 +1,11 @@
+--TEST--
+Bug #34304 ()
+--FILE--
+<?php
+date_default_timezone_set("UTC");
+echo date('o\-\WW\-N', strtotime('2 January 2005')), "\n";
+echo date('o\-\WW\-N', strtotime('9 January 2005')), "\n";
+?>
+--EXPECT--
+2004-W53-7
+2005-W01-7