if ((passed+notpassed) % 10000 == 0) g_print ("."); fflush (stdout); \
} G_STMT_END
-void g_date_debug_print(GDate* d)
+static void
+g_date_debug_print (GDate* d)
{
if (!d) g_print("NULL!\n");
else
3000, 3001, 3002, 3998, 3999, 4000, 4001, 4002, 4003
};
guint n_check_years = sizeof(check_years)/sizeof(GDateYear);
- guint i;
+ guint i, k;
gboolean discontinuity;
g_print("checking GDate...");
discontinuity = TRUE;
y = check_years[0];
prev_y = G_DATE_BAD_YEAR;
- while (i < n_check_years)
+g_print ("testing %d years\n", n_check_years);
+ while (i < n_check_years)
{
guint32 first_day_of_year = G_DATE_BAD_JULIAN;
guint16 days_in_year = g_date_is_leap_year(y) ? 366 : 365;
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");
while (day <= dim)
{
- guint i;
GDate tmp;
TEST("DMY triplet is valid", g_date_valid_dmy(day,m,y));
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",
/*************** Increments ***********/
- i = 1;
- while (i < 402) /* Need to get 400 year increments in */
+ k = 1;
+ while (k < 402) /* Need to get 400 year increments in */
{
/***** Days ******/
tmp = *d;
- g_date_add_days(d, i);
+ g_date_add_days(d, k);
TEST("Adding days gives a value greater than previous",
g_date_compare(d, &tmp) > 0);
- g_date_subtract_days(d, i);
+ g_date_subtract_days(d, k);
TEST("Forward days then backward days returns us to current day",
g_date_get_day(d) == day);
if (failed)
{
- g_print(" (increment %u, dmy %u %u %u) ", i, day, m, y);
+ g_print(" (increment %u, dmy %u %u %u) ", k, day, m, y);
g_date_debug_print(d);
}
if (failed)
{
- g_print(" (increment %u, dmy %u %u %u) ", i, day, m, y);
+ g_print(" (increment %u, dmy %u %u %u) ", k, day, m, y);
g_date_debug_print(d);
}
if (failed)
{
- g_print(" (increment %u, dmy %u %u %u) ", i, day, m, y);
+ g_print(" (increment %u, dmy %u %u %u) ", k, day, m, y);
g_date_debug_print(d);
}
/******* Months ********/
tmp = *d;
- g_date_add_months(d, i);
+ g_date_add_months(d, k);
TEST("Adding months gives a larger value",
g_date_compare(d, &tmp) > 0);
- g_date_subtract_months(d, i);
+ g_date_subtract_months(d, k);
TEST("Forward months then backward months returns us to current month",
g_date_get_month(d) == m);
if (failed)
{
- g_print(" (increment %u, dmy %u %u %u) ", i, day, m, y);
+ g_print(" (increment %u, dmy %u %u %u) ", k, day, m, y);
g_date_debug_print(d);
}
if (failed)
{
- g_print(" (increment %u, dmy %u %u %u) ", i, day, m, y);
+ g_print(" (increment %u, dmy %u %u %u) ", k, day, m, y);
g_date_debug_print(d);
}
if (failed)
{
- g_print(" (increment %u, dmy %u %u %u) ", i, day, m, y);
+ g_print(" (increment %u, dmy %u %u %u) ", k, day, m, y);
g_date_debug_print(d);
}
}
/******* Years ********/
tmp = *d;
- g_date_add_years(d, i);
+ g_date_add_years(d, k);
TEST("Adding years gives a larger value",
g_date_compare(d,&tmp) > 0);
- g_date_subtract_years(d, i);
+ g_date_subtract_years(d, k);
TEST("Forward years then backward years returns us to current month",
g_date_get_month(d) == m);
if (failed)
{
- g_print(" (increment %u, dmy %u %u %u) ", i, day, m, y);
+ g_print(" (increment %u, dmy %u %u %u) ", k, day, m, y);
g_date_debug_print(d);
}
if (failed)
{
- g_print(" (increment %u, dmy %u %u %u) ", i, day, m, y);
+ g_print(" (increment %u, dmy %u %u %u) ", k, day, m, y);
g_date_debug_print(d);
}
if (failed)
{
- g_print(" (increment %u, dmy %u %u %u) ", i, day, m, y);
+ g_print(" (increment %u, dmy %u %u %u) ", k, day, m, y);
g_date_debug_print(d);
}
}
g_date_set_day(d, day); /* reset */
}
- i += 10;
+ k += 10;
}
/***** increment test relative to our local Julian count */
}
g_print(" done\n");
++i;
+ if (i == n_check_years)
+ break;
prev_y = y;
y = check_years[i];
if (prev_y == G_DATE_BAD_YEAR ||