[glib/wip/date-time-fixes: 2/5] datetime: Allow setting fractionary seconds in new_full()



commit cca2c474281077d72d0e2968b828fd5cdbe5ba59
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Wed Sep 15 10:05:41 2010 +0100

    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

 glib/gdatetime.c       |    6 +++---
 glib/gdatetime.h       |    2 +-
 glib/tests/gdatetime.c |    6 +++++-
 3 files changed, 9 insertions(+), 5 deletions(-)
---
diff --git a/glib/gdatetime.c b/glib/gdatetime.c
index a51f28f..634f73d 100644
--- a/glib/gdatetime.c
+++ b/glib/gdatetime.c
@@ -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);
diff --git a/glib/gdatetime.h b/glib/gdatetime.h
index 4a7bf8f..53d62d9 100644
--- a/glib/gdatetime.h
+++ b/glib/gdatetime.h
@@ -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);
diff --git a/glib/tests/gdatetime.c b/glib/tests/gdatetime.c
index 1c04459..fe6808e 100644
--- a/glib/tests/gdatetime.c
+++ b/glib/tests/gdatetime.c
@@ -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



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]