1
0
mirror of https://gitlab.gnome.org/GNOME/glib.git synced 2025-04-23 07:39:17 +02:00

Changed to take a const argument, and then to cast out const.

2001-06-01  Jon Trowbridge  <trow@gnu.org>

       * gdate.c (g_date_update_julian): Changed to take a const
       argument, and then to cast out const.
       (g_date_update_dmy): Changed to take a const argument, and then
       cast out const.
       (g_date_get_weekday): Changed argument to be const.
       (g_date_get_month): Changed argument to be const.
       (g_date_get_year): Changed argument to be const.
       (g_date_get_day): Changed argument to be const.
       (g_date_get_julian): Changed argument to be const.
       (g_date_get_day_of_year): Changed argument to be const.
       (g_date_get_monday_week_of_year): Changed argument to be const.
       (g_date_get_sunday_week_of_year): Changed argument to be const.
       (g_date_compare): Changed arguments to be const.
       (g_date_to_struct_tm): Changed GDate argument to be const.
       (g_date_strftime): Changed GDate argument to be const.
       (g_date_clamp): Added.  The equivalent of the CLAMP macro for
       GDates.
       (g_date_order): Added.  Ensure that the first GDate argument
       preceeds the second, swapping them if necessary.
       (g_date_days_between): Added.  Computes the (signed) number of days
       between two dates.
This commit is contained in:
Jon Trowbridge 2001-06-05 20:59:02 +00:00 committed by Havoc Pennington
parent 96ba1917d8
commit 4d2b54ff8b
15 changed files with 422 additions and 65 deletions

@ -1,3 +1,27 @@
2001-06-01 Jon Trowbridge <trow@gnu.org>
* gdate.c (g_date_update_julian): Changed to take a const
argument, and then to cast out const.
(g_date_update_dmy): Changed to take a const argument, and then
cast out const.
(g_date_get_weekday): Changed argument to be const.
(g_date_get_month): Changed argument to be const.
(g_date_get_year): Changed argument to be const.
(g_date_get_day): Changed argument to be const.
(g_date_get_julian): Changed argument to be const.
(g_date_get_day_of_year): Changed argument to be const.
(g_date_get_monday_week_of_year): Changed argument to be const.
(g_date_get_sunday_week_of_year): Changed argument to be const.
(g_date_compare): Changed arguments to be const.
(g_date_to_struct_tm): Changed GDate argument to be const.
(g_date_strftime): Changed GDate argument to be const.
(g_date_clamp): Added. The equivalent of the CLAMP macro for
GDates.
(g_date_order): Added. Ensure that the first GDate argument
preceeds the second, swapping them if necessary.
(g_date_days_between): Added. Computes the (signed) number of days
between two dates.
Mon Jun 4 16:02:57 2001 Owen Taylor <otaylor@redhat.com> Mon Jun 4 16:02:57 2001 Owen Taylor <otaylor@redhat.com>
* gstrfuncs.c (g_strup/strdown): to match g_strcasecmp, * gstrfuncs.c (g_strup/strdown): to match g_strcasecmp,

@ -1,3 +1,27 @@
2001-06-01 Jon Trowbridge <trow@gnu.org>
* gdate.c (g_date_update_julian): Changed to take a const
argument, and then to cast out const.
(g_date_update_dmy): Changed to take a const argument, and then
cast out const.
(g_date_get_weekday): Changed argument to be const.
(g_date_get_month): Changed argument to be const.
(g_date_get_year): Changed argument to be const.
(g_date_get_day): Changed argument to be const.
(g_date_get_julian): Changed argument to be const.
(g_date_get_day_of_year): Changed argument to be const.
(g_date_get_monday_week_of_year): Changed argument to be const.
(g_date_get_sunday_week_of_year): Changed argument to be const.
(g_date_compare): Changed arguments to be const.
(g_date_to_struct_tm): Changed GDate argument to be const.
(g_date_strftime): Changed GDate argument to be const.
(g_date_clamp): Added. The equivalent of the CLAMP macro for
GDates.
(g_date_order): Added. Ensure that the first GDate argument
preceeds the second, swapping them if necessary.
(g_date_days_between): Added. Computes the (signed) number of days
between two dates.
Mon Jun 4 16:02:57 2001 Owen Taylor <otaylor@redhat.com> Mon Jun 4 16:02:57 2001 Owen Taylor <otaylor@redhat.com>
* gstrfuncs.c (g_strup/strdown): to match g_strcasecmp, * gstrfuncs.c (g_strup/strdown): to match g_strcasecmp,

