*/
/**
- * gst_date_time_new_from_unix_epoch:
+ * gst_date_time_new_from_unix_epoch_local_time:
* @secs: seconds from the Unix epoch
*
* Creates a new #GstDateTime using the time since Jan 1, 1970 specified by
*/
/**
+ * gst_date_time_new_from_unix_epoch_utc:
+ * @secs: seconds from the Unix epoch
+ *
+ * Creates a new #GstDateTime using the time since Jan 1, 1970 specified by
+ * @secs. The #GstDateTime is in the UTC timezone.
+ *
+ * Return value: the newly created #GstDateTime
+ *
+ * Since: 0.10.31
+ */
+
+/**
* gst_date_time_new_local_time:
* @year: the gregorian year
* @month: the gregorian month
}
GstDateTime *
-gst_date_time_new_from_unix_epoch (gint64 secs)
+gst_date_time_new_from_unix_epoch_local_time (gint64 secs)
{
GstDateTime *dt;
struct tm tm;
}
GstDateTime *
+gst_date_time_new_from_unix_epoch_utc (gint64 secs)
+{
+ GstDateTime *dt;
+ struct tm tm;
+ time_t tt;
+
+ memset (&tm, 0, sizeof (tm));
+ tt = (time_t) secs;
+
+#ifdef HAVE_GMTIME_R
+ gmtime_r (&tt, &tm);
+#else
+ memcpy (&tm, gmtime (&tt), sizeof (struct tm));
+#endif
+
+ 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);
+ return dt;
+}
+
+GstDateTime *
gst_date_time_new_local_time (gint year, gint month, gint day, gint hour,
gint minute, gdouble seconds)
{
GTimeVal tv;
g_get_current_time (&tv);
- datetime = gst_date_time_new_from_unix_epoch (tv.tv_sec);
+ datetime = gst_date_time_new_from_unix_epoch_local_time (tv.tv_sec);
datetime->usec += tv.tv_usec;
gst_date_time_set_local_timezone (datetime);
return datetime;
}
GstDateTime *
-gst_date_time_new_from_unix_epoch (gint64 secs)
+gst_date_time_new_from_unix_epoch_local_time (gint64 secs)
{
return
gst_date_time_new_from_gdatetime (g_date_time_new_from_unix_local (secs));
}
GstDateTime *
+gst_date_time_new_from_unix_epoch_utc (gint64 secs)
+{
+ return
+ gst_date_time_new_from_gdatetime (g_date_time_new_from_unix_utc (secs));
+}
+
+GstDateTime *
gst_date_time_new_local_time (gint year, gint month, gint day, gint hour,
gint minute, gdouble seconds)
{
memset (&tm, 0, sizeof (tm));
t = time (NULL);
+#ifdef HAVE_LOCALTIME_R
localtime_r (&t, &tm);
+#else
+ memcpy (&tm, localtime (&t), sizeof (struct tm));
+#endif
dt = gst_date_time_new_now_local_time ();
assert_equals_int (gst_date_time_get_year (dt), 1900 + tm.tm_year);
assert_equals_int (gst_date_time_get_month (dt), 1 + tm.tm_mon);
GST_END_TEST;
-GST_START_TEST (test_GstDateTime_new_from_unix_epoch)
+GST_START_TEST (test_GstDateTime_new_from_unix_epoch_local_time)
{
GstDateTime *dt;
struct tm tm;
memset (&tm, 0, sizeof (tm));
t = time (NULL);
+#ifdef HAVE_LOCALTIME_R
localtime_r (&t, &tm);
- dt = gst_date_time_new_from_unix_epoch (t);
+#else
+ memcpy (&tm, localtime (&t), sizeof (struct tm));
+#endif
+ dt = gst_date_time_new_from_unix_epoch_local_time (t);
assert_equals_int (gst_date_time_get_year (dt), 1900 + tm.tm_year);
assert_equals_int (gst_date_time_get_month (dt), 1 + tm.tm_mon);
assert_equals_int (gst_date_time_get_day (dt), tm.tm_mday);
tm.tm_min = 0;
tm.tm_sec = 0;
t = mktime (&tm);
- dt = gst_date_time_new_from_unix_epoch (t);
+ dt = gst_date_time_new_from_unix_epoch_local_time (t);
assert_equals_int (gst_date_time_get_year (dt), 1970);
assert_equals_int (gst_date_time_get_month (dt), 1);
assert_equals_int (gst_date_time_get_day (dt), 1);
GST_END_TEST;
+
+GST_START_TEST (test_GstDateTime_new_from_unix_epoch_utc)
+{
+ GstDateTime *dt;
+ struct tm tm;
+ time_t t;
+
+ memset (&tm, 0, sizeof (tm));
+ t = time (NULL);
+#ifdef HAVE_GMTIME_R
+ gmtime_r (&t, &tm);
+#else
+ memcpy (&tm, gmtime (&t), sizeof (struct tm));
+#endif
+ dt = gst_date_time_new_from_unix_epoch_utc (t);
+ assert_equals_int (gst_date_time_get_year (dt), 1900 + tm.tm_year);
+ assert_equals_int (gst_date_time_get_month (dt), 1 + tm.tm_mon);
+ assert_equals_int (gst_date_time_get_day (dt), tm.tm_mday);
+ assert_equals_int (gst_date_time_get_hour (dt), tm.tm_hour);
+ assert_equals_int (gst_date_time_get_minute (dt), tm.tm_min);
+ assert_equals_int (gst_date_time_get_second (dt), tm.tm_sec);
+ assert_equals_int (gst_date_time_get_time_zone_offset (dt), 0);
+ gst_date_time_unref (dt);
+}
+
+GST_END_TEST;
+
GST_START_TEST (test_GstDateTime_get_dmy)
{
GstDateTime *dt;
struct tm tt;
t = time (NULL);
+#ifdef HAVE_LOCALTIME_R
localtime_r (&t, &tt);
- dt = gst_date_time_new_from_unix_epoch (t);
+#else
+ memcpy (&tt, localtime (&t), sizeof (struct tm));
+#endif
+ dt = gst_date_time_new_from_unix_epoch_local_time (t);
assert_equals_int (gst_date_time_get_year (dt), tt.tm_year + 1900);
assert_equals_int (gst_date_time_get_month (dt), tt.tm_mon + 1);
assert_equals_int (gst_date_time_get_day (dt), tt.tm_mday);
struct tm tm;
t = time (NULL);
+#ifdef HAVE_GMTIME_R
gmtime_r (&t, &tm);
+#else
+ memcpy (&tm, gmtime (&t), sizeof (struct tm));
+#endif
dt = gst_date_time_new_now_utc ();
assert_equals_int (tm.tm_year + 1900, gst_date_time_get_year (dt));
assert_equals_int (tm.tm_mon + 1, gst_date_time_get_month (dt));
t = time (NULL);
memset (&tm, 0, sizeof (tm));
+#ifdef HAVE_LOCALTIME_R
localtime_r (&t, &tm);
+#else
+ memcpy (&tm, localtime (&t), sizeof (struct tm));
+#endif
dt = gst_date_time_new_now_local_time ();
ts = gst_date_time_get_time_zone_offset (dt);
tcase_add_test (tc_chain, test_GstDateTime_get_minute);
tcase_add_test (tc_chain, test_GstDateTime_get_second);
tcase_add_test (tc_chain, test_GstDateTime_get_utc_offset);
- tcase_add_test (tc_chain, test_GstDateTime_new_from_unix_epoch);
+ tcase_add_test (tc_chain, test_GstDateTime_new_from_unix_epoch_local_time);
+ tcase_add_test (tc_chain, test_GstDateTime_new_from_unix_epoch_utc);
tcase_add_test (tc_chain, test_GstDateTime_new_full);
tcase_add_test (tc_chain, test_GstDateTime_now);
tcase_add_test (tc_chain, test_GstDateTime_utc_now);