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)
This commit is contained in:
Matthias Clasen 2005-11-17 17:51:59 +00:00 committed by Matthias Clasen
parent 1ee0917984
commit 9f90f2f23e
9 changed files with 110 additions and 20 deletions

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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>

View File

@ -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 ##### -->

View File

@ -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

View File

@ -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,

View File

@ -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