@ -1,3 +1,27 @@
2001-06-01 Jon Trowbridge <trow@gnu.org>
* gdate.c (g_date_update_julian): Changed to take a const
argument, and then to cast out const.
(g_date_update_dmy): Changed to take a const argument, and then
cast out const.
(g_date_get_weekday): Changed argument to be const.
(g_date_get_month): Changed argument to be const.
(g_date_get_year): Changed argument to be const.
(g_date_get_day): Changed argument to be const.
(g_date_get_julian): Changed argument to be const.
(g_date_get_day_of_year): Changed argument to be const.
(g_date_get_monday_week_of_year): Changed argument to be const.
(g_date_get_sunday_week_of_year): Changed argument to be const.
(g_date_compare): Changed arguments to be const.
(g_date_to_struct_tm): Changed GDate argument to be const.
(g_date_strftime): Changed GDate argument to be const.
(g_date_clamp): Added. The equivalent of the CLAMP macro for
GDates.
(g_date_order): Added. Ensure that the first GDate argument
preceeds the second, swapping them if necessary.
(g_date_days_between): Added. Computes the (signed) number of days
between two dates.
Mon Jun 4 16:02:57 2001 Owen Taylor <otaylor@redhat.com> Mon Jun 4 16:02:57 2001 Owen Taylor <otaylor@redhat.com>
* gstrfuncs.c (g_strup/strdown): to match g_strcasecmp, * gstrfuncs.c (g_strup/strdown): to match g_strcasecmp,

@ -1,3 +1,27 @@
2001-06-01 Jon Trowbridge <trow@gnu.org>
* gdate.c (g_date_update_julian): Changed to take a const
argument, and then to cast out const.
(g_date_update_dmy): Changed to take a const argument, and then
cast out const.
(g_date_get_weekday): Changed argument to be const.
(g_date_get_month): Changed argument to be const.
(g_date_get_year): Changed argument to be const.
(g_date_get_day): Changed argument to be const.
(g_date_get_julian): Changed argument to be const.
(g_date_get_day_of_year): Changed argument to be const.
(g_date_get_monday_week_of_year): Changed argument to be const.
(g_date_get_sunday_week_of_year): Changed argument to be const.
(g_date_compare): Changed arguments to be const.
(g_date_to_struct_tm): Changed GDate argument to be const.
(g_date_strftime): Changed GDate argument to be const.
(g_date_clamp): Added. The equivalent of the CLAMP macro for
GDates.
(g_date_order): Added. Ensure that the first GDate argument
preceeds the second, swapping them if necessary.
(g_date_days_between): Added. Computes the (signed) number of days
between two dates.
Mon Jun 4 16:02:57 2001 Owen Taylor <otaylor@redhat.com> Mon Jun 4 16:02:57 2001 Owen Taylor <otaylor@redhat.com>
* gstrfuncs.c (g_strup/strdown): to match g_strcasecmp, * gstrfuncs.c (g_strup/strdown): to match g_strcasecmp,

@ -1,3 +1,27 @@
2001-06-01 Jon Trowbridge <trow@gnu.org>
* gdate.c (g_date_update_julian): Changed to take a const
argument, and then to cast out const.
(g_date_update_dmy): Changed to take a const argument, and then
cast out const.
(g_date_get_weekday): Changed argument to be const.
(g_date_get_month): Changed argument to be const.
(g_date_get_year): Changed argument to be const.
(g_date_get_day): Changed argument to be const.
(g_date_get_julian): Changed argument to be const.
(g_date_get_day_of_year): Changed argument to be const.
(g_date_get_monday_week_of_year): Changed argument to be const.
(g_date_get_sunday_week_of_year): Changed argument to be const.
(g_date_compare): Changed arguments to be const.
(g_date_to_struct_tm): Changed GDate argument to be const.
(g_date_strftime): Changed GDate argument to be const.
(g_date_clamp): Added. The equivalent of the CLAMP macro for
GDates.
(g_date_order): Added. Ensure that the first GDate argument
preceeds the second, swapping them if necessary.
(g_date_days_between): Added. Computes the (signed) number of days
between two dates.
Mon Jun 4 16:02:57 2001 Owen Taylor <otaylor@redhat.com> Mon Jun 4 16:02:57 2001 Owen Taylor <otaylor@redhat.com>
* gstrfuncs.c (g_strup/strdown): to match g_strcasecmp, * gstrfuncs.c (g_strup/strdown): to match g_strcasecmp,

@ -1,3 +1,27 @@
2001-06-01 Jon Trowbridge <trow@gnu.org>
* gdate.c (g_date_update_julian): Changed to take a const
argument, and then to cast out const.
(g_date_update_dmy): Changed to take a const argument, and then
cast out const.
(g_date_get_weekday): Changed argument to be const.
(g_date_get_month): Changed argument to be const.
(g_date_get_year): Changed argument to be const.
(g_date_get_day): Changed argument to be const.
(g_date_get_julian): Changed argument to be const.
(g_date_get_day_of_year): Changed argument to be const.
(g_date_get_monday_week_of_year): Changed argument to be const.
(g_date_get_sunday_week_of_year): Changed argument to be const.
(g_date_compare): Changed arguments to be const.
(g_date_to_struct_tm): Changed GDate argument to be const.
(g_date_strftime): Changed GDate argument to be const.
(g_date_clamp): Added. The equivalent of the CLAMP macro for
GDates.
(g_date_order): Added. Ensure that the first GDate argument
preceeds the second, swapping them if necessary.
(g_date_days_between): Added. Computes the (signed) number of days
between two dates.
Mon Jun 4 16:02:57 2001 Owen Taylor <otaylor@redhat.com> Mon Jun 4 16:02:57 2001 Owen Taylor <otaylor@redhat.com>
* gstrfuncs.c (g_strup/strdown): to match g_strcasecmp, * gstrfuncs.c (g_strup/strdown): to match g_strcasecmp,

