savetz.orig_tzid = 0;
savetz.new_env_str = 0;
- if(getenv("TZ") != 0){
- orig_tzid = (char*)icalmemory_strdup(getenv("TZ"));
+ if (g_getenv("TZ") != NULL) {
+ orig_tzid = (char*)icalmemory_strdup(g_getenv("TZ"));
- if(orig_tzid == 0){
+ if (orig_tzid == 0) {
icalerror_set_errno(ICAL_NEWFAILED_ERROR);
- return savetz;
- }
+ return savetz;
+ }
}
tmp_sz =strlen(tzid)+4;
time_t icaltime_as_timet(struct icaltimetype tt)
{
+ time_t t;
+
+#ifdef G_OS_WIN32
+ GTimeZone *zone;
+ GDateTime *dt;
+
+ if (tt.is_utc == 1)
+ zone = g_time_zone_new_utc();
+ else
+ zone = g_time_zone_new_local();
+
+ dt = g_date_time_new(
+ zone,
+ tt.year,
+ tt.month,
+ tt.day,
+ tt.hour,
+ tt.minute,
+ tt.second);
+
+ /* Got to return something... */
+ if (dt == NULL)
+ return 0;
+
+ t = g_date_time_to_unix(dt);
+
+ g_date_time_unref(dt);
+ g_time_zone_unref(zone);
+
+#else
struct tm stm;
- time_t t;
memset(&stm,0,sizeof( struct tm));
} else {
t = mktime(&stm);
}
+#endif
return t;
-
}
char* icaltime_as_ical_string(struct icaltimetype tt)
struct icaltimetype icaltime_normalize(struct icaltimetype tt)
{
+#ifndef G_OS_WIN32
struct tm stm, buft;
time_t tut;
tt.day = stm.tm_mday;
tt.month = stm.tm_mon +1;
tt.year = stm.tm_year+1900;
-
+#endif
return tt;
}
short icaltime_day_of_year(struct icaltimetype t){
+#ifdef G_OS_WIN32
+ GTimeZone *zone;
+ GDateTime *dt;
+
+ if (t.is_utc == 1)
+ zone = g_time_zone_new_utc();
+ else
+ zone = g_time_zone_new_local();
+
+ dt = g_date_time_new(
+ zone,
+ t.year,
+ t.month,
+ t.day,
+ t.hour,
+ t.minute,
+ t.second);
+
+ /* Got to return something... */
+ if (dt == NULL)
+ return 1;
+
+ gint doy = g_date_time_get_day_of_year(dt) - 1;
+ g_date_time_unref(dt);
+ g_time_zone_unref(zone);
+
+ return doy;
+
+#else
time_t tt = icaltime_as_timet(t);
struct tm *stm, buft;
}
return stm->tm_yday+1;
-
+#endif
}
/* Jan 1 is day #1, not 0 */
struct icaltimetype icaltime_from_day_of_year(short doy, short year)
{
+#ifdef G_OS_WIN32
+ GDateTime *dt = g_date_time_new_utc(
+ year,
+ 1,
+ 1,
+ 0,
+ 0,
+ 0);
+ GDateTime *dtd = g_date_time_add_days(dt, doy);
+
+ g_date_time_unref(dt);
+ struct icaltimetype t = icaltime_null_time();
+
+ t.year = g_date_time_get_year(dtd);
+ t.month = g_date_time_get_month(dtd);
+ t.day = g_date_time_get_day_of_month(dtd);
+ t.hour = g_date_time_get_hour(dtd);
+ t.minute = g_date_time_get_minute(dtd);
+ t.second = g_date_time_get_second(dtd);
+ t.is_utc = 1;
+ t.is_date = 1;
+ g_date_time_unref(dtd);
+
+ return t;
+
+#else
struct tm stm;
time_t tt;
struct set_tz_save old_tz = set_tz("UTC");
tt += doy *60*60*24;
return icaltime_from_timet(tt, 1);
+#endif
}
struct icaltimetype icaltime_null_time()