From d7a216df8fe986cdfbe093dd1d403ca9605440a8 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 22 Aug 2005 15:39:34 +0000 Subject: [PATCH] Point out time_t vs GTime pitfalls. 2005-08-22 Matthias Clasen * glib/tmpl/date.sgml: Point out time_t vs GTime pitfalls. --- docs/reference/ChangeLog | 4 ++++ docs/reference/glib/tmpl/date.sgml | 30 ++++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index f6cfd08e..34197f5d 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,7 @@ +2005-08-22 Matthias Clasen + + * glib/tmpl/date.sgml: Point out time_t vs GTime pitfalls. + 2005-08-15 Matthias Clasen * glib/glib-gettexttize.xml: diff --git a/docs/reference/glib/tmpl/date.sgml b/docs/reference/glib/tmpl/date.sgml index ab83317b..6e4c4c93 100644 --- a/docs/reference/glib/tmpl/date.sgml +++ b/docs/reference/glib/tmpl/date.sgml @@ -53,9 +53,9 @@ representation is valid. Sometimes neither is valid. Use the API. GLib doesn't contain any time-manipulation functions; however, there -is a #GTime typedef which is equivalent to time_t, and a #GTimeVal -struct which represents a more precise time (with microseconds). You -can request the current time as a #GTimeVal with g_get_current_time(). +is a #GTime typedef and a #GTimeVal struct which represents a more +precise time (with microseconds). You can request the current time as +a #GTimeVal with g_get_current_time(). @@ -76,9 +76,9 @@ code readability. -Represents a precise time, with seconds and microseconds. Same as the -struct timeval returned by the -gettimeofday() UNIX call. +Represents a precise time, with seconds and microseconds. +Similar to the struct timeval returned by +the gettimeofday() UNIX call. @tv_sec: seconds. @@ -139,6 +139,24 @@ month, and year. Simply a replacement for time_t. Unrelated to #GTimer. + +Note that GTime is defined to always be a 32bit integer, +unlike time_t which may be 64bit on some systems. +Therefore, GType will overflow in the year 2038, and +you cannot use the address of a GTime variable as argument +to the UNIX time() function. Instead, do the following: + + +time_t ttime; +GTime gtime; + +time (&ttime); +gtime = (GTime)ttime; + + + + + -- 2.34.1