@ -1,3 +1,27 @@
2001-06-01 Jon Trowbridge <trow@gnu.org>
* gdate.c (g_date_update_julian): Changed to take a const
argument, and then to cast out const.
(g_date_update_dmy): Changed to take a const argument, and then
cast out const.
(g_date_get_weekday): Changed argument to be const.
(g_date_get_month): Changed argument to be const.
(g_date_get_year): Changed argument to be const.
(g_date_get_day): Changed argument to be const.
(g_date_get_julian): Changed argument to be const.
(g_date_get_day_of_year): Changed argument to be const.
(g_date_get_monday_week_of_year): Changed argument to be const.
(g_date_get_sunday_week_of_year): Changed argument to be const.
(g_date_compare): Changed arguments to be const.
(g_date_to_struct_tm): Changed GDate argument to be const.
(g_date_strftime): Changed GDate argument to be const.
(g_date_clamp): Added. The equivalent of the CLAMP macro for
GDates.
(g_date_order): Added. Ensure that the first GDate argument
preceeds the second, swapping them if necessary.
(g_date_days_between): Added. Computes the (signed) number of days
between two dates.
Mon Jun 4 16:02:57 2001 Owen Taylor <otaylor@redhat.com> Mon Jun 4 16:02:57 2001 Owen Taylor <otaylor@redhat.com>
* gstrfuncs.c (g_strup/strdown): to match g_strcasecmp, * gstrfuncs.c (g_strup/strdown): to match g_strcasecmp,

@ -1,3 +1,27 @@
2001-06-01 Jon Trowbridge <trow@gnu.org>
* gdate.c (g_date_update_julian): Changed to take a const
argument, and then to cast out const.
(g_date_update_dmy): Changed to take a const argument, and then
cast out const.
(g_date_get_weekday): Changed argument to be const.
(g_date_get_month): Changed argument to be const.
(g_date_get_year): Changed argument to be const.
(g_date_get_day): Changed argument to be const.
(g_date_get_julian): Changed argument to be const.
(g_date_get_day_of_year): Changed argument to be const.
(g_date_get_monday_week_of_year): Changed argument to be const.
(g_date_get_sunday_week_of_year): Changed argument to be const.
(g_date_compare): Changed arguments to be const.
(g_date_to_struct_tm): Changed GDate argument to be const.
(g_date_strftime): Changed GDate argument to be const.
(g_date_clamp): Added. The equivalent of the CLAMP macro for
GDates.
(g_date_order): Added. Ensure that the first GDate argument
preceeds the second, swapping them if necessary.
(g_date_days_between): Added. Computes the (signed) number of days
between two dates.
Mon Jun 4 16:02:57 2001 Owen Taylor <otaylor@redhat.com> Mon Jun 4 16:02:57 2001 Owen Taylor <otaylor@redhat.com>
* gstrfuncs.c (g_strup/strdown): to match g_strcasecmp, * gstrfuncs.c (g_strup/strdown): to match g_strcasecmp,

@ -895,7 +895,10 @@ g_date_add_months
g_date_subtract_months g_date_subtract_months
g_date_add_years g_date_add_years
g_date_subtract_years g_date_subtract_years
g_date_days_between
g_date_compare g_date_compare
g_date_clamp
g_date_order
<SUBSECTION> <SUBSECTION>
g_date_get_day g_date_get_day

@ -414,6 +414,18 @@ must be valid.
@n_years: Number of years to move @n_years: Number of years to move
<!-- ##### FUNCTION g_date_days_between ##### -->
<para>
Compute the number of days between two dates.
If @date2 is prior to @date1, the returned value is negative.
Both dates must be valid.
</para>
@date1: The first date
@date2: The second date
@Returns: The number of days between @date1 and @date2
<!-- ##### FUNCTION g_date_compare ##### --> <!-- ##### FUNCTION g_date_compare ##### -->
<para> <para>
<function>qsort()</function>-style comparsion function for dates. Both <function>qsort()</function>-style comparsion function for dates. Both
@ -426,6 +438,29 @@ dates must be valid.
greater than zero if @lhs is greater than @rhs greater than zero if @lhs is greater than @rhs
<!-- ##### FUNCTION g_date_clamp ##### -->
<para>
If @date is prior to @min_date, set @date equal to @min_date.
If @date falls after @max_date, set @date equal to @max_date.
Either @min_date and @max_date may be %NULL. All non-%NULL dates
must be valid.
</para>
@date: Date to clamp
@min_date: Minimum accepted value for @date
@max_date: Maximum accepted value for @date
<!-- ##### FUNCTION g_date_order ##### -->
<para>
Check if @date1 is less than or equal to @date2,
and swap the values if this is not the case.
</para>
@date1: The first date
@date2: The second date
<!-- ##### FUNCTION g_date_get_day ##### --> <!-- ##### FUNCTION g_date_get_day ##### -->
<para> <para>
Return the day of the month; the #GDate must be valid. Return the day of the month; the #GDate must be valid.

