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);
@ -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,11 +806,9 @@ 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)
{ {
if (pt.month != G_DATE_BAD_MONTH) if (pt.month != G_DATE_BAD_MONTH)
@ -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);
@ -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;
@ -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;
@ -1187,9 +1174,8 @@ g_date_add_years (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);
d->year += nyears; d->year += nyears;
@ -1197,10 +1183,8 @@ 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;
} }
@ -1212,9 +1196,8 @@ g_date_subtract_years (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);
g_return_if_fail (d->year > nyears); g_return_if_fail (d->year > nyears);
@ -1223,15 +1206,12 @@ 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)
{ {
@ -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 */
@ -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);