summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Santos <thiago.sousa.santos@collabora.co.uk>2010-10-12 15:13:48 -0300
committerThiago Santos <thiago.sousa.santos@collabora.co.uk>2010-10-13 11:48:57 -0300
commite9312870e5881295b52853825e7dab95a9c34b6e (patch)
treea10f368a3d4fa18a131fe7a374fcc642ae710aac
parent0d3c623b4b7c1e5ee44e5ad67c59a724b0d8efc6 (diff)
datetime: Use seconds as double
Use seconds as double to make API similar to glib's gdatetime. Also move timezone parameter to the first position, just like glib's. https://bugzilla.gnome.org/show_bug.cgi?id=628408
-rw-r--r--gst/gstdatetime.c38
-rw-r--r--gst/gstdatetime.h10
-rw-r--r--gst/gstvalue.c6
-rw-r--r--tests/check/gst/gstdatetime.c17
-rw-r--r--tests/check/gst/gstvalue.c6
5 files changed, 38 insertions, 39 deletions
diff --git a/gst/gstdatetime.c b/gst/gstdatetime.c
index ad83349887..97ddc6026e 100644
--- a/gst/gstdatetime.c
+++ b/gst/gstdatetime.c
@@ -25,6 +25,7 @@
#include "gst_private.h"
#include "gstdatetime.h"
#include <glib.h>
+#include <math.h>
/**
* SECTION:gstdatetime
@@ -180,6 +181,7 @@
/**
* gst_date_time_new:
+ * @tzoffset: Offset from UTC in hours.
* @year: the gregorian year
* @month: the gregorian month
* @day: the day of the gregorian month
@@ -187,7 +189,6 @@
* @minute: the minute of the hour
* @second: the second of the minute
* @microsecond: the microsecond of the second
- * @tzoffset: Offset from UTC in hours.
*
* Creates a new #GstDateTime using the date and times in the gregorian calendar
* in the supplied timezone.
@@ -422,20 +423,19 @@ gst_date_time_new_from_unix_epoch (gint64 secs)
memcpy (&tm, localtime (&tt), sizeof (struct tm));
#endif
- dt = gst_date_time_new (tm.tm_year + 1900,
- tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, 0, 0);
+ dt = gst_date_time_new (0, tm.tm_year + 1900,
+ tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
gst_date_time_set_local_timezone (dt);
return dt;
}
GstDateTime *
gst_date_time_new_local_time (gint year, gint month, gint day, gint hour,
- gint minute, gint second, gint microsecond)
+ gint minute, gdouble seconds)
{
GstDateTime *dt;
- dt = gst_date_time_new (year, month, day, hour, minute, second, microsecond,
- 0);
+ dt = gst_date_time_new (0, year, month, day, hour, minute, seconds);
gst_date_time_set_local_timezone (dt);
@@ -443,24 +443,25 @@ gst_date_time_new_local_time (gint year, gint month, gint day, gint hour,
}
GstDateTime *
-gst_date_time_new (gint year, gint month, gint day, gint hour,
- gint minute, gint second, gint microsecond, gfloat tzoffset)
+gst_date_time_new (gfloat tzoffset, gint year, gint month, gint day, gint hour,
+ gint minute, gdouble seconds)
{
GstDateTime *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 (microsecond >= 0 && microsecond < 1000000, NULL);
+ g_return_val_if_fail (seconds >= 0 && seconds < 60, NULL);
+ g_return_val_if_fail (tzoffset >= -12.0 && tzoffset <= 12.0, NULL);
if (!(dt = gst_date_time_new_from_date (year, month, day)))
return NULL;
dt->usec = (hour * GST_DATE_TIME_USEC_PER_HOUR)
+ (minute * GST_DATE_TIME_USEC_PER_MINUTE)
- + (second * GST_DATE_TIME_USEC_PER_SECOND)
- + microsecond;
- dt->tzoffset = (gint) (60 * tzoffset);
+ + (guint64) (floor (seconds * GST_DATE_TIME_USEC_PER_SECOND + 0.5));
+
+ /* we store in minutes */
+ dt->tzoffset = (gint) tzoffset *60.0;
return dt;
}
@@ -663,10 +664,10 @@ gst_date_time_new_from_unix_epoch (gint64 secs)
GstDateTime *
gst_date_time_new_local_time (gint year, gint month, gint day, gint hour,
- gint minute, gint second, gint microsecond)
+ gint minute, gdouble seconds)
{
return gst_date_time_new_from_gdatetime (g_date_time_new_local (year, month,
- day, hour, minute, second + (microsecond / 1000000.0)));
+ day, hour, minute, seconds));
}
GstDateTime *
@@ -690,8 +691,8 @@ priv_gst_date_time_compare (gconstpointer dt1, gconstpointer dt2)
}
GstDateTime *
-gst_date_time_new (gint year, gint month, gint day, gint hour, gint minute,
- gint second, gint microsecond, gfloat tzoffset)
+gst_date_time_new (gfloat tzoffset, gint year, gint month, gint day, gint hour,
+ gint minute, gdouble seconds)
{
gchar buf[6];
GTimeZone *tz;
@@ -705,8 +706,7 @@ gst_date_time_new (gint year, gint month, gint day, gint hour, gint minute,
tzminute);
tz = g_time_zone_new (buf);
- dt = g_date_time_new (tz, year, month, day, hour, minute,
- second + (microsecond / 1000000.0));
+ dt = g_date_time_new (tz, year, month, day, hour, minute, seconds);
g_time_zone_unref (tz);
return gst_date_time_new_from_gdatetime (dt);
}
diff --git a/gst/gstdatetime.h b/gst/gstdatetime.h
index 5317a18a7a..957faaefe7 100644
--- a/gst/gstdatetime.h
+++ b/gst/gstdatetime.h
@@ -49,14 +49,12 @@ GstDateTime *gst_date_time_new_from_unix_epoch (gint64 secs);
GstDateTime *gst_date_time_new_local_time (gint year, gint month,
gint day, gint hour,
gint minute,
- gint second,
- gint microsecond);
-GstDateTime *gst_date_time_new (gint year, gint month,
+ gdouble seconds);
+GstDateTime *gst_date_time_new (gfloat tzoffset,
+ gint year, gint month,
gint day, gint hour,
gint minute,
- gint second,
- gint microsecond,
- gfloat tzoffset);
+ gdouble seconds);
GstDateTime *gst_date_time_new_now_local_time (void);
GstDateTime *gst_date_time_new_now_utc (void);
diff --git a/gst/gstvalue.c b/gst/gstvalue.c
index 883356a751..ca449bc45a 100644
--- a/gst/gstvalue.c
+++ b/gst/gstvalue.c
@@ -4376,7 +4376,7 @@ static gchar *
gst_value_serialize_date_time (const GValue * val)
{
GstDateTime *date = (GstDateTime *) g_value_get_boxed (val);
- gint offset;
+ gfloat offset;
gint tzhour, tzminute;
if (date == NULL)
@@ -4417,8 +4417,8 @@ gst_value_deserialize_date_time (GValue * dest, const gchar * s)
} else
return FALSE;
- g_value_take_boxed (dest, gst_date_time_new (year, month, day, hour,
- minute, second, usecond, tzoffset));
+ g_value_take_boxed (dest, gst_date_time_new (tzoffset, year, month, day, hour,
+ minute, second + (usecond / 1000000.0)));
return TRUE;
}
diff --git a/tests/check/gst/gstdatetime.c b/tests/check/gst/gstdatetime.c
index 8fea42adca..74e2291afb 100644
--- a/tests/check/gst/gstdatetime.c
+++ b/tests/check/gst/gstdatetime.c
@@ -111,19 +111,19 @@ GST_START_TEST (test_GstDateTime_get_hour)
{
GstDateTime *dt;
- dt = gst_date_time_new (2009, 10, 19, 15, 13, 11, 0, 0);
+ dt = gst_date_time_new (0, 2009, 10, 19, 15, 13, 11);
assert_equals_int (15, gst_date_time_get_hour (dt));
gst_date_time_unref (dt);
- dt = gst_date_time_new (100, 10, 19, 1, 0, 0, 0, 0);
+ dt = gst_date_time_new (0, 100, 10, 19, 1, 0, 0);
assert_equals_int (1, gst_date_time_get_hour (dt));
gst_date_time_unref (dt);
- dt = gst_date_time_new (100, 10, 19, 0, 0, 0, 0, 0);
+ dt = gst_date_time_new (0, 100, 10, 19, 0, 0, 0);
assert_equals_int (0, gst_date_time_get_hour (dt));
gst_date_time_unref (dt);
- dt = gst_date_time_new (100, 10, 1, 23, 59, 59, 0, 0);
+ dt = gst_date_time_new (0, 100, 10, 1, 23, 59, 59);
assert_equals_int (23, gst_date_time_get_hour (dt));
gst_date_time_unref (dt);
}
@@ -136,7 +136,8 @@ GST_START_TEST (test_GstDateTime_get_microsecond)
GstDateTime *dt;
g_get_current_time (&tv);
- dt = gst_date_time_new (2010, 7, 15, 11, 12, 13, tv.tv_usec, 0);
+ dt = gst_date_time_new (0, 2010, 7, 15, 11, 12,
+ 13 + (tv.tv_usec / 1000000.0));
assert_equals_int (tv.tv_usec, gst_date_time_get_microsecond (dt));
gst_date_time_unref (dt);
}
@@ -147,7 +148,7 @@ GST_START_TEST (test_GstDateTime_get_minute)
{
GstDateTime *dt;
- dt = gst_date_time_new (2009, 12, 1, 1, 31, 0, 0, 0);
+ dt = gst_date_time_new (0, 2009, 12, 1, 1, 31, 0);
assert_equals_int (31, gst_date_time_get_minute (dt));
gst_date_time_unref (dt);
}
@@ -158,7 +159,7 @@ GST_START_TEST (test_GstDateTime_get_second)
{
GstDateTime *dt;
- dt = gst_date_time_new (2009, 12, 1, 1, 31, 44, 0, 0);
+ dt = gst_date_time_new (0, 2009, 12, 1, 1, 31, 44);
assert_equals_int (44, gst_date_time_get_second (dt));
gst_date_time_unref (dt);
}
@@ -169,7 +170,7 @@ GST_START_TEST (test_GstDateTime_new_full)
{
GstDateTime *dt;
- dt = gst_date_time_new (2009, 12, 11, 12, 11, 10, 1234, 0);
+ dt = gst_date_time_new (0, 2009, 12, 11, 12, 11, 10.001234);
assert_equals_int (2009, gst_date_time_get_year (dt));
assert_equals_int (12, gst_date_time_get_month (dt));
assert_equals_int (11, gst_date_time_get_day (dt));
diff --git a/tests/check/gst/gstvalue.c b/tests/check/gst/gstvalue.c
index ae0d1169da..4d981e2f7d 100644
--- a/tests/check/gst/gstvalue.c
+++ b/tests/check/gst/gstvalue.c
@@ -2010,7 +2010,7 @@ GST_START_TEST (test_date_time)
gchar *str;
/* utc timezone */
- datetime = gst_date_time_new (2010, 6, 23, 7, 40, 10, 0, 0);
+ datetime = gst_date_time_new (0, 2010, 6, 23, 7, 40, 10);
s = gst_structure_new ("media/x-type", "SOME_DATE_TIME_TAG",
GST_TYPE_DATE_TIME, datetime, NULL);
@@ -2066,7 +2066,7 @@ GST_START_TEST (test_date_time)
str = NULL;
/* with timezone */
- datetime = gst_date_time_new (2010, 6, 23, 7, 40, 10, 1, -3.0);
+ datetime = gst_date_time_new (-3.0, 2010, 6, 23, 7, 40, 10.000001);
s = gst_structure_new ("media/x-type", "SOME_DATE_TIME_TAG",
GST_TYPE_DATE_TIME, datetime, NULL);
@@ -2122,7 +2122,7 @@ GST_START_TEST (test_date_time)
str = NULL;
/* with positive timezone */
- datetime = gst_date_time_new (2010, 6, 23, 7, 40, 10, 1, 2);
+ datetime = gst_date_time_new (2.0, 2010, 6, 23, 7, 40, 10.000001);
s = gst_structure_new ("media/x-type", "SOME_DATE_TIME_TAG",
GST_TYPE_DATE_TIME, datetime, NULL);