Improve g_date_clamp docs. (#491970, Areg Beketovski)

2007-11-09  Matthias Clasen <mclasen@redhat.com>

        * glib/tmpl/date.sgml: Improve g_date_clamp docs.  (#491970,
        Areg Beketovski)


svn path=/trunk/; revision=5849
This commit is contained in:
Matthias Clasen 2007-11-10 00:16:23 +00:00 committed by Matthias Clasen
parent 284c7e559b
commit 0a967d39e7
4 changed files with 91 additions and 101 deletions

View File

@ -1,3 +1,7 @@
2007-11-09 Matthias Clasen <mclasen@redhat.com>
* glib/gdate.c: Coding style fixes.
2007-11-09 Matthias Clasen <mclasen@redhat.com> 2007-11-09 Matthias Clasen <mclasen@redhat.com>
* configure.in: Add AM_PROG_CC_C_O. * configure.in: Add AM_PROG_CC_C_O.

View File

@ -1,3 +1,8 @@
2007-11-09 Matthias Clasen <mclasen@redhat.com>
* glib/tmpl/date.sgml: Improve g_date_clamp docs. (#491970,
Areg Beketovski)
2007-11-08 Matthias Clasen <mclasen@redhat.com> 2007-11-08 Matthias Clasen <mclasen@redhat.com>
* glib/tmpl/memory.sgml * glib/tmpl/memory.sgml

View File

@ -509,6 +509,7 @@ dates must be valid.
<para> <para>
If @date is prior to @min_date, sets @date equal to @min_date. If @date is prior to @min_date, sets @date equal to @min_date.
If @date falls after @max_date, sets @date equal to @max_date. If @date falls after @max_date, sets @date equal to @max_date.
Otherwise, @date is unchanged.
Either @min_date and @max_date may be %NULL. All non-%NULL dates Either @min_date and @max_date may be %NULL. All non-%NULL dates
must be valid. must be valid.
</para> </para>

View File

@ -57,7 +57,9 @@ g_date_new (void)
} }
GDate* GDate*
g_date_new_dmy (GDateDay day, GDateMonth m, GDateYear y) g_date_new_dmy (GDateDay day,
GDateMonth m,
GDateYear y)
{ {
GDate *d; GDate *d;
g_return_val_if_fail (g_date_valid_dmy (day, m, y), NULL); g_return_val_if_fail (g_date_valid_dmy (day, m, y), NULL);
@ -123,19 +125,19 @@ static const guint16 days_in_year[2][14] =
}; };
gboolean gboolean
g_date_valid_month (GDateMonth m) g_date_valid_month (GDateMonth m)
{ {
return ( (m > G_DATE_BAD_MONTH) && (m < 13) ); return ( (m > G_DATE_BAD_MONTH) && (m < 13) );
} }
gboolean gboolean
g_date_valid_year (GDateYear y) g_date_valid_year (GDateYear y)
{ {
return ( y > G_DATE_BAD_YEAR ); return ( y > G_DATE_BAD_YEAR );
} }
gboolean gboolean
g_date_valid_day (GDateDay d) g_date_valid_day (GDateDay d)
{ {
return ( (d > G_DATE_BAD_DAY) && (d < 32) ); return ( (d > G_DATE_BAD_DAY) && (d < 32) );
} }
@ -147,15 +149,15 @@ g_date_valid_weekday (GDateWeekday w)
} }
gboolean gboolean
g_date_valid_julian (guint32 j) g_date_valid_julian (guint32 j)
{ {
return (j > G_DATE_BAD_JULIAN); return (j > G_DATE_BAD_JULIAN);
} }
gboolean gboolean
g_date_valid_dmy (GDateDay d, g_date_valid_dmy (GDateDay d,
GDateMonth m, GDateMonth m,
GDateYear y) GDateYear y)
{ {
return ( (m > G_DATE_BAD_MONTH) && return ( (m > G_DATE_BAD_MONTH) &&
(m < 13) && (m < 13) &&
@ -240,10 +242,8 @@ g_date_update_dmy (const GDate *const_d)
#ifdef G_ENABLE_DEBUG #ifdef G_ENABLE_DEBUG
if (!g_date_valid_dmy (day, m, y)) if (!g_date_valid_dmy (day, m, y))
{ g_warning ("\nOOPS julian: %u computed dmy: %u %u %u\n",
g_warning ("\nOOPS julian: %u computed dmy: %u %u %u\n", d->julian_days, day, m, y);
d->julian_days, day, m, y);
}
#endif #endif
d->month = m; d->month = m;
@ -259,9 +259,8 @@ g_date_get_weekday (const GDate *d)
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);
if (!d->julian) if (!d->julian)
{ g_date_update_julian (d);
g_date_update_julian (d);
}
g_return_val_if_fail (d->julian, G_DATE_BAD_WEEKDAY); g_return_val_if_fail (d->julian, G_DATE_BAD_WEEKDAY);
return ((d->julian_days - 1) % 7) + 1; return ((d->julian_days - 1) % 7) + 1;
@ -273,9 +272,8 @@ g_date_get_month (const GDate *d)
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);
if (!d->dmy) if (!d->dmy)
{ g_date_update_dmy (d);
g_date_update_dmy (d);
}
g_return_val_if_fail (d->dmy, G_DATE_BAD_MONTH); g_return_val_if_fail (d->dmy, G_DATE_BAD_MONTH);
return d->month; return d->month;
@ -287,9 +285,8 @@ g_date_get_year (const GDate *d)
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);
if (!d->dmy) if (!d->dmy)
{ g_date_update_dmy (d);
g_date_update_dmy (d);
}
g_return_val_if_fail (d->dmy, G_DATE_BAD_YEAR); g_return_val_if_fail (d->dmy, G_DATE_BAD_YEAR);
return d->year; return d->year;
@ -301,9 +298,8 @@ g_date_get_day (const GDate *d)
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);
if (!d->dmy) if (!d->dmy)
{ g_date_update_dmy (d);
g_date_update_dmy (d);
}
g_return_val_if_fail (d->dmy, G_DATE_BAD_DAY); g_return_val_if_fail (d->dmy, G_DATE_BAD_DAY);
return d->day; return d->day;
@ -315,9 +311,8 @@ g_date_get_julian (const GDate *d)
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);
if (!d->julian) if (!d->julian)
{ g_date_update_julian (d);
g_date_update_julian (d);
}
g_return_val_if_fail (d->julian, G_DATE_BAD_JULIAN); g_return_val_if_fail (d->julian, G_DATE_BAD_JULIAN);
return d->julian_days; return d->julian_days;
@ -331,9 +326,8 @@ g_date_get_day_of_year (const GDate *d)
g_return_val_if_fail (g_date_valid (d), 0); g_return_val_if_fail (g_date_valid (d), 0);
if (!d->dmy) if (!d->dmy)
{ g_date_update_dmy (d);
g_date_update_dmy (d);
}
g_return_val_if_fail (d->dmy, 0); g_return_val_if_fail (d->dmy, 0);
index = g_date_is_leap_year (d->year) ? 1 : 0; index = g_date_is_leap_year (d->year) ? 1 : 0;
@ -351,9 +345,8 @@ g_date_get_monday_week_of_year (const GDate *d)
g_return_val_if_fail (g_date_valid (d), 0); g_return_val_if_fail (g_date_valid (d), 0);
if (!d->dmy) if (!d->dmy)
{ g_date_update_dmy (d);
g_date_update_dmy (d);
}
g_return_val_if_fail (d->dmy, 0); g_return_val_if_fail (d->dmy, 0);
g_date_clear (&first, 1); g_date_clear (&first, 1);
@ -376,9 +369,8 @@ g_date_get_sunday_week_of_year (const GDate *d)
g_return_val_if_fail (g_date_valid (d), 0); g_return_val_if_fail (g_date_valid (d), 0);
if (!d->dmy) if (!d->dmy)
{ g_date_update_dmy (d);
g_date_update_dmy (d);
}
g_return_val_if_fail (d->dmy, 0); g_return_val_if_fail (d->dmy, 0);
g_date_clear (&first, 1); g_date_clear (&first, 1);
@ -412,6 +404,7 @@ g_date_get_iso8601_week_of_year (const GDate *d)
if (!d->julian) if (!d->julian)
g_date_update_julian (d); g_date_update_julian (d);
g_return_val_if_fail (d->julian, 0); g_return_val_if_fail (d->julian, 0);
/* Formula taken from the Calendar FAQ; the formula was for the /* Formula taken from the Calendar FAQ; the formula was for the
@ -584,7 +577,8 @@ g_date_fill_parse_tokens (const gchar *str, GDateParseTokens *pt)
/* HOLDS: g_date_global_lock */ /* HOLDS: g_date_global_lock */
static void static void
g_date_prepare_to_parse (const gchar *str, GDateParseTokens *pt) g_date_prepare_to_parse (const gchar *str,
GDateParseTokens *pt)
{ {
const gchar *locale = setlocale (LC_TIME, NULL); const gchar *locale = setlocale (LC_TIME, NULL);
gboolean recompute_localeinfo = FALSE; gboolean recompute_localeinfo = FALSE;
@ -595,9 +589,7 @@ g_date_prepare_to_parse (const gchar *str, GDateParseTokens *pt)
g_date_clear (&d, 1); /* clear for scratch use */ g_date_clear (&d, 1); /* clear for scratch use */
if ( (current_locale == NULL) || (strcmp (locale, current_locale) != 0) ) if ( (current_locale == NULL) || (strcmp (locale, current_locale) != 0) )
{ recompute_localeinfo = TRUE; /* Uh, there used to be a reason for the temporary */
recompute_localeinfo = TRUE; /* Uh, there used to be a reason for the temporary */
}
if (recompute_localeinfo) if (recompute_localeinfo)
{ {
@ -814,9 +806,7 @@ g_date_set_parse (GDate *d,
else if (pt.num_ints == 2) else if (pt.num_ints == 2)
{ {
if (m == G_DATE_BAD_MONTH && pt.month != G_DATE_BAD_MONTH) if (m == G_DATE_BAD_MONTH && pt.month != G_DATE_BAD_MONTH)
{ m = pt.month;
m = pt.month;
}
} }
} }
else if (pt.num_ints == 1) else if (pt.num_ints == 1)
@ -934,8 +924,8 @@ g_date_set_time_t (GDate *date,
* @Deprecated:2.10: Use g_date_set_time_t() instead. * @Deprecated:2.10: Use g_date_set_time_t() instead.
*/ */
void void
g_date_set_time (GDate *date, g_date_set_time (GDate *date,
GTime time_) GTime time_)
{ {
g_date_set_time_t (date, (time_t) time_); g_date_set_time_t (date, (time_t) time_);
} }
@ -977,8 +967,8 @@ g_date_set_month (GDate *d,
} }
void void
g_date_set_day (GDate *d, g_date_set_day (GDate *d,
GDateDay day) GDateDay day)
{ {
g_return_if_fail (d != NULL); g_return_if_fail (d != NULL);
g_return_if_fail (g_date_valid_day (day)); g_return_if_fail (g_date_valid_day (day));
@ -1013,10 +1003,10 @@ g_date_set_year (GDate *d,
} }
void void
g_date_set_dmy (GDate *d, g_date_set_dmy (GDate *d,
GDateDay day, GDateDay day,
GDateMonth m, GDateMonth m,
GDateYear y) GDateYear y)
{ {
g_return_if_fail (d != NULL); g_return_if_fail (d != NULL);
g_return_if_fail (g_date_valid_dmy (day, m, y)); g_return_if_fail (g_date_valid_dmy (day, m, y));
@ -1031,7 +1021,8 @@ g_date_set_dmy (GDate *d,
} }
void void
g_date_set_julian (GDate *d, guint32 j) g_date_set_julian (GDate *d,
guint32 j)
{ {
g_return_if_fail (d != NULL); g_return_if_fail (d != NULL);
g_return_if_fail (g_date_valid_julian (j)); g_return_if_fail (g_date_valid_julian (j));
@ -1048,9 +1039,8 @@ g_date_is_first_of_month (const GDate *d)
g_return_val_if_fail (g_date_valid (d), FALSE); g_return_val_if_fail (g_date_valid (d), FALSE);
if (!d->dmy) if (!d->dmy)
{ g_date_update_dmy (d);
g_date_update_dmy (d);
}
g_return_val_if_fail (d->dmy, FALSE); g_return_val_if_fail (d->dmy, FALSE);
if (d->day == 1) return TRUE; if (d->day == 1) return TRUE;
@ -1065,9 +1055,8 @@ g_date_is_last_of_month (const GDate *d)
g_return_val_if_fail (g_date_valid (d), FALSE); g_return_val_if_fail (g_date_valid (d), FALSE);
if (!d->dmy) if (!d->dmy)
{ g_date_update_dmy (d);
g_date_update_dmy (d);
}
g_return_val_if_fail (d->dmy, FALSE); g_return_val_if_fail (d->dmy, FALSE);
index = g_date_is_leap_year (d->year) ? 1 : 0; index = g_date_is_leap_year (d->year) ? 1 : 0;
@ -1077,14 +1066,14 @@ g_date_is_last_of_month (const GDate *d)
} }
void void
g_date_add_days (GDate *d, guint ndays) g_date_add_days (GDate *d,
guint ndays)
{ {
g_return_if_fail (g_date_valid (d)); g_return_if_fail (g_date_valid (d));
if (!d->julian) if (!d->julian)
{ g_date_update_julian (d);
g_date_update_julian (d);
}
g_return_if_fail (d->julian); g_return_if_fail (d->julian);
d->julian_days += ndays; d->julian_days += ndays;
@ -1092,14 +1081,14 @@ g_date_add_days (GDate *d, guint ndays)
} }
void void
g_date_subtract_days (GDate *d, guint ndays) g_date_subtract_days (GDate *d,
guint ndays)
{ {
g_return_if_fail (g_date_valid (d)); g_return_if_fail (g_date_valid (d));
if (!d->julian) if (!d->julian)
{ g_date_update_julian (d);
g_date_update_julian (d);
}
g_return_if_fail (d->julian); g_return_if_fail (d->julian);
g_return_if_fail (d->julian_days > ndays); g_return_if_fail (d->julian_days > ndays);
@ -1108,8 +1097,8 @@ g_date_subtract_days (GDate *d, guint ndays)
} }
void void
g_date_add_months (GDate *d, g_date_add_months (GDate *d,
guint nmonths) guint nmonths)
{ {
guint years, months; guint years, months;
gint index; gint index;
@ -1117,9 +1106,8 @@ g_date_add_months (GDate *d,
g_return_if_fail (g_date_valid (d)); g_return_if_fail (g_date_valid (d));
if (!d->dmy) if (!d->dmy)
{ g_date_update_dmy (d);
g_date_update_dmy (d);
}
g_return_if_fail (d->dmy); g_return_if_fail (d->dmy);
nmonths += d->month - 1; nmonths += d->month - 1;
@ -1141,8 +1129,8 @@ g_date_add_months (GDate *d,
} }
void void
g_date_subtract_months (GDate *d, g_date_subtract_months (GDate *d,
guint nmonths) guint nmonths)
{ {
guint years, months; guint years, months;
gint index; gint index;
@ -1150,9 +1138,8 @@ g_date_subtract_months (GDate *d,
g_return_if_fail (g_date_valid (d)); g_return_if_fail (g_date_valid (d));
if (!d->dmy) if (!d->dmy)
{ g_date_update_dmy (d);
g_date_update_dmy (d);
}
g_return_if_fail (d->dmy); g_return_if_fail (d->dmy);
years = nmonths/12; years = nmonths/12;
@ -1181,15 +1168,14 @@ g_date_subtract_months (GDate *d,
} }
void void
g_date_add_years (GDate *d, g_date_add_years (GDate *d,
guint nyears) guint nyears)
{ {
g_return_if_fail (g_date_valid (d)); g_return_if_fail (g_date_valid (d));
if (!d->dmy) if (!d->dmy)
{ g_date_update_dmy (d);
g_date_update_dmy (d);
}
g_return_if_fail (d->dmy); g_return_if_fail (d->dmy);
d->year += nyears; d->year += nyears;
@ -1197,24 +1183,21 @@ g_date_add_years (GDate *d,
if (d->month == 2 && d->day == 29) if (d->month == 2 && d->day == 29)
{ {
if (!g_date_is_leap_year (d->year)) if (!g_date_is_leap_year (d->year))
{ d->day = 28;
d->day = 28;
}
} }
d->julian = FALSE; d->julian = FALSE;
} }
void void
g_date_subtract_years (GDate *d, g_date_subtract_years (GDate *d,
guint nyears) guint nyears)
{ {
g_return_if_fail (g_date_valid (d)); g_return_if_fail (g_date_valid (d));
if (!d->dmy) if (!d->dmy)
{ g_date_update_dmy (d);
g_date_update_dmy (d);
}
g_return_if_fail (d->dmy); g_return_if_fail (d->dmy);
g_return_if_fail (d->year > nyears); g_return_if_fail (d->year > nyears);
@ -1223,17 +1206,14 @@ g_date_subtract_years (GDate *d,
if (d->month == 2 && d->day == 29) if (d->month == 2 && d->day == 29)
{ {
if (!g_date_is_leap_year (d->year)) if (!g_date_is_leap_year (d->year))
{ d->day = 28;
d->day = 28;
}
} }
d->julian = FALSE; d->julian = FALSE;
} }
gboolean gboolean
g_date_is_leap_year (GDateYear year) g_date_is_leap_year (GDateYear year)
{ {
g_return_val_if_fail (g_date_valid_year (year), FALSE); g_return_val_if_fail (g_date_valid_year (year), FALSE);
@ -1256,7 +1236,7 @@ g_date_get_days_in_month (GDateMonth month,
} }
guint8 guint8
g_date_get_monday_weeks_in_year (GDateYear year) g_date_get_monday_weeks_in_year (GDateYear year)
{ {
GDate d; GDate d;
@ -1278,7 +1258,7 @@ g_date_get_monday_weeks_in_year (GDateYear year)
} }
guint8 guint8
g_date_get_sunday_weeks_in_year (GDateYear year) g_date_get_sunday_weeks_in_year (GDateYear year)
{ {
GDate d; GDate d;
@ -1312,7 +1292,6 @@ g_date_compare (const GDate *lhs,
while (TRUE) while (TRUE)
{ {
if (lhs->julian && rhs->julian) if (lhs->julian && rhs->julian)
{ {
if (lhs->julian_days < rhs->julian_days) return -1; if (lhs->julian_days < rhs->julian_days) return -1;
@ -1360,9 +1339,8 @@ g_date_to_struct_tm (const GDate *d,
g_return_if_fail (tm != NULL); g_return_if_fail (tm != NULL);
if (!d->dmy) if (!d->dmy)
{ g_date_update_dmy (d);
g_date_update_dmy (d);
}
g_return_if_fail (d->dmy); g_return_if_fail (d->dmy);
/* zero all the irrelevant fields to be sure they're valid */ /* zero all the irrelevant fields to be sure they're valid */
@ -1389,7 +1367,7 @@ g_date_to_struct_tm (const GDate *d,
} }
void void
g_date_clamp (GDate *date, g_date_clamp (GDate *date,
const GDate *min_date, const GDate *min_date,
const GDate *max_date) const GDate *max_date)
{ {
@ -1397,8 +1375,10 @@ g_date_clamp (GDate *date,
if (min_date != NULL) if (min_date != NULL)
g_return_if_fail (g_date_valid (min_date)); g_return_if_fail (g_date_valid (min_date));
if (max_date != NULL) if (max_date != NULL)
g_return_if_fail (g_date_valid (max_date)); g_return_if_fail (g_date_valid (max_date));
if (min_date != NULL && max_date != NULL) if (min_date != NULL && max_date != NULL)
g_return_if_fail (g_date_compare (min_date, max_date) <= 0); g_return_if_fail (g_date_compare (min_date, max_date) <= 0);