Add tests for g_date_get_iso8601_week_of_year().
authorMatthias Clasen <mclasen@redhat.com>
Mon, 28 Mar 2005 05:22:56 +0000 (05:22 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Mon, 28 Mar 2005 05:22:56 +0000 (05:22 +0000)
2005-03-28  Matthias Clasen  <mclasen@redhat.com>

* tests/date-test.c:
* tests/testgdate.c: Add tests for
g_date_get_iso8601_week_of_year().

* glib/gdate.c (g_date_get_iso8601_week_of_year):
Fix the calculation.  (#169858, Jon-Kare Hellan)

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-8
glib/gdate.c
tests/date-test.c
tests/testgdate.c

index 01c7fe0..1d14a65 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2005-03-28  Matthias Clasen  <mclasen@redhat.com>
+
+       * tests/date-test.c: 
+       * tests/testgdate.c: Add tests for 
+       g_date_get_iso8601_week_of_year().
+
+       * glib/gdate.c (g_date_get_iso8601_week_of_year): 
+       Fix the calculation.  (#169858, Jon-Kare Hellan)
+
 2005-03-27  Tor Lillqvist  <tml@novell.com>
 
        * configure.in: Apparently AC_LIBTOOL_WIN32_DLL isn't deprecated
index 01c7fe0..1d14a65 100644 (file)
@@ -1,3 +1,12 @@
+2005-03-28  Matthias Clasen  <mclasen@redhat.com>
+
+       * tests/date-test.c: 
+       * tests/testgdate.c: Add tests for 
+       g_date_get_iso8601_week_of_year().
+
+       * glib/gdate.c (g_date_get_iso8601_week_of_year): 
+       Fix the calculation.  (#169858, Jon-Kare Hellan)
+
 2005-03-27  Tor Lillqvist  <tml@novell.com>
 
        * configure.in: Apparently AC_LIBTOOL_WIN32_DLL isn't deprecated
index 01c7fe0..1d14a65 100644 (file)
@@ -1,3 +1,12 @@
+2005-03-28  Matthias Clasen  <mclasen@redhat.com>
+
+       * tests/date-test.c: 
+       * tests/testgdate.c: Add tests for 
+       g_date_get_iso8601_week_of_year().
+
+       * glib/gdate.c (g_date_get_iso8601_week_of_year): 
+       Fix the calculation.  (#169858, Jon-Kare Hellan)
+
 2005-03-27  Tor Lillqvist  <tml@novell.com>
 
        * configure.in: Apparently AC_LIBTOOL_WIN32_DLL isn't deprecated
index 01c7fe0..1d14a65 100644 (file)
@@ -1,3 +1,12 @@
+2005-03-28  Matthias Clasen  <mclasen@redhat.com>
+
+       * tests/date-test.c: 
+       * tests/testgdate.c: Add tests for 
+       g_date_get_iso8601_week_of_year().
+
+       * glib/gdate.c (g_date_get_iso8601_week_of_year): 
+       Fix the calculation.  (#169858, Jon-Kare Hellan)
+
 2005-03-27  Tor Lillqvist  <tml@novell.com>
 
        * configure.in: Apparently AC_LIBTOOL_WIN32_DLL isn't deprecated
index 4e204f1..85c6171 100644 (file)
@@ -414,7 +414,7 @@ g_date_get_iso8601_week_of_year (const GDate *d)
    * Julian Period which starts on 1 January 4713 BC, so we add
    * 1,721,425 to the number of days before doing the formula. 
    */
-  j  = d->julian + 1721425;
+  j  = d->julian_days + 1721425;
   d4 = (j + 31741 - (j % 7)) % 146097 % 36524 % 1461;
   L  = d4 / 1460;
   d1 = ((d4 - L) % 365) + L;
index d6e1d72..1a35030 100644 (file)
@@ -159,6 +159,7 @@ int main(int argc, char** argv)
       guint   sunday_weeks_in_year = g_date_get_sunday_weeks_in_year(y);
       guint   monday_week_of_year = 0;
       guint   monday_weeks_in_year = g_date_get_monday_weeks_in_year(y);
+      guint   iso8601_week_of_year = 0;
 
       if (discontinuity)
         g_print(" (Break in sequence of requested years to check)\n");
@@ -257,15 +258,28 @@ int main(int argc, char** argv)
                  
                  TEST("Monday week of year on Monday 1 more than previous day's week of year",
                       (g_date_get_monday_week_of_year(d) - monday_week_of_year) == 1);
+                 if ((m == G_DATE_JANUARY && day <= 4) ||
+                     (m == G_DATE_DECEMBER && day >= 29)) {
+                   TEST("ISO 8601 week of year on Monday Dec 29 - Jan 4 is 1",
+                        (g_date_get_iso8601_week_of_year(d) == 1));
+                 } else {
+                   TEST("ISO 8601 week of year on Monday 1 more than previous day's week of year",
+                        (g_date_get_iso8601_week_of_year(d) - iso8601_week_of_year) == 1);
+                 }
                }
              else 
                {
                  TEST("Monday week of year on non-Monday 0 more than previous day's week of year",
                       (g_date_get_monday_week_of_year(d) - monday_week_of_year) == 0);
+                 if (!(day == 1 && m == G_DATE_JANUARY)) {
+                   TEST("ISO 8601 week of year on non-Monday 0 more than previous day's week of year (",
+                        (g_date_get_iso8601_week_of_year(d) - iso8601_week_of_year) == 0);
+                 }
                }
 
 
              monday_week_of_year = g_date_get_monday_week_of_year(d);
+             iso8601_week_of_year = g_date_get_iso8601_week_of_year(d);
 
 
              TEST("Sunday week of year is not more than number of weeks in the year",
index ef4019e..85d22dc 100644 (file)
@@ -166,6 +166,7 @@ int main(int argc, char** argv)
       guint   sunday_weeks_in_year = g_date_get_sunday_weeks_in_year(y);
       guint   monday_week_of_year = 0;
       guint   monday_weeks_in_year = g_date_get_monday_weeks_in_year(y);
+      guint   iso8601_week_of_year = 0;
 
       if (discontinuity)
         g_print(" (Break in sequence of requested years to check)\n");
@@ -264,15 +265,28 @@ int main(int argc, char** argv)
                  
                  TEST("Monday week of year on Monday 1 more than previous day's week of year",
                       (g_date_get_monday_week_of_year(d) - monday_week_of_year) == 1);
+                 if ((m == G_DATE_JANUARY && day <= 4) ||
+                     (m == G_DATE_DECEMBER && day >= 29)) {
+                   TEST("ISO 8601 week of year on Monday Dec 29 - Jan 4 is 1",
+                        (g_date_get_iso8601_week_of_year(d) == 1));
+                 } else {
+                   TEST("ISO 8601 week of year on Monday 1 more than previous day's week of year",
+                        (g_date_get_iso8601_week_of_year(d) - iso8601_week_of_year) == 1);
+                 }
                }
              else 
                {
                  TEST("Monday week of year on non-Monday 0 more than previous day's week of year",
                       (g_date_get_monday_week_of_year(d) - monday_week_of_year) == 0);
+                 if (!(day == 1 && m == G_DATE_JANUARY)) {
+                   TEST("ISO 8601 week of year on non-Monday 0 more than previous day's week of year (",
+                        (g_date_get_iso8601_week_of_year(d) - iso8601_week_of_year) == 0);
+                 }
                }
 
 
              monday_week_of_year = g_date_get_monday_week_of_year(d);
+             iso8601_week_of_year = g_date_get_iso8601_week_of_year(d);
 
 
              TEST("Sunday week of year is not more than number of weeks in the year",