After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 628408 - Use GDateTime that has been released
Use GDateTime that has been released
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gstreamer (core)
git master
Other Linux
: Normal blocker
: 0.10.31
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2010-08-31 11:04 UTC by Thiago Sousa Santos
Modified: 2012-08-02 09:14 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
datetime: Use GDateTime if available (4.85 KB, patch)
2010-09-29 17:57 UTC, Thiago Sousa Santos
needs-work Details | Review
glib-private: Add protection include macro (849 bytes, patch)
2010-10-11 21:17 UTC, Thiago Sousa Santos
committed Details | Review
datetime: Use GDateTime if available (6.94 KB, patch)
2010-10-11 21:17 UTC, Thiago Sousa Santos
committed Details | Review
gstdatetime: Move doc outside the ifdefs (12.69 KB, patch)
2010-10-11 21:17 UTC, Thiago Sousa Santos
accepted-commit_now Details | Review
gstdatetime: Move doc outside the ifdefs (13.14 KB, patch)
2010-10-12 23:21 UTC, Thiago Sousa Santos
committed Details | Review
datetime: Use seconds as double (9.17 KB, patch)
2010-10-12 23:22 UTC, Thiago Sousa Santos
none Details | Review
datetime: Handle timezone offset in usecs (9.00 KB, patch)
2010-10-12 23:23 UTC, Thiago Sousa Santos
none Details | Review
datetime: Use seconds as double (9.47 KB, patch)
2010-10-13 00:03 UTC, Thiago Sousa Santos
reviewed Details | Review
datetime: Handle timezone offset in usecs (8.60 KB, patch)
2010-10-13 00:04 UTC, Thiago Sousa Santos
rejected Details | Review

Description Thiago Sousa Santos 2010-08-31 11:04:44 UTC
The new glib release (2.25.15) contains GDateTime and we still haven't released a core/base including GstDateTime. We should add an #if/#else and use GDateTime if that is available on the system.

If someone has this new version available, he/she will be able to use all GDateTime API, while if someone doesn't, it will fall back to our minimalist GstDateTime API.
Comment 1 Thiago Sousa Santos 2010-09-29 17:57:39 UTC
Created attachment 171353 [details] [review]
datetime: Use GDateTime if available

Only use GstDateTime if the glib version still doesn't have
GDateTime.

This makes us avoid duplicate effort with glib devels
Comment 2 Tim-Philipp Müller 2010-10-07 23:27:06 UTC
Comment on attachment 171353 [details] [review]
datetime: Use GDateTime if available

>diff --git a/gst/gstdatetime.h b/gst/gstdatetime.h
>index 26b65d4..c3d9574 100644
>--- a/gst/gstdatetime.h
>+++ b/gst/gstdatetime.h
>@@ -22,19 +22,24 @@
> 
> #include <time.h>
> #include <glib.h>
>+#include "glib-compat-private.h"

This private header is not installed, so we can't include it in a public header.
 

>+#ifndef GLIB_HAS_GDATETIME
> typedef struct _GstDateTime GstDateTime;
>+#else
>+typedef GDateTime GstDateTime;
>+#endif

IMHO GstDateTime should *always* be 100% opaque at the API level, even if internally we just map it to GDateTime (more on that below though).

We should provide API (a function) to get a GDateTime from a GstDateTime though. If libgstreamer was built against GLib < 2.26 that function would return NULL. gstdatetime.h would define GDateTime to gpointer if we are building against GLib headers < 2.26.

Part of the reason I'd like it 100% opaque is that I think we can't just do the 1:1 mapping, not even internally, with the current GDateTime functionality: since the main use case for GstDateTime is to express dates and times from tags, we need to be able to express/set/query the 'granularity' of the datetime provided, so that we can express incomplete date/times properly (ie. "year 2010" or "2010-Aug-08, unknown time"). This is important for transcoding/retagging, so we can, err, "transtag"/rewrite such incomplete tags correctly, without adding bogus information (like making 'year 2010' into 2010-Jan-01, 00:00.000h UTC).
Comment 3 Thiago Sousa Santos 2010-10-11 21:17:05 UTC
Created attachment 172132 [details] [review]
glib-private: Add protection include macro
Comment 4 Thiago Sousa Santos 2010-10-11 21:17:36 UTC
Created attachment 172133 [details] [review]
datetime: Use GDateTime if available

Updates with Tim's comments.
Comment 5 Thiago Sousa Santos 2010-10-11 21:17:49 UTC
Created attachment 172134 [details] [review]
gstdatetime: Move doc outside the ifdefs

Move the datetime documentation of the functions outside the
ifdefs
Comment 6 Thiago Sousa Santos 2010-10-11 21:21:06 UTC
There are still 2 differences from our API to glib's.

1) They use a double to represent seconds + microseconds. We have 2 separate fields in functions.

2) They use a string for representing a timezone (+0300 or America/Recife or ...) as they can parse tzdata. And for the timezone offset they use microseconds resolution. We are using a double in hours resolution.

Item 1 is simple enough to update on our side.

For item 2 we could take our timezone handling to microseconds resolution too. glib does it because their datetime math API is based on microseconds, so it makes some sense. For us it doesn't make, but we get consistency with their API.

What do you think?
Comment 7 Tim-Philipp Müller 2010-10-12 12:16:03 UTC
Comment on attachment 172132 [details] [review]
glib-private: Add protection include macro

> glib-private: Add protection include macro

