summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2005-11-17 17:51:59 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2005-11-17 17:51:59 +0000
commit9f90f2f23e60a20ca052681268912f2e5c900b11 (patch)
tree4f50a1259364d40ffcb1407b107828f2abdab350
parent1ee0917984152f9fe09b33a3660ba96cec0b55b1 (diff)
Add functions to set a date from a time_t and from a GTimeVal.
2005-11-17 Matthias Clasen <mclasen@redhat.com> * glib/glib.symbols: * glib/gdate.h: * glib/gdate.c (g_date_set_time_t): (g_date_set_time_val): Add functions to set a date from a time_t and from a GTimeVal. (g_date_set_time): Deprecate. (#314067, Roger Leigh)
-rw-r--r--ChangeLog7
-rw-r--r--ChangeLog.pre-2-107
-rw-r--r--ChangeLog.pre-2-127
-rw-r--r--docs/reference/ChangeLog6
-rw-r--r--docs/reference/glib/glib-sections.txt2
-rw-r--r--docs/reference/glib/tmpl/date.sgml16
-rw-r--r--glib/gdate.c72
-rw-r--r--glib/gdate.h9
-rw-r--r--glib/glib.symbols4
9 files changed, 110 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index ba164723f..b527b1ad0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2005-11-17 Matthias Clasen <mclasen@redhat.com>
+ * glib/glib.symbols:
+ * glib/gdate.h:
+ * glib/gdate.c (g_date_set_time_t):
+ (g_date_set_time_val): Add functions to set a date from
+ a time_t and from a GTimeVal.
+ (g_date_set_time): Deprecate. (#314067, Roger Leigh)
+
* tests/Makefile.am:
* tests/utf8-pointer.c: Unit tests for g_utf8_pointer_to_offset
and g_utf8_offset_to_pointer.
diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10
index ba164723f..b527b1ad0 100644
--- a/ChangeLog.pre-2-10
+++ b/ChangeLog.pre-2-10
@@ -1,5 +1,12 @@
2005-11-17 Matthias Clasen <mclasen@redhat.com>
+ * glib/glib.symbols:
+ * glib/gdate.h:
+ * glib/gdate.c (g_date_set_time_t):
+ (g_date_set_time_val): Add functions to set a date from
+ a time_t and from a GTimeVal.
+ (g_date_set_time): Deprecate. (#314067, Roger Leigh)
+
* tests/Makefile.am:
* tests/utf8-pointer.c: Unit tests for g_utf8_pointer_to_offset
and g_utf8_offset_to_pointer.
diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12
index ba164723f..b527b1ad0 100644
--- a/ChangeLog.pre-2-12
+++ b/ChangeLog.pre-2-12
@@ -1,5 +1,12 @@
2005-11-17 Matthias Clasen <mclasen@redhat.com>
+ * glib/glib.symbols:
+ * glib/gdate.h:
+ * glib/gdate.c (g_date_set_time_t):
+ (g_date_set_time_val): Add functions to set a date from
+ a time_t and from a GTimeVal.
+ (g_date_set_time): Deprecate. (#314067, Roger Leigh)
+
* tests/Makefile.am:
* tests/utf8-pointer.c: Unit tests for g_utf8_pointer_to_offset
and g_utf8_offset_to_pointer.
diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog
index 0969a7c74..42c274ce6 100644
--- a/docs/reference/ChangeLog
+++ b/docs/reference/ChangeLog
@@ -1,3 +1,9 @@
+2005-11-17 Matthias Clasen <mclasen@redhat.com>
+
+ * glib/tmpl/date.sgml:
+ * glib/glib-sections.txt: Add g_date_set_time_t,
+ g_date_set_time_val.
+
2005-11-08 Matthias Clasen <mclasen@redhat.com>
* glib/tmpl/threads.sgml: Improve GOnce docs.
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index 80cd93da0..efae15c5f 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -1171,6 +1171,8 @@ g_date_set_year
g_date_set_dmy
g_date_set_julian
g_date_set_time
+g_date_set_time_t
+g_date_set_time_val
g_date_set_parse
<SUBSECTION>
diff --git a/docs/reference/glib/tmpl/date.sgml b/docs/reference/glib/tmpl/date.sgml
index 83985adde..7ec46480d 100644
--- a/docs/reference/glib/tmpl/date.sgml
+++ b/docs/reference/glib/tmpl/date.sgml
@@ -136,9 +136,13 @@ month, and year.
<!-- ##### TYPEDEF GTime ##### -->
<para>
-Simply a replacement for <type>time_t</type>. Unrelated to #GTimer.
+Simply a replacement for <type>time_t</type>. It has been deprected
+since it is <emphasis>not</emphasis> equivalent to <type>time_t</type>
+on 64-bit platforms with a 64-bit <type>time_t</type>.
+Unrelated to #GTimer.
</para>
+
<para>
Note that <type>GTime</type> is defined to always be a 32bit integer,
unlike <type>time_t</type> which may be 64bit on some systems.
@@ -346,15 +350,11 @@ Sets the value of a #GDate from a Julian day number.
<!-- ##### FUNCTION g_date_set_time ##### -->
<para>
-Sets the value of a date from a #GTime (<type>time_t</type>) value.
-To set the value of a date to the current day, you could write:
-<informalexample><programlisting>
-g_date_set_time (date, time (NULL));
-</programlisting></informalexample>
+
</para>
-@date: a #GDate.
-@time_: #GTime value to set.
+@date:
+@time_:
<!-- ##### FUNCTION g_date_set_parse ##### -->
diff --git a/glib/gdate.c b/glib/gdate.c
index 3e9db33d8..17212a322 100644
--- a/glib/gdate.c
+++ b/glib/gdate.c
@@ -859,20 +859,33 @@ g_date_set_parse (GDate *d,
G_UNLOCK (g_date_global);
}
+/**
+ * g_date_set_time_t:
+ * @date: a #GDate
+ * @timet: <type>time_t</type> value to set
+ *
+ * Sets the value of a date from a <type>time_t</type> value.
+ *
+ * To set the value of a date to the current day, you could write:
+ * <informalexample><programlisting>
+ * g_date_set_time_t (date, time (NULL));
+ * </programlisting></informalexample>
+ *
+ * Since: 2.10
+ */
void
-g_date_set_time (GDate *d,
- GTime time)
+g_date_set_time_t (GDate *date,
+ time_t timet)
{
- time_t t = time;
struct tm tm;
- g_return_if_fail (d != NULL);
+ g_return_if_fail (date != NULL);
#ifdef HAVE_LOCALTIME_R
- localtime_r (&t, &tm);
+ localtime_r (&timet, &tm);
#else
{
- struct tm *ptm = localtime (&t);
+ struct tm *ptm = localtime (&timet);
if (ptm == NULL)
{
@@ -892,15 +905,50 @@ g_date_set_time (GDate *d,
}
#endif
- d->julian = FALSE;
+ date->julian = FALSE;
- d->month = tm.tm_mon + 1;
- d->day = tm.tm_mday;
- d->year = tm.tm_year + 1900;
+ date->month = tm.tm_mon + 1;
+ date->day = tm.tm_mday;
+ date->year = tm.tm_year + 1900;
- g_return_if_fail (g_date_valid_dmy (d->day, d->month, d->year));
+ g_return_if_fail (g_date_valid_dmy (date->day, date->month, date->year));
- d->dmy = TRUE;
+ date->dmy = TRUE;
+}
+
+
+/**
+ * g_date_set_time:
+ * @date: a #GDate.
+ * @time_: #GTime value to set.
+ *
+ * Sets the value of a date from a #GTime value.
+ *
+ * @Deprecated: Use g_date_set_time_t() instead.
+ */
+void
+g_date_set_time (GDate *date,
+ GTime *time_)
+{
+ g_date_set_time_t (date, (time_t) time_);
+}
+
+/**
+ * g_date_set_time_val:
+ * @date: a #GDate
+ * @timeval: #GTimeVal value to set
+ *
+ * Sets the value of a date from a #GTimeVal value. Note that the
+ * @tv_usec member is ignored, because #GDate can't make use of the
+ * additional precision.
+ *
+ * Since: 2.10
+ */
+void
+g_date_set_time_val (GDate *date,
+ GTimeVal *timeval)
+{
+ g_date_set_time_t (date, (time_t) timeval->tv_sec);
}
void
diff --git a/glib/gdate.h b/glib/gdate.h
index eafb16a6e..e2ee21534 100644
--- a/glib/gdate.h
+++ b/glib/gdate.h
@@ -27,6 +27,9 @@
#ifndef __G_DATE_H__
#define __G_DATE_H__
+#include <time.h>
+
+#include <glib/gtypes.h>
#include <glib/gquark.h>
G_BEGIN_DECLS
@@ -165,8 +168,14 @@ void g_date_clear (GDate *date,
*/
void g_date_set_parse (GDate *date,
const gchar *str);
+void g_date_set_time_t (GDate *date,
+ time_t timet);
+void g_date_set_time_val (GDate *date,
+ GTimeVal *timeval);
+#ifndef G_DISABLE_DEPRECATED
void g_date_set_time (GDate *date,
GTime time_);
+#endif
void g_date_set_month (GDate *date,
GDateMonth month);
void g_date_set_day (GDate *date,
diff --git a/glib/glib.symbols b/glib/glib.symbols
index fe4bef1ca..abe997f31 100644
--- a/glib/glib.symbols
+++ b/glib/glib.symbols
@@ -213,7 +213,11 @@ g_date_set_dmy
g_date_set_julian
g_date_set_month
g_date_set_parse
+#ifndef G_DISABLE_DEPRECATED
g_date_set_time
+#endif
+g_date_set_time_t
+g_date_set_time_val
g_date_set_year
g_date_strftime
g_date_subtract_days