mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-02 07:36:17 +01:00
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)
This commit is contained in:
parent
d1871edbdc
commit
fbbf70e280
@ -1,3 +1,10 @@
|
||||
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):
|
||||
|
@ -1,3 +1,10 @@
|
||||
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):
|
||||
|
@ -1,3 +1,10 @@
|
||||
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):
|
||||
|
@ -1,3 +1,10 @@
|
||||
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):
|
||||
|
@ -1,3 +1,10 @@
|
||||
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):
|
||||
|
36
glib/gdate.c
36
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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user