@ -837,7 +837,6 @@ of the above functions.
@user_data: @user_data:
@Returns: @Returns:
<!-- <!--
Local variables: Local variables:
mode: sgml mode: sgml

86
gdate.c

@ -100,7 +100,7 @@ g_date_free (GDate *d)
} }
gboolean gboolean
g_date_valid (GDate *d) g_date_valid (const GDate *d)
{ {
g_return_val_if_fail (d != NULL, FALSE); g_return_val_if_fail (d != NULL, FALSE);
@ -167,8 +167,9 @@ g_date_valid_dmy (GDateDay d,
* Jan 1, Year 1 * Jan 1, Year 1
*/ */
static void static void
g_date_update_julian (GDate *d) g_date_update_julian (const GDate *const_d)
{ {
GDate *d = (GDate *) const_d;
GDateYear year; GDateYear year;
gint index; gint index;
@ -201,8 +202,9 @@ g_date_update_julian (GDate *d)
} }
static void static void
g_date_update_dmy (GDate *d) g_date_update_dmy (const GDate *const_d)
{ {
GDate *d = (GDate *) const_d;
GDateYear y; GDateYear y;
GDateMonth m; GDateMonth m;
GDateDay day; GDateDay day;
@ -249,7 +251,7 @@ g_date_update_dmy (GDate *d)
} }
GDateWeekday GDateWeekday
g_date_get_weekday (GDate *d) g_date_get_weekday (const GDate *d)
{ {
g_return_val_if_fail (d != NULL, G_DATE_BAD_WEEKDAY); g_return_val_if_fail (d != NULL, G_DATE_BAD_WEEKDAY);
g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_WEEKDAY); g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_WEEKDAY);
@ -264,7 +266,7 @@ g_date_get_weekday (GDate *d)
} }
GDateMonth GDateMonth
g_date_get_month (GDate *d) g_date_get_month (const GDate *d)
{ {
g_return_val_if_fail (d != NULL, G_DATE_BAD_MONTH); g_return_val_if_fail (d != NULL, G_DATE_BAD_MONTH);
g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_MONTH); g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_MONTH);
@ -279,7 +281,7 @@ g_date_get_month (GDate *d)
} }
GDateYear GDateYear
g_date_get_year (GDate *d) g_date_get_year (const GDate *d)
{ {
g_return_val_if_fail (d != NULL, G_DATE_BAD_YEAR); g_return_val_if_fail (d != NULL, G_DATE_BAD_YEAR);
g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_YEAR); g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_YEAR);
@ -294,7 +296,7 @@ g_date_get_year (GDate *d)
} }
GDateDay GDateDay
g_date_get_day (GDate *d) g_date_get_day (const GDate *d)
{ {
g_return_val_if_fail (d != NULL, G_DATE_BAD_DAY); g_return_val_if_fail (d != NULL, G_DATE_BAD_DAY);
g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_DAY); g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_DAY);
@ -309,7 +311,7 @@ g_date_get_day (GDate *d)
} }
guint32 guint32
g_date_get_julian (GDate *d) g_date_get_julian (const GDate *d)
{ {
g_return_val_if_fail (d != NULL, G_DATE_BAD_JULIAN); g_return_val_if_fail (d != NULL, G_DATE_BAD_JULIAN);
g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_JULIAN); g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_JULIAN);
@ -324,7 +326,7 @@ g_date_get_julian (GDate *d)
} }
guint guint
g_date_get_day_of_year (GDate *d) g_date_get_day_of_year (const GDate *d)
{ {
gint index; gint index;
@ -343,7 +345,7 @@ g_date_get_day_of_year (GDate *d)
} }
guint guint
g_date_get_monday_week_of_year (GDate *d) g_date_get_monday_week_of_year (const GDate *d)
{ {
GDateWeekday wd; GDateWeekday wd;
guint day; guint day;
@ -369,7 +371,7 @@ g_date_get_monday_week_of_year (GDate *d)
} }
guint guint
g_date_get_sunday_week_of_year (GDate *d) g_date_get_sunday_week_of_year (const GDate *d)
{ {
GDateWeekday wd; GDateWeekday wd;
guint day; guint day;
@ -395,6 +397,19 @@ g_date_get_sunday_week_of_year (GDate *d)
return ((day + wd)/7U + (wd == 0 ? 1 : 0)); return ((day + wd)/7U + (wd == 0 ? 1 : 0));
} }
gint
g_date_days_between (const GDate *d1,
const GDate *d2)
{
g_return_val_if_fail (d1 != NULL, 0);
g_return_val_if_fail (d2 != NULL, 0);
g_return_val_if_fail (g_date_valid (d1), 0);
g_return_val_if_fail (g_date_valid (d2), 0);
return (gint)g_date_get_julian (d2) - (gint)g_date_get_julian (d1);
}
void void
g_date_clear (GDate *d, guint ndates) g_date_clear (GDate *d, guint ndates)
{ {
@ -919,7 +934,7 @@ g_date_set_julian (GDate *d, guint32 j)
gboolean gboolean
g_date_is_first_of_month (GDate *d) g_date_is_first_of_month (const GDate *d)
{ {
g_return_val_if_fail (d != NULL, FALSE); g_return_val_if_fail (d != NULL, FALSE);
g_return_val_if_fail (g_date_valid (d), FALSE); g_return_val_if_fail (g_date_valid (d), FALSE);
@ -935,7 +950,7 @@ g_date_is_first_of_month (GDate *d)
} }
gboolean gboolean
g_date_is_last_of_month (GDate *d) g_date_is_last_of_month (const GDate *d)
{ {
gint index; gint index;
@ -1184,8 +1199,8 @@ g_date_get_sunday_weeks_in_year (GDateYear year)
} }
gint gint
g_date_compare (GDate *lhs, g_date_compare (const GDate *lhs,
GDate *rhs) const GDate *rhs)
{ {
g_return_val_if_fail (lhs != NULL, 0); g_return_val_if_fail (lhs != NULL, 0);
g_return_val_if_fail (rhs != NULL, 0); g_return_val_if_fail (rhs != NULL, 0);
@ -1235,7 +1250,7 @@ g_date_compare (GDate *lhs,
void void
g_date_to_struct_tm (GDate *d, g_date_to_struct_tm (const GDate *d,
struct tm *tm) struct tm *tm)
{ {
GDateWeekday day; GDateWeekday day;
@ -1273,11 +1288,48 @@ g_date_to_struct_tm (GDate *d,
tm->tm_isdst = -1; /* -1 means "information not available" */ tm->tm_isdst = -1; /* -1 means "information not available" */
} }
void
g_date_clamp (GDate *date,
const GDate *min_date,
const GDate *max_date)
{
g_return_if_fail (date);
g_return_if_fail (g_date_valid (date));
if (min_date != NULL)
g_return_if_fail (g_date_valid (min_date));
if (max_date != NULL)
g_return_if_fail (g_date_valid (max_date));
if (min_date != NULL && max_date != NULL)
g_return_if_fail (g_date_compare (min_date, max_date) <= 0);
if (min_date && g_date_compare (date, min_date) < 0)
*date = *min_date;
if (max_date && g_date_compare (max_date, date) < 0)
*date = *max_date;
}
void
g_date_order (GDate *date1,
GDate *date2)
{
g_return_if_fail (date1 != NULL);
g_return_if_fail (date2 != NULL);
g_return_if_fail (g_date_valid (date1));
g_return_if_fail (g_date_valid (date2));
if (g_date_compare (date1, date2) == 1) {
GDate tmp = *date1;
*date1 = *date2;
*date2 = tmp;
}
}
gsize gsize
g_date_strftime (gchar *s, g_date_strftime (gchar *s,
gsize slen, gsize slen,
const gchar *format, const gchar *format,
GDate *d) const GDate *d)
{ {
struct tm tm; struct tm tm;
gsize retval; gsize retval;

42
gdate.h

@ -126,7 +126,7 @@ void g_date_free (GDate *date);
* dates (the exceptions are the mutators, since you need those to * dates (the exceptions are the mutators, since you need those to
* return to validity). * return to validity).
*/ */
gboolean g_date_valid (GDate *date); gboolean g_date_valid (const GDate *date);
gboolean g_date_valid_day (GDateDay day) G_GNUC_CONST; gboolean g_date_valid_day (GDateDay day) G_GNUC_CONST;
gboolean g_date_valid_month (GDateMonth month) G_GNUC_CONST; gboolean g_date_valid_month (GDateMonth month) G_GNUC_CONST;
gboolean g_date_valid_year (GDateYear year) G_GNUC_CONST; gboolean g_date_valid_year (GDateYear year) G_GNUC_CONST;
@ -136,20 +136,20 @@ gboolean g_date_valid_dmy (GDateDay day,
GDateMonth month, GDateMonth month,
GDateYear year) G_GNUC_CONST; GDateYear year) G_GNUC_CONST;
GDateWeekday g_date_get_weekday (GDate *date); GDateWeekday g_date_get_weekday (const GDate *date);
GDateMonth g_date_get_month (GDate *date); GDateMonth g_date_get_month (const GDate *date);
GDateYear g_date_get_year (GDate *date); GDateYear g_date_get_year (const GDate *date);
GDateDay g_date_get_day (GDate *date); GDateDay g_date_get_day (const GDate *date);
guint32 g_date_get_julian (GDate *date); guint32 g_date_get_julian (const GDate *date);
guint g_date_get_day_of_year (GDate *date); guint g_date_get_day_of_year (const GDate *date);
/* First monday/sunday is the start of week 1; if we haven't reached /* First monday/sunday is the start of week 1; if we haven't reached
* that day, return 0. These are not ISO weeks of the year; that * that day, return 0. These are not ISO weeks of the year; that
* routine needs to be added. * routine needs to be added.
* these functions return the number of weeks, starting on the * these functions return the number of weeks, starting on the
* corrsponding day * corrsponding day
*/ */
guint g_date_get_monday_week_of_year (GDate *date); guint g_date_get_monday_week_of_year (const GDate *date);
guint g_date_get_sunday_week_of_year (GDate *date); guint g_date_get_sunday_week_of_year (const GDate *date);
/* If you create a static date struct you need to clear it to get it /* 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 * in a sane state before use. You can clear a whole array at
@ -178,8 +178,8 @@ void g_date_set_dmy (GDate *date,
GDateYear y); GDateYear y);
void g_date_set_julian (GDate *date, void g_date_set_julian (GDate *date,
guint32 julian_date); guint32 julian_date);
gboolean g_date_is_first_of_month (GDate *date); gboolean g_date_is_first_of_month (const GDate *date);
gboolean g_date_is_last_of_month (GDate *date); gboolean g_date_is_last_of_month (const GDate *date);
/* To go forward by some number of weeks just go forward weeks*7 days */ /* To go forward by some number of weeks just go forward weeks*7 days */
void g_date_add_days (GDate *date, void g_date_add_days (GDate *date,
@ -204,19 +204,31 @@ guint8 g_date_get_days_in_month (GDateMonth month,
guint8 g_date_get_monday_weeks_in_year (GDateYear year) G_GNUC_CONST; guint8 g_date_get_monday_weeks_in_year (GDateYear year) G_GNUC_CONST;
guint8 g_date_get_sunday_weeks_in_year (GDateYear year) G_GNUC_CONST; guint8 g_date_get_sunday_weeks_in_year (GDateYear year) G_GNUC_CONST;
/* Returns the number of days between the two dates. If date2 comes
before date1, a negative value is return. */
gint g_date_days_between (const GDate *date1,
const GDate *date2);
/* qsort-friendly (with a cast...) */ /* qsort-friendly (with a cast...) */
gint g_date_compare (GDate *lhs, gint g_date_compare (const GDate *lhs,
GDate *rhs); const GDate *rhs);
void g_date_to_struct_tm (GDate *date, void g_date_to_struct_tm (const GDate *date,
struct tm *tm); struct tm *tm);
void g_date_clamp (GDate *date,
const GDate *min_date,
const GDate *max_date);
/* Swap date1 and date2's values if date1 > date2. */
void g_date_order (GDate *date1, GDate *date2);
/* Just like strftime() except you can only use date-related formats. /* Just like strftime() except you can only use date-related formats.
* Using a time format is undefined. * Using a time format is undefined.
*/ */
gsize g_date_strftime (gchar *s, gsize g_date_strftime (gchar *s,
gsize slen, gsize slen,
const gchar *format, const gchar *format,
GDate *date); const GDate *date);
#ifndef G_DISABLE_DEPRECATED #ifndef G_DISABLE_DEPRECATED

@ -100,7 +100,7 @@ g_date_free (GDate *d)
} }
gboolean gboolean
g_date_valid (GDate *d) g_date_valid (const GDate *d)
{ {
g_return_val_if_fail (d != NULL, FALSE); g_return_val_if_fail (d != NULL, FALSE);
@ -167,8 +167,9 @@ g_date_valid_dmy (GDateDay d,
* Jan 1, Year 1 * Jan 1, Year 1
*/ */
static void static void
g_date_update_julian (GDate *d) g_date_update_julian (const GDate *const_d)
{ {
GDate *d = (GDate *) const_d;
GDateYear year; GDateYear year;
gint index; gint index;
@ -201,8 +202,9 @@ g_date_update_julian (GDate *d)
} }
static void static void
g_date_update_dmy (GDate *d) g_date_update_dmy (const GDate *const_d)
{ {
GDate *d = (GDate *) const_d;
GDateYear y; GDateYear y;
GDateMonth m; GDateMonth m;
GDateDay day; GDateDay day;
@ -249,7 +251,7 @@ g_date_update_dmy (GDate *d)
} }
GDateWeekday GDateWeekday
g_date_get_weekday (GDate *d) g_date_get_weekday (const GDate *d)
{ {
g_return_val_if_fail (d != NULL, G_DATE_BAD_WEEKDAY); g_return_val_if_fail (d != NULL, G_DATE_BAD_WEEKDAY);
g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_WEEKDAY); g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_WEEKDAY);
@ -264,7 +266,7 @@ g_date_get_weekday (GDate *d)
} }
GDateMonth GDateMonth
g_date_get_month (GDate *d) g_date_get_month (const GDate *d)
{ {
g_return_val_if_fail (d != NULL, G_DATE_BAD_MONTH); g_return_val_if_fail (d != NULL, G_DATE_BAD_MONTH);
g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_MONTH); g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_MONTH);
@ -279,7 +281,7 @@ g_date_get_month (GDate *d)
} }
GDateYear GDateYear
g_date_get_year (GDate *d) g_date_get_year (const GDate *d)
{ {
g_return_val_if_fail (d != NULL, G_DATE_BAD_YEAR); g_return_val_if_fail (d != NULL, G_DATE_BAD_YEAR);
g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_YEAR); g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_YEAR);
@ -294,7 +296,7 @@ g_date_get_year (GDate *d)
} }
GDateDay GDateDay
g_date_get_day (GDate *d) g_date_get_day (const GDate *d)
{ {
g_return_val_if_fail (d != NULL, G_DATE_BAD_DAY); g_return_val_if_fail (d != NULL, G_DATE_BAD_DAY);
g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_DAY); g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_DAY);
@ -309,7 +311,7 @@ g_date_get_day (GDate *d)
} }
guint32 guint32
g_date_get_julian (GDate *d) g_date_get_julian (const GDate *d)
{ {
g_return_val_if_fail (d != NULL, G_DATE_BAD_JULIAN); g_return_val_if_fail (d != NULL, G_DATE_BAD_JULIAN);
g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_JULIAN); g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_JULIAN);
@ -324,7 +326,7 @@ g_date_get_julian (GDate *d)
} }
guint guint
g_date_get_day_of_year (GDate *d) g_date_get_day_of_year (const GDate *d)
{ {
gint index; gint index;
@ -343,7 +345,7 @@ g_date_get_day_of_year (GDate *d)
} }
guint guint
g_date_get_monday_week_of_year (GDate *d) g_date_get_monday_week_of_year (const GDate *d)
{ {
GDateWeekday wd; GDateWeekday wd;
guint day; guint day;
@ -369,7 +371,7 @@ g_date_get_monday_week_of_year (GDate *d)
} }
guint guint
g_date_get_sunday_week_of_year (GDate *d) g_date_get_sunday_week_of_year (const GDate *d)
{ {
GDateWeekday wd; GDateWeekday wd;
guint day; guint day;
@ -395,6 +397,19 @@ g_date_get_sunday_week_of_year (GDate *d)
return ((day + wd)/7U + (wd == 0 ? 1 : 0)); return ((day + wd)/7U + (wd == 0 ? 1 : 0));
} }
gint
g_date_days_between (const GDate *d1,
const GDate *d2)
{
g_return_val_if_fail (d1 != NULL, 0);
g_return_val_if_fail (d2 != NULL, 0);
g_return_val_if_fail (g_date_valid (d1), 0);
g_return_val_if_fail (g_date_valid (d2), 0);
return (gint)g_date_get_julian (d2) - (gint)g_date_get_julian (d1);
}
void void
g_date_clear (GDate *d, guint ndates) g_date_clear (GDate *d, guint ndates)
{ {
@ -919,7 +934,7 @@ g_date_set_julian (GDate *d, guint32 j)
gboolean gboolean
g_date_is_first_of_month (GDate *d) g_date_is_first_of_month (const GDate *d)
{ {
g_return_val_if_fail (d != NULL, FALSE); g_return_val_if_fail (d != NULL, FALSE);
g_return_val_if_fail (g_date_valid (d), FALSE); g_return_val_if_fail (g_date_valid (d), FALSE);
@ -935,7 +950,7 @@ g_date_is_first_of_month (GDate *d)
} }
gboolean gboolean
g_date_is_last_of_month (GDate *d) g_date_is_last_of_month (const GDate *d)
{ {
gint index; gint index;
@ -1184,8 +1199,8 @@ g_date_get_sunday_weeks_in_year (GDateYear year)
} }
gint gint
g_date_compare (GDate *lhs, g_date_compare (const GDate *lhs,
GDate *rhs) const GDate *rhs)
{ {
g_return_val_if_fail (lhs != NULL, 0); g_return_val_if_fail (lhs != NULL, 0);
g_return_val_if_fail (rhs != NULL, 0); g_return_val_if_fail (rhs != NULL, 0);
@ -1235,7 +1250,7 @@ g_date_compare (GDate *lhs,
void void
g_date_to_struct_tm (GDate *d, g_date_to_struct_tm (const GDate *d,
struct tm *tm) struct tm *tm)
{ {
GDateWeekday day; GDateWeekday day;
@ -1273,11 +1288,48 @@ g_date_to_struct_tm (GDate *d,
tm->tm_isdst = -1; /* -1 means "information not available" */ tm->tm_isdst = -1; /* -1 means "information not available" */
} }
void
g_date_clamp (GDate *date,
const GDate *min_date,
const GDate *max_date)
{
g_return_if_fail (date);
g_return_if_fail (g_date_valid (date));
if (min_date != NULL)
g_return_if_fail (g_date_valid (min_date));
if (max_date != NULL)
g_return_if_fail (g_date_valid (max_date));
if (min_date != NULL && max_date != NULL)
g_return_if_fail (g_date_compare (min_date, max_date) <= 0);
if (min_date && g_date_compare (date, min_date) < 0)
*date = *min_date;
if (max_date && g_date_compare (max_date, date) < 0)
*date = *max_date;
}
void
g_date_order (GDate *date1,
GDate *date2)
{
g_return_if_fail (date1 != NULL);
g_return_if_fail (date2 != NULL);
g_return_if_fail (g_date_valid (date1));
g_return_if_fail (g_date_valid (date2));
if (g_date_compare (date1, date2) == 1) {
GDate tmp = *date1;
*date1 = *date2;
*date2 = tmp;
}
}
gsize gsize
g_date_strftime (gchar *s, g_date_strftime (gchar *s,
gsize slen, gsize slen,
const gchar *format, const gchar *format,
GDate *d) const GDate *d)
{ {
struct tm tm; struct tm tm;
gsize retval; gsize retval;

@ -126,7 +126,7 @@ void g_date_free (GDate *date);
* dates (the exceptions are the mutators, since you need those to * dates (the exceptions are the mutators, since you need those to
* return to validity). * return to validity).
*/ */
gboolean g_date_valid (GDate *date); gboolean g_date_valid (const GDate *date);
gboolean g_date_valid_day (GDateDay day) G_GNUC_CONST; gboolean g_date_valid_day (GDateDay day) G_GNUC_CONST;
gboolean g_date_valid_month (GDateMonth month) G_GNUC_CONST; gboolean g_date_valid_month (GDateMonth month) G_GNUC_CONST;
gboolean g_date_valid_year (GDateYear year) G_GNUC_CONST; gboolean g_date_valid_year (GDateYear year) G_GNUC_CONST;
@ -136,20 +136,20 @@ gboolean g_date_valid_dmy (GDateDay day,
GDateMonth month, GDateMonth month,
GDateYear year) G_GNUC_CONST; GDateYear year) G_GNUC_CONST;
GDateWeekday g_date_get_weekday (GDate *date); GDateWeekday g_date_get_weekday (const GDate *date);
GDateMonth g_date_get_month (GDate *date); GDateMonth g_date_get_month (const GDate *date);
GDateYear g_date_get_year (GDate *date); GDateYear g_date_get_year (const GDate *date);
GDateDay g_date_get_day (GDate *date); GDateDay g_date_get_day (const GDate *date);
guint32 g_date_get_julian (GDate *date); guint32 g_date_get_julian (const GDate *date);
guint g_date_get_day_of_year (GDate *date); guint g_date_get_day_of_year (const GDate *date);
/* First monday/sunday is the start of week 1; if we haven't reached /* First monday/sunday is the start of week 1; if we haven't reached
* that day, return 0. These are not ISO weeks of the year; that * that day, return 0. These are not ISO weeks of the year; that
* routine needs to be added. * routine needs to be added.
* these functions return the number of weeks, starting on the * these functions return the number of weeks, starting on the
* corrsponding day * corrsponding day
*/ */
guint g_date_get_monday_week_of_year (GDate *date); guint g_date_get_monday_week_of_year (const GDate *date);
guint g_date_get_sunday_week_of_year (GDate *date); guint g_date_get_sunday_week_of_year (const GDate *date);
/* If you create a static date struct you need to clear it to get it /* 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 * in a sane state before use. You can clear a whole array at
@ -178,8 +178,8 @@ void g_date_set_dmy (GDate *date,
GDateYear y); GDateYear y);
void g_date_set_julian (GDate *date, void g_date_set_julian (GDate *date,
guint32 julian_date); guint32 julian_date);
gboolean g_date_is_first_of_month (GDate *date); gboolean g_date_is_first_of_month (const GDate *date);
gboolean g_date_is_last_of_month (GDate *date); gboolean g_date_is_last_of_month (const GDate *date);
/* To go forward by some number of weeks just go forward weeks*7 days */ /* To go forward by some number of weeks just go forward weeks*7 days */
void g_date_add_days (GDate *date, void g_date_add_days (GDate *date,
@ -204,19 +204,31 @@ guint8 g_date_get_days_in_month (GDateMonth month,
guint8 g_date_get_monday_weeks_in_year (GDateYear year) G_GNUC_CONST; guint8 g_date_get_monday_weeks_in_year (GDateYear year) G_GNUC_CONST;
guint8 g_date_get_sunday_weeks_in_year (GDateYear year) G_GNUC_CONST; guint8 g_date_get_sunday_weeks_in_year (GDateYear year) G_GNUC_CONST;
/* Returns the number of days between the two dates. If date2 comes
before date1, a negative value is return. */
gint g_date_days_between (const GDate *date1,
const GDate *date2);
/* qsort-friendly (with a cast...) */ /* qsort-friendly (with a cast...) */
gint g_date_compare (GDate *lhs, gint g_date_compare (const GDate *lhs,
GDate *rhs); const GDate *rhs);
void g_date_to_struct_tm (GDate *date, void g_date_to_struct_tm (const GDate *date,
struct tm *tm); struct tm *tm);
void g_date_clamp (GDate *date,
const GDate *min_date,
const GDate *max_date);
/* Swap date1 and date2's values if date1 > date2. */
void g_date_order (GDate *date1, GDate *date2);
/* Just like strftime() except you can only use date-related formats. /* Just like strftime() except you can only use date-related formats.
* Using a time format is undefined. * Using a time format is undefined.
*/ */
gsize g_date_strftime (gchar *s, gsize g_date_strftime (gchar *s,
gsize slen, gsize slen,
const gchar *format, const gchar *format,
GDate *date); const GDate *date);
#ifndef G_DISABLE_DEPRECATED #ifndef G_DISABLE_DEPRECATED