[gnome-calendar/wip/gbsneto/gdatetime: 5/13] utils: add convertion functions between GDateTime - icaltimetype
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/wip/gbsneto/gdatetime: 5/13] utils: add convertion functions between GDateTime - icaltimetype
- Date: Mon, 4 Jan 2016 04:19:44 +0000 (UTC)
commit 76a9350742cf89b6e05f07ba5f32a59f2b5c80ee
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Thu Dec 31 13:36:33 2015 -0200
utils: add convertion functions between GDateTime - icaltimetype
These will be extensively used during the migration proccess
to GDateTime.
src/gcal-utils.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/gcal-utils.h | 4 +++
2 files changed, 61 insertions(+), 0 deletions(-)
---
diff --git a/src/gcal-utils.c b/src/gcal-utils.c
index 7969f28..914ebca 100644
--- a/src/gcal-utils.c
+++ b/src/gcal-utils.c
@@ -63,6 +63,63 @@ month_item[12] =
G_DEFINE_BOXED_TYPE (icaltimetype, icaltime, gcal_dup_icaltime, g_free)
+GDateTime*
+icaltimetype_to_datetime (const icaltimetype *date)
+{
+ GDateTime *dt;
+ GTimeZone *tz;
+ gboolean is_date;
+
+ if (!date)
+ return NULL;
+
+ is_date = date->is_date ? TRUE : FALSE;
+
+
+ if (icaltime_get_tzid (*date))
+ tz = g_time_zone_new (icaltime_get_tzid (*date));
+ else
+ tz = g_time_zone_new_local ();
+
+ dt = g_date_time_new (tz,
+ date->year,
+ date->month,
+ date->day,
+ is_date ? date->hour : 0,
+ is_date ? date->minute : 0,
+ is_date ? date->second : 0.0);
+
+ g_time_zone_unref (tz);
+
+ return dt;
+}
+
+icaltimetype*
+datetime_to_icaltimetype (GDateTime *date)
+{
+ icaltimetype *new_date;
+ const gchar *tzid;
+
+ if (!date)
+ return NULL;
+
+ tzid = g_date_time_get_timezone_abbreviation (date);
+
+ new_date= g_new (icaltimetype, 1);
+ new_date->year = g_date_time_get_year (date);
+ new_date->month = g_date_time_get_month (date);
+ new_date->day = g_date_time_get_day_of_month (date);
+ new_date->hour = g_date_time_get_hour (date);
+ new_date->minute = g_date_time_get_minute (date);
+ new_date->second = g_date_time_get_second (date);
+ new_date->is_date = new_date->hour == 0 && new_date->minute == 0;
+ new_date->is_daylight = g_date_time_is_daylight_savings (date);
+ new_date->is_utc = g_strcmp0 (g_date_time_get_timezone_abbreviation (date), "UTC") == 0;
+ new_date->zone = icaltimezone_get_builtin_timezone_from_tzid (tzid);
+
+ return new_date;
+}
+
icaltimetype*
gcal_dup_icaltime (const icaltimetype *date)
{
diff --git a/src/gcal-utils.h b/src/gcal-utils.h
index cbc8e7d..5c436e5 100644
--- a/src/gcal-utils.h
+++ b/src/gcal-utils.h
@@ -52,6 +52,10 @@ const gchar* (*GcalTranslateFunc) (GtkWidget
GType icaltime_get_type (void) G_GNUC_CONST;
+GDateTime* icaltimetype_to_datetime (const icaltimetype *date);
+
+icaltimetype* datetime_to_icaltimetype (GDateTime *date);
+
icaltimetype* gcal_dup_icaltime (const icaltimetype *date);
gchar* gcal_get_weekday (gint i);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]