Looks ok (not sure if the glib-compat-private.h stuff is needed here though, see other comment)
Comment 8 Tim-Philipp Müller 2010-10-12 12:17:35 UTC
Comment on attachment 172133 [details] [review]
datetime: Use GDateTime if available

>Use GDateTime internally on GstDateTime if glib already
>provides it.

>--- a/gst/glib-compat-private.h
>+++ b/gst/glib-compat-private.h
>@@ -8,7 +8,6 @@
> #ifndef __GLIB_COMPAT_PRIVATE_H__
> #define __GLIB_COMPAT_PRIVATE_H__
> 
>-#include "gst_private.h" /* for g_warning */
> #include <glib.h>
> 
> G_BEGIN_DECLS
>@@ -17,6 +16,10 @@ G_BEGIN_DECLS
> typedef struct stat GStatBuf;
> #endif
> 
>+#if GLIB_CHECK_VERSION(2,26,0)
>+#define GLIB_HAS_GDATETIME
>+#endif
>+
> /* copies */
> 
> /* adaptations */
>diff --git a/gst/gstdatetime.c b/gst/gstdatetime.c
>index e02ea25..00cab13 100644
>--- a/gst/gstdatetime.c
>+++ b/gst/gstdatetime.c
>@@ -21,8 +21,12 @@
> #include "config.h"
> #endif
> 
>+#include "glib-compat-private.h"

Since it's not used anywhere else, maybe this define should just go into gstdatetime.c instead?
Comment 9 Tim-Philipp Müller 2010-10-12 12:30:23 UTC
> There are still 2 differences from our API to glib's.
> 
> 1) They use a double to represent seconds + microseconds. We have 2 separate
> fields in functions.

Makes sense to change our API to match GLib's here IMHO.  Don't think people care too much about micro-seconds in our main usage scenario (tags).


> 2) They use a string for representing a timezone (+0300 or America/Recife or
> ...) as they can parse tzdata. And for the timezone offset they use
> microseconds resolution. We are using a double in hours resolution.
>   (...)
> For item 2 we could take our timezone handling to microseconds resolution too.
> glib does it because their datetime math API is based on microseconds, so it
> makes some sense. For us it doesn't make, but we get consistency with their
> API.
> 
> What do you think?

No strong opinion, I could live with both. I think passing timezone offsets in microseconds is a bit weird though.
Comment 10 Thiago Sousa Santos 2010-10-12 23:21:52 UTC
Created attachment 172219 [details] [review]
gstdatetime: Move doc outside the ifdefs
Comment 11 Thiago Sousa Santos 2010-10-12 23:22:23 UTC
Created attachment 172220 [details] [review]
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.
Comment 12 Thiago Sousa Santos 2010-10-12 23:23:32 UTC
Created attachment 172221 [details] [review]
datetime: Handle timezone offset in usecs

Handle timezone offsets in microseconds, just like
glib API does. This doesn't seem nice and doesn't produce
a good looking code, but our goal here is to be as close
as possible to glib's API. So...

This is the weird one, I prefer to do the same as glib here,
as it makes it easier for people to use one or another.
Comment 13 Thiago Sousa Santos 2010-10-13 00:03:50 UTC
Created attachment 172223 [details] [review]
datetime: Use seconds as double

Of course I forgot something here.
Comment 14 Thiago Sousa Santos 2010-10-13 00:04:05 UTC
Created attachment 172224 [details] [review]
datetime: Handle timezone offset in usecs

Updated version.
Comment 15 Thiago Sousa Santos 2010-10-13 00:21:50 UTC
Btw, already got a patch for -base.
Comment 16 Tim-Philipp Müller 2010-10-13 13:18:26 UTC
Comment on attachment 172223 [details] [review]
datetime: Use seconds as double

> datetime: Use seconds as double

Should we also add g_return_if_fail() or g_warn_if_fail() for the tzoffset arguments here? (might have missed them though)
Comment 17 Tim-Philipp Müller 2010-10-13 13:20:09 UTC
Comment on attachment 172224 [details] [review]
datetime: Handle timezone offset in usecs

> datetime: Handle timezone offset in usecs

Bah :)
Comment 18 Thiago Sousa Santos 2010-10-13 15:01:15 UTC
Comment on attachment 172223 [details] [review]
datetime: Use seconds as double

Updated with the check and commited.
Comment 19 Thiago Sousa Santos 2010-10-13 15:02:27 UTC
Comment on attachment 172224 [details] [review]
datetime: Handle timezone offset in usecs

Ok, so not pushing this. It looks ugly.
Comment 20 Thiago Sousa Santos 2010-10-13 15:04:19 UTC
commit e9312870e5881295b52853825e7dab95a9c34b6e
commit 0d3c623b4b7c1e5ee44e5ad67c59a724b0d8efc6
commit c7e5bc1e5d7ff76aec986aa36eed860d4df484f2
commit 6d883ed95c19ca26eb7df479a6c53ac51c9e6c12

pushed to core.
Comment 21 Murray Cumming 2012-08-02 08:56:48 UTC
Wouldn't gstreamer 1.0 be a good time to replace GstDateTime with GDateTime?
Comment 22 Tim-Philipp Müller 2012-08-02 09:14:56 UTC
> Wouldn't gstreamer 1.0 be a good time to replace GstDateTime with GDateTime?

We need additional features that GDateTime does not support, namely partial dates (only year, only year/month, etc.), and had little hope that we'd have been able to push those into GLib for the GLib release version we would have needed them for.