Commit fbbf70e2 authored by Matthias Clasen's avatar Matthias Clasen Committed by Matthias Clasen

Add a function to calculate the ISO 8601 week number of a date. (#92579,

Wed Sep  1 20:22:39 2004  Matthias Clasen  <maclas@gmx.de>

	* 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)
parent d1871edb
Wed Sep 1 20:22:39 2004 Matthias Clasen <maclas@gmx.de>
* 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 <andersca@gnome.org>
* glib/goption.c: (g_option_context_parse):
......
Wed Sep 1 20:22:39 2004 Matthias Clasen <maclas@gmx.de>
* 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 <andersca@gnome.org>
* glib/goption.c: (g_option_context_parse):
......
Wed Sep 1 20:22:39 2004 Matthias Clasen <maclas@gmx.de>
* 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 <andersca@gnome.org>
* glib/goption.c: (g_option_context_parse):
......
Wed Sep 1 20:22:39 2004 Matthias Clasen <maclas@gmx.de>
* 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 <andersca@gnome.org>
* glib/goption.c: (g_option_context_parse):
......
Wed Sep 1 20:22:39 2004 Matthias Clasen <maclas@gmx.de>
* 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 <andersca@gnome.org>
* glib/goption.c: (g_option_context_parse):
......
......@@ -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)
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment