/* for GstToc */
#include "gsttoc.h"
+#include "gstdatetime.h"
+
G_BEGIN_DECLS
/* used by gstparse.c and grammar.y */
((c) == '.'))
/* This is only meant for internal uses */
-gint priv_gst_date_time_compare (gconstpointer dt1, gconstpointer dt2);
+gint __gst_date_time_compare (const GstDateTime * dt1, const GstDateTime * dt2);
#ifndef GST_DISABLE_REGISTRY
/* Secret variable to initialise gst without registry cache */
#include "glib-compat-private.h"
#include "gst_private.h"
#include "gstdatetime.h"
+#include "gstvalue.h"
#include <glib.h>
#include <math.h>
#include <stdio.h>
GST_DATE_TIME_FIELDS_YMD, /* have year, month and day */
GST_DATE_TIME_FIELDS_YMD_HM,
GST_DATE_TIME_FIELDS_YMD_HMS
+ /* Note: if we ever add more granularity here, e.g. for microsecs,
+ * the compare function will need updating */
} GstDateTimeFields;
struct _GstDateTime
}
gint
-priv_gst_date_time_compare (gconstpointer dt1, gconstpointer dt2)
-{
- const GstDateTime *datetime1 = dt1;
- const GstDateTime *datetime2 = dt2;
- return g_date_time_compare (datetime1->datetime, datetime2->datetime);
+__gst_date_time_compare (const GstDateTime * dt1, const GstDateTime * dt2)
+{
+ gint64 diff;
+
+ /* we assume here that GST_DATE_TIME_FIELDS_YMD_HMS is the highest
+ * resolution, and ignore microsecond differences on purpose for now */
+ if (dt1->fields != dt2->fields)
+ return GST_VALUE_UNORDERED;
+
+ /* This will round down to nearest second, which is what we want. We're
+ * not comparing microseconds on purpose here, since we're not
+ * serialising them when doing new_utc_now() + to_string() */
+ diff =
+ g_date_time_to_unix (dt1->datetime) - g_date_time_to_unix (dt2->datetime);
+ if (diff < 0)
+ return GST_VALUE_LESS_THAN;
+ else if (diff > 0)
+ return GST_VALUE_GREATER_THAN;
+ else
+ return GST_VALUE_EQUAL;
}
/**
{
const GstDateTime *date1 = (const GstDateTime *) g_value_get_boxed (value1);
const GstDateTime *date2 = (const GstDateTime *) g_value_get_boxed (value2);
- gint ret;
if (date1 == date2)
return GST_VALUE_EQUAL;
return GST_VALUE_LESS_THAN;
}
- ret = priv_gst_date_time_compare (date1, date2);
-
- if (ret == 0)
- return GST_VALUE_EQUAL;
- else if (ret < 0)
- return GST_VALUE_LESS_THAN;
- else
- return GST_VALUE_GREATER_THAN;
+ /* returns GST_VALUE_* */
+ return __gst_date_time_compare (date1, date2);
}
static gchar *