datetime: Allow setting fractionary seconds in new_full()

Otherwise we'll have to do:

  dt = g_date_time_new_full (Y, M, D, h, m, s, tz);
  tmp = g_date_time_add_usec (dt, usec);
  g_date_time_unref (dt);
  dt = tmp;

With its additional allocations.

https://bugzilla.gnome.org/show_bug.cgi?id=50076
This commit is contained in:
Emmanuele Bassi 2010-09-15 10:05:41 +01:00 committed by Ryan Lortie
parent 67f1e52ce2
commit 0746f74036
3 changed files with 9 additions and 5 deletions

View File

@ -2111,7 +2111,7 @@ g_date_time_new_from_timeval (GTimeVal *tv)
* @day: the day of the Gregorian month
* @hour: the hour of the day
* @minute: the minute of the hour
* @second: the second of the minute
* @second: the second of the minute, with eventual fractionary parts
* @time_zone: (allow-none): a #GTimeZone, or %NULL for UTC
*
* Creates a new #GDateTime using the date and times in the Gregorian
@ -2130,14 +2130,14 @@ g_date_time_new_full (gint year,
gint day,
gint hour,
gint minute,
gint second,
gdouble second,
const GTimeZone *time_zone)
{
GDateTime *dt;
g_return_val_if_fail (hour >= 0 && hour < 24, NULL);
g_return_val_if_fail (minute >= 0 && minute < 60, NULL);
g_return_val_if_fail (second >= 0 && second <= 60, NULL);
g_return_val_if_fail (second >= 0.0 && second <= 60.0, NULL);
dt = g_date_time_new ();
dt->days = date_to_proleptic_gregorian (year, month, day);

View File

@ -116,7 +116,7 @@ GDateTime * g_date_time_new_full (gint year,
gint day,
gint hour,
gint minute,
gint second,
gdouble second,
const GTimeZone *time_zone);
GDateTime * g_date_time_ref (GDateTime *datetime);

View File

@ -188,7 +188,6 @@ test_GDateTime_compare (void)
dt2 = g_date_time_new_full (2000, 1, 1, 0, 0, 0, NULL);
g_assert_cmpint (0, ==, g_date_time_compare (dt1, dt2));
g_date_time_unref (dt2);
g_date_time_unref (dt1);
}
@ -391,6 +390,11 @@ test_GDateTime_get_millisecond (void)
dt = g_date_time_new_from_timeval (&tv);
g_assert_cmpint ((tv.tv_usec / 1000), ==, g_date_time_get_millisecond (dt));
g_date_time_unref (dt);
dt = g_date_time_new_full (2010, 9, 15, 12, 0, 0.1234, NULL);
g_assert_cmpint (123, ==, g_date_time_get_millisecond (dt));
g_assert_cmpint (123400, ==, g_date_time_get_microsecond (dt));
g_date_time_unref (dt);
}
static void