GDateTime * g_flickr_parse_date (const gchar *date) { /* See http://www.flickr.com/services/api/misc.dates.html */ guint year, month, day, hours, minutes; gdouble seconds; sscanf (date, "%u-%u-%u %u:%u:%lf", &year, &month, &day, &hours, &minutes, &seconds); /* The date we get from flickr is expressed in the timezone of the camera, * which we cannot know, so we just go with utc */ return g_date_time_new_utc (year, month, day, hours, minutes, seconds); }
time64 gnc_timegm (struct tm* time) { GDateTime *gdt; time64 secs; normalize_struct_tm (time); gdt = g_date_time_new_utc (time->tm_year + 1900, time->tm_mon, time->tm_mday, time->tm_hour, time->tm_min, (gdouble)(time->tm_sec)); time->tm_mon = time->tm_mon > 0 ? time->tm_mon - 1 : 11; // Watch out: struct tm has wday=0..6 with Sunday=0, but GDateTime has wday=1..7 with Sunday=7. time->tm_wday = g_date_time_get_day_of_week (gdt) % 7; time->tm_yday = g_date_time_get_day_of_year (gdt); time->tm_isdst = g_date_time_is_daylight_savings (gdt); secs = g_date_time_to_unix (gdt); g_date_time_unref (gdt); return secs; }
GDateTime* utils_parse_time_iso_8601(const gchar* time, GError** error) { GDateTime* ret = NULL; gint year, month, day, hour, min, sec; gint scanned = sscanf(time, "%d-%d-%dT%d:%d:%dZ", &year, &month, &day, &hour, &min, &sec); if (scanned != 6) { g_set_error(error, GT_UTILS_ERROR, GT_UTILS_ERROR_PARSING_TIME, "Unable to parse time from input '%s'", time); } else ret = g_date_time_new_utc(year, month, day, hour, min, sec); return ret; }
Timespec gnc_iso8601_to_timespec_gmt(const char *str) { Timespec time = { 0L, 0L }; GDateTime *gdt; gint hour = 0, minute = 0, day = 0, month = 0, year = 0; gchar zone[12]; gdouble second = 0.0; gint fields; memset (zone, 0, sizeof (zone)); if (!str) return time; fields = sscanf (str, ISO_DATE_FORMAT, &year, &month, &day, &hour, &minute, &second, zone); if (fields < 1) return time; else if (fields > 6 && strlen (zone) > 0) /* Date string included a timezone */ { GTimeZone *tz = g_time_zone_new (zone); time64 secs; second += 5e-10; gdt = g_date_time_new (tz, year, month, day, hour, minute, second); secs = g_date_time_to_unix (gdt); g_time_zone_unref (tz); } else /* No zone info, assume UTC */ { second += 5e-10; gdt = g_date_time_new_utc (year, month, day, hour, minute, second); } time.tv_sec = g_date_time_to_unix (gdt); time.tv_nsec = g_date_time_get_microsecond (gdt) * 1000; g_date_time_unref (gdt); return time; }
static void set_time (GstRTSPTime * time, GstRTSPTime2 * time2, GstRTSPRangeUnit unit, GstClockTime clock_time) { memset (time, 0, sizeof (GstRTSPTime)); memset (time2, 0, sizeof (GstRTSPTime2)); if (clock_time == GST_CLOCK_TIME_NONE) { time->type = GST_RTSP_TIME_END; return; } switch (unit) { case GST_RTSP_RANGE_SMPTE: case GST_RTSP_RANGE_SMPTE_30_DROP: { time->seconds = (guint64) (clock_time / GST_SECOND); time2->frames = 30003 * (clock_time % GST_SECOND) / (gdouble) (1001 * GST_SECOND); time->type = GST_RTSP_TIME_FRAMES; g_assert (time2->frames < 30); break; } case GST_RTSP_RANGE_SMPTE_25: { time->seconds = (guint64) (clock_time / GST_SECOND); time2->frames = (25 * (clock_time % GST_SECOND)) / (gdouble) GST_SECOND; time->type = GST_RTSP_TIME_FRAMES; g_assert (time2->frames < 25); break; } case GST_RTSP_RANGE_NPT: { time->seconds = (gdouble) clock_time / (gdouble) GST_SECOND; time->type = GST_RTSP_TIME_SECONDS; break; } case GST_RTSP_RANGE_CLOCK: { GDateTime *bt, *datetime; GstClockTime subsecond = clock_time % GST_SECOND; bt = g_date_time_new_utc (1900, 1, 1, 0, 0, 0.0); datetime = g_date_time_add_seconds (bt, clock_time / GST_SECOND); time2->year = g_date_time_get_year (datetime); time2->month = g_date_time_get_month (datetime); time2->day = g_date_time_get_day_of_month (datetime); time->seconds = g_date_time_get_hour (datetime) * 60 * 60; time->seconds += g_date_time_get_minute (datetime) * 60; time->seconds += g_date_time_get_seconds (datetime); time->seconds += (gdouble) subsecond / (gdouble) GST_SECOND; time->type = GST_RTSP_TIME_UTC; g_date_time_unref (bt); g_date_time_unref (datetime); break; } } if (time->seconds < 0.000000001) time->seconds = 0; if (time2->frames < 0.000000001) time2->frames = 0; }
static void video_guess_values_from_display_name (const gchar *display_name, gchar **title, gchar **showname, GDateTime **date, gint *season, gint *episode) { gchar *metadata; GRegex *regex; GMatchInfo *info; metadata = video_display_name_to_metadata (display_name); regex = g_regex_new (MOVIE_REGEX, 0, 0, NULL); g_regex_match (regex, metadata, 0, &info); if (g_match_info_matches (info)) { if (title) { *title = g_match_info_fetch_named (info, "name"); /* Replace "." with <space> */ g_strdelimit (*title, ".", ' '); *title = g_strstrip (*title); } if (date) { gchar *year = g_match_info_fetch_named (info, "year"); *date = g_date_time_new_utc (atoi (year), 1, 1, 0, 0, 0.0); g_free (year); } if (showname) { *showname = NULL; } if (season) { *season = 0; } if (episode) { *episode = 0; } g_regex_unref (regex); g_match_info_free (info); g_free (metadata); return; } g_regex_unref (regex); g_match_info_free (info); regex = g_regex_new (TV_REGEX, 0, 0, NULL); g_regex_match (regex, metadata, 0, &info); if (g_match_info_matches (info)) { if (title) { *title = g_match_info_fetch_named (info, "name"); g_strdelimit (*title, ".()", ' '); *title = g_strstrip (*title); if (*title[0] == '\0') { g_free (*title); *title = NULL; } } if (showname) { *showname = g_match_info_fetch_named (info, "showname"); g_strdelimit (*showname, ".", ' '); *showname = g_strstrip (*showname); } if (season) { gchar *s = g_match_info_fetch_named (info, "season"); if (s) { if (*s == 's' || *s == 'S') { *season = atoi (s + 1); } else { *season = atoi (s); } } else { *season = 0; } g_free (s); } if (episode) { gchar *e = g_match_info_fetch_named (info, "episode"); if (e) { if (g_ascii_strncasecmp (e, "ep", 2) == 0) { *episode = atoi (e + 2); } else if (*e == 'e' || *e == 'E' || *e == 'x' || *e == '.') { *episode = atoi (e + 1); } else { *episode = atoi (e); } } else { *episode = 0; } g_free (e); } if (date) { *date = NULL; } g_regex_unref (regex); g_match_info_free (info); g_free (metadata); return; } g_regex_unref (regex); g_match_info_free (info); /* The filename doesn't look like a movie or a TV show, just use the filename without extension as the title */ if (title) { *title = g_strdelimit (metadata, ".", ' '); } if (showname) { *showname = NULL; } if (date) { *date = NULL; } if (season) { *season = 0; } if (episode) { *episode = 0; } }
dif_dive_t *dif_dive_set_datetime_utc(dif_dive_t *dive, guint year, guint month, guint day, guint hour, guint minute, guint second) { dive->datetime = g_date_time_new_utc(year, month, day, hour, minute, second); return dive; }