From: Matthias Clasen Date: Thu, 2 Sep 2004 00:27:27 +0000 (+0000) Subject: Add a function to calculate the ISO 8601 week number of a date. (#92579, X-Git-Tag: GLIB_2_5_3~28 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fbbf70e280e2fb06647877685f16399a5949dc7a;p=platform%2Fupstream%2Fglib.git Add a function to calculate the ISO 8601 week number of a date. (#92579, Wed Sep 1 20:22:39 2004 Matthias Clasen * glib/gdate.h: * glib/gdate.c (g_date_get_iso8601_week_of_year): Add a function to calculate the ISO 8601 week number of a date. (#92579, Niklas Lundell) --- diff --git a/ChangeLog b/ChangeLog index 51c46b1..9f97711 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Wed Sep 1 20:22:39 2004 Matthias Clasen + + * glib/gdate.h: + * glib/gdate.c (g_date_get_iso8601_week_of_year): Add + a function to calculate the ISO 8601 week number of + a date. (#92579, Niklas Lundell) + 2004-09-01 Anders Carlsson * glib/goption.c: (g_option_context_parse): diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 51c46b1..9f97711 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,10 @@ +Wed Sep 1 20:22:39 2004 Matthias Clasen + + * glib/gdate.h: + * glib/gdate.c (g_date_get_iso8601_week_of_year): Add + a function to calculate the ISO 8601 week number of + a date. (#92579, Niklas Lundell) + 2004-09-01 Anders Carlsson * glib/goption.c: (g_option_context_parse): diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 51c46b1..9f97711 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,10 @@ +Wed Sep 1 20:22:39 2004 Matthias Clasen + + * glib/gdate.h: + * glib/gdate.c (g_date_get_iso8601_week_of_year): Add + a function to calculate the ISO 8601 week number of + a date. (#92579, Niklas Lundell) + 2004-09-01 Anders Carlsson * glib/goption.c: (g_option_context_parse): diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 51c46b1..9f97711 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,10 @@ +Wed Sep 1 20:22:39 2004 Matthias Clasen + + * glib/gdate.h: + * glib/gdate.c (g_date_get_iso8601_week_of_year): Add + a function to calculate the ISO 8601 week number of + a date. (#92579, Niklas Lundell) + 2004-09-01 Anders Carlsson * glib/goption.c: (g_option_context_parse): diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 51c46b1..9f97711 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,10 @@ +Wed Sep 1 20:22:39 2004 Matthias Clasen + + * glib/gdate.h: + * glib/gdate.c (g_date_get_iso8601_week_of_year): Add + a function to calculate the ISO 8601 week number of + a date. (#92579, Niklas Lundell) + 2004-09-01 Anders Carlsson * glib/goption.c: (g_option_context_parse): diff --git a/glib/gdate.c b/glib/gdate.c index 62f84d5..8e12a8d 100644 --- a/glib/gdate.c +++ b/glib/gdate.c @@ -394,6 +394,42 @@ g_date_get_sunday_week_of_year (const GDate *d) return ((day + wd)/7U + (wd == 0 ? 1 : 0)); } +/** + * g_date_get_iso8601_week_of_year: + * @date: a valid #GDate + * + * Returns the week of the year, where weeks are interpreted according + * to ISO 8601. + * + * Returns: ISO 8601 week number of the year. + * + * Since: 2.6 + **/ +guint +g_date_get_iso8601_week_of_year (const GDate *d) +{ + guint j, d4, L, d1, w; + + g_return_val_if_fail (d != NULL, 0); + g_return_val_if_fail (g_date_valid (d), 0); + + if (!d->julian) + g_date_update_julian (d); + g_return_val_if_fail (d->julian, 0); + + /* Formula taken from the Calendar FAQ; the formula was for the + * 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; + d4 = (j + 31741 - (j % 7)) % 146097 % 36524 % 1461; + L = d4 / 1460; + d1 = ((d4 - L) % 365) + L; + w = d1 / 7 + 1; + + return w; +} + gint g_date_days_between (const GDate *d1, const GDate *d2) diff --git a/glib/gdate.h b/glib/gdate.h index 2b5eb32..eafb16a 100644 --- a/glib/gdate.h +++ b/glib/gdate.h @@ -150,6 +150,7 @@ guint g_date_get_day_of_year (const GDate *date); */ guint g_date_get_monday_week_of_year (const GDate *date); guint g_date_get_sunday_week_of_year (const GDate *date); +guint g_date_get_iso8601_week_of_year (const GDate *date); /* If you create a static date struct you need to clear it to get it * in a sane state before use. You can clear a whole array at