gint
main (gint argc,
      gchar *argv[])
{

  // if final value remains 0 the test is passed otherwise return a -1: 
  gint retVal = 0;

  GTimeZone *tz = (GTimeZone *)g_time_zone_new_local();  
  //gint64 year, month, day;

  GDateTime *date00 = (GDateTime *)g_date_time_new(tz, 2015, 10, 1, 0, 0, 0);
  GDateTime *date01 = (GDateTime *)g_date_time_new(tz, 2015, 10, 1, 0, 0, 0);
  GDateTime *date02 = (GDateTime *)g_date_time_new(tz, 2015, 10, 1, 0, 0, 0);

  GDateTime *dt_1 =  str_to_gdatetime(tz, "20151001", "%4d%2d%2d");
  if (g_date_time_compare(date00, dt_1) != 0) {
    g_printf("%s was improperly parsed as a GDateTime!", "20151001");
    retVal = -1;
  }
  g_date_time_unref(dt_1);

  GDateTime *dt_2 = str_to_gdatetime(tz, "2015/10/01", "%d/%d/%d");
  if (g_date_time_compare(date01, dt_2) != 0) {
    g_printf("%s was improperly parsed as a GDateTime!", "2015/10/01");
    retVal = -1;
  }
  g_date_time_unref(dt_2);

  GDateTime *dt_3 = str_to_gdatetime(tz, "2015-10-01", "%d-%d-%d");
  if (g_date_time_compare(date02, dt_3) != 0) {
    g_printf("%s was improperly parsed as a GDateTime!", "2015-10-01");
    retVal = -1;
  }
  g_date_time_unref(dt_3);
  
  if (retVal == 0) {
    g_printf("All test strings were properly parsed as GDateTimes in check_str_to_gdatetime.");
  }

  // clean everything up:
  g_date_time_unref(date00);
  g_date_time_unref(date01);
  g_date_time_unref(date02);

  g_time_zone_unref(tz);

  return retVal;

}
示例#2
0
gint
gcal_event_widget_sort_events (GcalEventWidget *widget1,
                               GcalEventWidget *widget2)
{
  g_autoptr (GDateTime) dt_time1 = NULL;
  g_autoptr (GDateTime) dt_time2 = NULL;
  icaltimetype *ical_dt;
  gint diff;

  diff = gcal_event_is_multiday (widget2->event) - gcal_event_is_multiday (widget1->event);

  if (diff != 0)
    return diff;

  diff = gcal_event_widget_compare_by_start_date (widget1, widget2);

  if (diff != 0)
    return diff;

  diff = gcal_event_widget_compare_by_length (widget1, widget2);

  if (diff != 0)
    return diff;

  e_cal_component_get_last_modified (gcal_event_get_component (widget1->event), &ical_dt);
  if (ical_dt)
    dt_time1 = gcal_date_time_from_icaltime (ical_dt);

  e_cal_component_get_last_modified (gcal_event_get_component (widget2->event), &ical_dt);
  if (ical_dt)
    dt_time2 = gcal_date_time_from_icaltime (ical_dt);

  return dt_time1 && dt_time2 ? g_date_time_compare (dt_time2, dt_time1) : 0;
}
示例#3
0
static GError*
_check(GList *working_m1list) {
	GError *error = NULL;

	if ( working_m1list ) {

		working_m1list=g_list_sort(working_m1list,meta0_assign_sort_by_score);
		struct meta0_assign_meta1_s *hM1 = working_m1list->data;
		struct meta0_assign_meta1_s *lM1 = (g_list_last(working_m1list))->data;
		guint highscore = hM1->score;
		guint lowscore = lM1->score;
		GRID_TRACE("check delta highscore %d ,lowscore %d",highscore,lowscore);
		if ( (highscore - lowscore) < (context->avgscore * trigger_assignment )/ 100  ) {
			GRID_WARN("New assign not necessary, high score %d , low score %d, average %d", highscore, lowscore, context->avgscore);
			error = NEWERROR(0, "New assign not necessary");
			return error;
		}
	}

	if ( context->lastAssignTime ) {
		GRID_TRACE("last time %s",g_date_time_format (context->lastAssignTime,"%Y-%m-%d %H:%M"));
		GDateTime *currentTime, *ltime;
		currentTime=g_date_time_new_now_local();
		ltime = g_date_time_add_minutes(context->lastAssignTime,period_between_two_assign);
		GRID_TRACE("currentTime :%s , last time + %d min :%s, comp :%d",g_date_time_format (currentTime,"%Y-%m-%d %H:%M"),period_between_two_assign,g_date_time_format (ltime,"%Y-%m-%d %H:%M"), g_date_time_compare(ltime,currentTime));
		if (g_date_time_compare(ltime,currentTime) > 0 ) {
			GRID_WARN("delay between two meta1 assign  not respected. Try later. last date [%s]",g_date_time_format (context->lastAssignTime,"%Y-%m-%d %H:%M"));
			error = NEWERROR(0,"delay between two meta1 assign  not respected. Try later.");
			return error;
		}
	}

	return NULL;
}
示例#4
0
static
void get_tile_box (MexEpgGrid      *grid,
                   MexEpgTile      *tile,
                   guint            row,
                   MxPadding       *padding,
                   ClutterActorBox *box)
{
  MexEpgGridPrivate *priv = grid->priv;
  MexEpgEvent *event;
  GDateTime *start_date;
  GTimeSpan diff;
  gint duration;

  event = mex_epg_tile_get_event (tile);
  start_date = mex_epg_event_get_start_date (event);

  if (g_date_time_compare (start_date, priv->first_date) < 0)
    diff = 0;
  else
    diff = g_date_time_difference (start_date, priv->first_date);   /* us */
  duration = mex_epg_event_get_duration (event);                  /*  s */

  box->x1 = padding->left + time_span_to_pixels (grid, diff);
  box->y1 = padding->top + HEADER_HEIGHT + TILE_HEIGHT * row;
  box->x2 = box->x1 + duration / 60 / 5 * priv->pixels_for_5_mins;
  box->y2 = box->y1 + TILE_HEIGHT;

#if 0
  g_message ("Allocating tile (%f,%f) (%f,%f)",
             box->x1, box->y1, box->x2, box->y2);
#endif
}
示例#5
0
gint
priv_gst_date_time_compare (gconstpointer dt1, gconstpointer dt2)
{
  const GstDateTime *datetime1 = dt1;
  const GstDateTime *datetime2 = dt2;
  return g_date_time_compare (datetime1->datetime, datetime2->datetime);
}
/**
 * eel_get_date_as_string:
 *
 * Get a formated date string where format equal iso, locale, informal.
 * The caller is responsible for g_free-ing the result.
 * @d: contains the UNIX time.
 * @date_format: string representing the format to convert the date to.
 *
 * Returns: Newly allocated date.
 *
**/
char *
eel_get_date_as_string (guint64 d, gchar *date_format)
{
    const char *format;
    gchar *result = NULL;
    GDateTime *date_time, *today, *last_year;
    GTimeSpan file_date_age;
    gboolean is_last_year;

    g_return_val_if_fail (date_format != NULL, NULL);
    date_time = g_date_time_new_from_unix_local ((gint64) d);

    if (!strcmp (date_format, "locale")) {
        result = g_date_time_format (date_time, "%c");
        goto out;
    } else if (!strcmp (date_format, "iso")) {
        result = g_date_time_format (date_time, "%Y-%m-%d %H:%M:%S");
        goto out;
    }

    today = g_date_time_new_now_local ();
    last_year = g_date_time_add_years (today, -1);
    file_date_age = g_date_time_difference (today, date_time);
    is_last_year = g_date_time_compare (date_time, last_year) > 0;
    g_date_time_unref (today);
    g_date_time_unref (last_year);

    /* Format varies depending on how old the date is. This minimizes
     * the length (and thus clutter & complication) of typical dates
     * while providing sufficient detail for recent dates to make
     * them maximally understandable at a glance. Keep all format
     * strings separate rather than combining bits & pieces for
     * internationalization's sake.
     */

    if (file_date_age < G_TIME_SPAN_DAY) {
        //TODAY_TIME_FORMATS
        //"Today at 00:00 PM"
        format = _("Today at %-I:%M %p");
    } else if (file_date_age < 2 * G_TIME_SPAN_DAY) {
        //YESTERDAY_TIME_FORMATS
        //"Yesterday at 00:00 PM"
        format = _("Yesterday at %-I:%M %p");
    } else if (is_last_year) {
        //CURRENT_YEAR_TIME_FORMATS
        //"Mon 00 Oct at 00:00 PM"
        format = _("%a %-d %b at %-I:%M %p");
    } else {
        //CURRENT_WEEK_TIME_FORMATS
        //"Mon 00 Oct 0000 at 00:00 PM"
        format = _("%a %-d %b %Y at %-I:%M %p");
    }

    result = g_date_time_format (date_time, format);

 out:
    g_date_time_unref (date_time);
    return result;
}
bool DateTime::operator==(const DateTime& that) const
{
    auto dt = get();
    auto tdt = that.get();
    if (!dt && !tdt) return true;
    if (!dt || !tdt) return false;
    return g_date_time_compare(get(), that.get()) == 0;
}
示例#8
0
static gint
bb_post_loader_compare_items(bb_item_t *a, bb_item_t *b)
{
    if (a == NULL || a->error != NULL || b == NULL || b->error != NULL)
        return -1;  // stack errors in the begin of the list.
    gint cmp = g_date_time_compare(a->post->metadata->datetime, b->post->metadata->datetime);
    return cmp * -1;
}
示例#9
0
gint
gdt_sorter (gconstpointer a,
        gconstpointer b)
{

  /* Just a little helper function for sorting the dates in
     print_dates_sorted (below). */

	return g_date_time_compare(*(gpointer *)a, *(gpointer *)b);

}
示例#10
0
static void
update_color (GcalEventWidget *self)
{
  GtkStyleContext *context;
  GdkRGBA *color;
  GQuark color_id;
  gchar *color_str;
  gchar *css_class;
  GDateTime *now;
  gint date_compare;

  context = gtk_widget_get_style_context (GTK_WIDGET (self));
  color = gcal_event_get_color (self->event);
  now = g_date_time_new_now_local ();
  date_compare = g_date_time_compare (self->dt_end, now);

  /* Fades out an event that's earlier than the current date */
  gtk_widget_set_opacity (GTK_WIDGET (self), date_compare < 0 ? 0.6 : 1.0);

  /* Remove the old style class */
  if (self->css_class)
    {
      gtk_style_context_remove_class (context, self->css_class);
      g_clear_pointer (&self->css_class, g_free);
    }

  color_str = gdk_rgba_to_string (color);
  color_id = g_quark_from_string (color_str);
  css_class = g_strdup_printf ("color-%d", color_id);

  gtk_style_context_add_class (context, css_class);

  if (INTENSITY (color) > 0.5)
    {
      gtk_style_context_remove_class (context, "color-dark");
      gtk_style_context_add_class (context, "color-light");
    }
  else
    {
      gtk_style_context_remove_class (context, "color-light");
      gtk_style_context_add_class (context, "color-dark");
    }

  /* Keep the current style around, so we can remove it later */
  self->css_class = css_class;

  g_clear_pointer (&now, g_date_time_unref);
  g_free (color_str);
}
示例#11
0
static gint
date_time_day_difference (GDateTime *first,
                          GDateTime *second)
{
	gint dfirst;
	gint dsecond;

	dfirst = g_date_time_get_day_of_year (first);
	dsecond = g_date_time_get_day_of_year (second);

	if (dfirst == dsecond)
		return 0;
	else
		return g_date_time_compare (first, second);
}
示例#12
0
GSList *
chat_log_get_previous(const gchar * const login, const gchar * const recipient,
    GSList *history)
{
    GTimeZone *tz = g_time_zone_new_local();

    GDateTime *now = g_date_time_new_now_local();
    GDateTime *log_date = g_date_time_new(tz,
        g_date_time_get_year(session_started),
        g_date_time_get_month(session_started),
        g_date_time_get_day_of_month(session_started),
        g_date_time_get_hour(session_started),
        g_date_time_get_minute(session_started),
        g_date_time_get_second(session_started));

    // get data from all logs from the day the session was started to today
    while (g_date_time_compare(log_date, now) != 1) {
        char *filename = _get_log_filename(recipient, login, log_date, FALSE);

        FILE *logp = fopen(filename, "r");
        char *line;
        if (logp != NULL) {
            GString *gs_header = g_string_new("");
            g_string_append_printf(gs_header, "%d/%d/%d:",
                g_date_time_get_day_of_month(log_date),
                g_date_time_get_month(log_date),
                g_date_time_get_year(log_date));
            char *header = strdup(gs_header->str);
            history = g_slist_append(history, header);
            g_string_free(gs_header, TRUE);

            while ((line = prof_getline(logp)) != NULL) {
                history = g_slist_append(history, line);
            }

            fclose(logp);
        }

        free(filename);
        GDateTime *next = g_date_time_add_days(log_date, 1);
        g_date_time_unref(log_date);
        log_date = g_date_time_ref(next);
    }

    g_time_zone_unref(tz);

    return history;
}
示例#13
0
文件: dif.c 项目: pridkett/dc2uddf
gint _dif_dive_compare(gconstpointer a, gconstpointer b) {
    dif_dive_t *dive1 = (dif_dive_t *)a;
    dif_dive_t *dive2 = (dif_dive_t *)b;
    GDateTime *time1 = dive1->datetime;
    GDateTime *time2 = dive2->datetime;
    if (time1 != NULL && time2 != NULL) {
        return g_date_time_compare(time1, time2);
    } else if (time1 != NULL && time2 == NULL) {
        return -1;
    } else if (time1 == NULL && time2 != NULL) {
        return 1;
    } else {
        return 0;
    }
    return 0;
}
static void
set_sensitivity (UmHistoryDialog *um)
{
        GArray *login_history;
        UmLoginHistory history;
        gboolean sensitive = FALSE;

        login_history = get_login_history (um->user);
        if (login_history != NULL) {
                history = g_array_index (login_history, UmLoginHistory, 0);
                sensitive = g_date_time_to_unix (um->week) > history.login_time;
                g_array_free (login_history, TRUE);
        }
        gtk_widget_set_sensitive (get_widget (um, "previous-button"), sensitive);

        sensitive = (g_date_time_compare (um->current_week, um->week) == 1);
        gtk_widget_set_sensitive (get_widget (um, "next-button"), sensitive);
}
示例#15
0
gint
ide_project_info_compare (IdeProjectInfo *info1,
                          IdeProjectInfo *info2)
{
  const gchar *name1;
  const gchar *name2;
  GDateTime *dt1;
  GDateTime *dt2;
  gint ret;
  gint prio1;
  gint prio2;

  g_assert (IDE_IS_PROJECT_INFO (info1));
  g_assert (IDE_IS_PROJECT_INFO (info2));

  prio1 = ide_project_info_get_priority (info1);
  prio2 = ide_project_info_get_priority (info2);

  if (prio1 != prio2)
    return prio1 - prio2;

  dt1 = ide_project_info_get_last_modified_at (info1);
  dt2 = ide_project_info_get_last_modified_at (info2);

  ret = g_date_time_compare (dt2, dt1);

  if (ret != 0)
    return ret;

  name1 = ide_project_info_get_name (info1);
  name2 = ide_project_info_get_name (info2);

  if (name1 == NULL)
    return 1;
  else if (name2 == NULL)
    return -1;
  else
    return strcasecmp (name1, name2);
}
示例#16
0
/**
 * gcal_event_widget_set_date_end:
 * @self: a #GcalEventWidget
 * @date_end: the end date of this widget
 *
 * Sets the visible end date of this widget. This
 * may differ from the event's end date, but cannot
 * be after it.
 */
void
gcal_event_widget_set_date_end (GcalEventWidget *self,
                                GDateTime       *date_end)
{
  g_return_if_fail (GCAL_IS_EVENT_WIDGET (self));

  if (self->dt_end != date_end &&
      (!self->dt_end || !date_end ||
       (self->dt_end && date_end && !g_date_time_equal (self->dt_end, date_end))))
    {
      /* The end date should never be after the event's end date */
      if (date_end && g_date_time_compare (date_end, gcal_event_get_date_end (self->event)) > 0)
        return;

      g_clear_pointer (&self->dt_end, g_date_time_unref);
      self->dt_end = g_date_time_ref (date_end);

      gcal_event_widget_update_style (self);

      g_object_notify (G_OBJECT (self), "date-end");
    }
}
示例#17
0
/**
 * gcal_event_widget_set_date_start:
 * @self: a #GcalEventWidget
 * @date_end: the start date of this widget
 *
 * Sets the visible start date of this widget. This
 * may differ from the event's start date, but cannot
 * be before it.
 */
void
gcal_event_widget_set_date_start (GcalEventWidget *self,
                                  GDateTime       *date_start)
{
  g_return_if_fail (GCAL_IS_EVENT_WIDGET (self));

  if (self->dt_start != date_start &&
      (!self->dt_start || !date_start ||
       (self->dt_start && date_start && !g_date_time_equal (self->dt_start, date_start))))
    {
      /* The start date should never be before the event's start date */
      if (date_start && g_date_time_compare (date_start, gcal_event_get_date_start (self->event)) < 0)
        return;

      g_clear_pointer (&self->dt_start, g_date_time_unref);
      self->dt_start = g_date_time_ref (date_start);

      gcal_event_widget_update_style (self);

      g_object_notify (G_OBJECT (self), "date-start");
    }
}
示例#18
0
gint
gcal_compare_event_widget_by_date (gconstpointer a,
                                   gconstpointer b)
{
  /* negative value if a < b; zero if a = b; positive value if a > b. */
  GcalViewChild *a_child;
  GcalViewChild *b_child;
  GDateTime *a_date;
  GDateTime *b_date;

  gint comparison;

  a_child = (GcalViewChild*) a;
  b_child = (GcalViewChild*) b;

  a_date = gcal_event_get_date_start (gcal_event_widget_get_event (GCAL_EVENT_WIDGET (a_child->widget)));
  b_date = gcal_event_get_date_start (gcal_event_widget_get_event (GCAL_EVENT_WIDGET (b_child->widget)));

  comparison = g_date_time_compare (a_date, b_date);

  return comparison;
}
bool DateTime::operator<=(const DateTime& that) const
{
    return g_date_time_compare(get(), that.get()) <= 0;
}
/**
 * gst_video_time_code_compare:
 * @tc1: a #GstVideoTimeCode
 * @tc2: another #GstVideoTimeCode
 *
 * Compares @tc1 and @tc2 . If both have latest daily jam information, it is
 * taken into account. Otherwise, it is assumed that the daily jam of both
 * @tc1 and @tc2 was at the same time.
 *
 * Returns: 1 if @tc1 is after @tc2, -1 if @tc1 is before @tc2, 0 otherwise.
 *
 * Since: 1.10
 */
gint
gst_video_time_code_compare (const GstVideoTimeCode * tc1,
    const GstVideoTimeCode * tc2)
{
  g_return_val_if_fail (gst_video_time_code_is_valid (tc1), -1);
  g_return_val_if_fail (gst_video_time_code_is_valid (tc2), -1);

  if (tc1->config.latest_daily_jam == NULL
      || tc2->config.latest_daily_jam == NULL) {
    guint64 nsec1, nsec2;
#ifndef GST_DISABLE_GST_DEBUG
    gchar *str1, *str2;

    str1 = gst_video_time_code_to_string (tc1);
    str2 = gst_video_time_code_to_string (tc2);
    GST_INFO
        ("Comparing time codes %s and %s, but at least one of them has no "
        "latest daily jam information. Assuming they started together",
        str1, str2);
    g_free (str1);
    g_free (str2);
#endif
    if (tc1->hours > tc2->hours) {
      return 1;
    } else if (tc1->hours < tc2->hours) {
      return -1;
    }
    if (tc1->minutes > tc2->minutes) {
      return 1;
    } else if (tc1->minutes < tc2->minutes) {
      return -1;
    }
    if (tc1->seconds > tc2->seconds) {
      return 1;
    } else if (tc1->seconds < tc2->seconds) {
      return -1;
    }

    nsec1 =
        gst_util_uint64_scale (GST_SECOND,
        tc1->frames * tc1->config.fps_n, tc1->config.fps_d);
    nsec2 =
        gst_util_uint64_scale (GST_SECOND,
        tc2->frames * tc2->config.fps_n, tc2->config.fps_d);
    if (nsec1 > nsec2) {
      return 1;
    } else if (nsec1 < nsec2) {
      return -1;
    }
    if (tc1->config.flags & GST_VIDEO_TIME_CODE_FLAGS_INTERLACED) {
      if (tc1->field_count > tc2->field_count)
        return 1;
      else if (tc1->field_count < tc2->field_count)
        return -1;
    }
    return 0;
  } else {
    GDateTime *dt1, *dt2;
    gint ret;

    dt1 = gst_video_time_code_to_date_time (tc1);
    dt2 = gst_video_time_code_to_date_time (tc2);

    ret = g_date_time_compare (dt1, dt2);

    g_date_time_unref (dt1);
    g_date_time_unref (dt2);

    return ret;
  }
}
示例#21
0
gint
gcal_event_widget_compare_by_start_date (GcalEventWidget *widget1,
                                         GcalEventWidget *widget2)
{
  return g_date_time_compare (widget1->dt_start, widget2->dt_start);
}
示例#22
0
static void
gcal_event_widget_update_style (GcalEventWidget *self)
{
  GtkStyleContext *context;
  gboolean slanted_start;
  gboolean slanted_end;
  gboolean timed;

  context = gtk_widget_get_style_context (GTK_WIDGET (self));
  slanted_start = FALSE;
  slanted_end = FALSE;

  /* Clear previous style classes */
  gtk_style_context_remove_class (context, "slanted");
  gtk_style_context_remove_class (context, "slanted-start");
  gtk_style_context_remove_class (context, "slanted-end");

  /*
   * If the event's dates differs from the widget's dates,
   * add a slanted edge class at the widget.
   */

  if (self->dt_start)
    slanted_start = g_date_time_compare (gcal_event_get_date_start (self->event), self->dt_start) != 0;

  if (self->dt_end)
    slanted_end = g_date_time_compare (gcal_event_get_date_end (self->event), self->dt_end) != 0;

  if (slanted_start && slanted_end)
    gtk_style_context_add_class (context, "slanted");
  else if (slanted_start)
    gtk_style_context_add_class (context, "slanted-start");
  else if (slanted_end)
    gtk_style_context_add_class (context, "slanted-end");

  /* TODO: adjust margins based on the CSS gradients sizes, not hardcoded */
  gtk_widget_set_margin_start (self->stack, slanted_start ? 20 : 4);
  gtk_widget_set_margin_end (self->stack, slanted_end ? 20 : 4);

  /* Add style classes for orientation selectors */
  if (self->orientation == GTK_ORIENTATION_HORIZONTAL)
    {
      gtk_style_context_add_class (context, "horizontal");
      gtk_style_context_remove_class (context, "vertical");
    }
  else
    {
      gtk_style_context_add_class (context, "vertical");
      gtk_style_context_remove_class (context, "horizontal");
    }

  /*
   * If the event is a timed, single-day event, draw it differently
   * from all-day or multi-day events.
   */
  timed = !gcal_event_get_all_day (self->event) && !gcal_event_is_multiday (self->event);

  gtk_widget_set_visible (self->color_box, timed);

  if (timed)
    {
      GtkStyleContext *context;

      context = gtk_widget_get_style_context (GTK_WIDGET (self));
      gtk_style_context_add_class (context, "timed");

      if (self->orientation == GTK_ORIENTATION_HORIZONTAL)
        {
          gtk_widget_set_margin_start (self->stack, 0);
          gtk_widget_set_margin_end (self->stack, 2);
        }
      else
        {
          gtk_widget_set_visible (self->color_box, FALSE);
        }
    }
}
示例#23
0
static void
cleaner_task_handler (GTask *task, gpointer source_object,
			gpointer task_data, GCancellable *cancellable)
{
	HevFileboxCleaner *self = HEV_FILEBOX_CLEANER (source_object);
    HevFileboxCleanerPrivate *priv = HEV_FILEBOX_CLEANER_GET_PRIVATE (self);
	gchar *fp_path = NULL, *fm_path = NULL;
	GFile *file = NULL;
	GFileEnumerator *file_enumerator = NULL;
	GFileInfo *file_info = NULL;

    g_debug ("%s:%d[%s]", __FILE__, __LINE__, __FUNCTION__);

	fp_path = g_key_file_get_string (priv->config, "Module", "FilePoolPath", NULL);
	fm_path = g_key_file_get_string (priv->config, "Module", "FileMetaPath", NULL);

	/* enumerate file pool */
	file = g_file_new_for_path (fp_path);
	file_enumerator = g_file_enumerate_children (file,
				G_FILE_ATTRIBUTE_STANDARD_NAME","G_FILE_ATTRIBUTE_STANDARD_TYPE,
				G_FILE_QUERY_INFO_NONE, NULL, NULL);
	while (file_info = g_file_enumerator_next_file (file_enumerator, NULL, NULL)) {
		if (G_FILE_TYPE_REGULAR == g_file_info_get_file_type (file_info)) {
			gchar *meta_path = NULL;
			GKeyFile *meta = NULL;

			meta_path = g_build_filename (fm_path, g_file_info_get_name (file_info), NULL);
			meta = g_key_file_new ();
			if (g_key_file_load_from_file (meta, meta_path, G_KEY_FILE_NONE, NULL)) {
				gint64 exp = 0;
				GDateTime *now_date = NULL, *exp_date = NULL;

				exp = g_key_file_get_int64 (meta, "Meta", "ExpDate", NULL);
				now_date = g_date_time_new_now_utc ();
				exp_date = g_date_time_new_from_unix_utc (exp);

				/* compare date */
				if (1 == g_date_time_compare (now_date, exp_date)) {
					gchar *file_path = NULL;

					file_path = g_build_filename (fp_path,
								g_file_info_get_name (file_info), NULL);
					/* delete file and it's meta */
					g_unlink ((const gchar *) file_path);
					g_unlink ((const gchar *) meta_path);
					g_free (file_path);
				}

				g_date_time_unref (now_date);
				g_date_time_unref (exp_date);
			}
			g_key_file_unref (meta);
			g_free (meta_path);
		}
		g_object_unref (file_info);
	}
	g_object_unref (file_enumerator);
	g_object_unref (file);

	g_free (fp_path);
	g_free (fm_path);

	g_task_return_boolean (task, TRUE);
}
static EosUpdateInfo *
get_latest_update (GArray *sources,
                   GHashTable *source_to_update)
{
  g_autoptr(GHashTable) latest = g_hash_table_new (NULL, NULL);
  GHashTableIter iter;
  gpointer name_ptr;
  gpointer update_ptr;
  g_autoptr(GDateTime) latest_timestamp = NULL;
  gsize idx;

  g_debug ("%s: source_to_update mapping:", G_STRFUNC);

  g_hash_table_iter_init (&iter, source_to_update);
  while (g_hash_table_iter_next (&iter, &name_ptr, &update_ptr))
    {
      EosUpdateInfo *update = update_ptr;
      g_autofree gchar *update_string = eos_update_info_to_string (update);
      gint compare_value = 1;
      g_autoptr(GDateTime) update_timestamp = NULL;

      g_debug ("%s: - %s: %s", G_STRFUNC, (const gchar *) name_ptr, update_string);

      update_timestamp = eos_update_info_get_commit_timestamp (update);

      if (latest_timestamp != NULL)
        compare_value = g_date_time_compare (update_timestamp,
                                             latest_timestamp);
      if (compare_value > 0)
        {
          g_clear_pointer (&latest_timestamp, g_date_time_unref);
          latest_timestamp = g_date_time_ref (update_timestamp);
          g_hash_table_remove_all (latest);
          compare_value = 0;
        }

      if (compare_value == 0)
        g_hash_table_insert (latest, name_ptr, update_ptr);
    }

  g_debug ("%s: sources list:", G_STRFUNC);

  for (idx = 0; idx < sources->len; ++idx)
    {
      EosUpdaterDownloadSource source = g_array_index (sources,
                                                       EosUpdaterDownloadSource,
                                                       idx);
      const gchar *name = download_source_to_string (source);
      EosUpdateInfo *update = g_hash_table_lookup (latest, name);

      if (update != NULL)
        {
          g_debug ("%s: - %s (matched)", G_STRFUNC, name);
          return update;
        }
      else
        {
          g_debug ("%s: - %s", G_STRFUNC, name);
        }
    }

  return NULL;
}
示例#25
0
static gboolean
parse_epg_dat_line (Request   *req,
                    gchar     *line,
                    GPtrArray *events)
{
  gchar *duration_s, *start_time_s, *end_time_s, *date_s;
  gboolean start_in_between, end_in_between, englobing;
  gint year, month, day, hours, minutes, duration;
  GDateTime *start_date, *end_date;
  gint n_parsed;

  duration_s = cut_last_field_out (line);
  if (duration_s == NULL)
    goto no_duration;

  end_time_s = cut_last_field_out (line);
  if (end_time_s == NULL)
    goto no_end_time;

  start_time_s = cut_last_field_out (line);
  if (start_time_s == NULL)
    goto no_start_time;

  date_s = cut_last_field_out (line);
  if (date_s == NULL)
    goto no_date;

  n_parsed = sscanf (date_s, "%d/%d/%d", &day, &month, &year);
  if (n_parsed != 3)
    goto scanf_failed;

  n_parsed = sscanf (start_time_s, "%d:%d", &hours, &minutes);
  if (n_parsed != 2)
    goto scanf_failed;

  duration = atoi (duration_s);
  if (duration == 0)
    return TRUE;

  /* duration is always is seconds in Mex, minutes in the data files */
  duration *= 60;

  start_date = g_date_time_new_local (year, month, day, hours, minutes, 0);
  end_date = g_date_time_add_seconds (start_date, duration);

  start_in_between = g_date_time_compare (start_date, req->start_date) >= 0
		     && g_date_time_compare (start_date, req->end_date) <= 0;
  end_in_between = g_date_time_compare (end_date, req->start_date) >= 0 &&
		   g_date_time_compare (end_date, req->end_date) <= 0;
  englobing = g_date_time_compare (start_date, req->start_date) <= 0 &&
              g_date_time_compare (end_date, req->end_date) >= 0;

  if (start_in_between || end_in_between || englobing)
    {
      MexEpgEvent *event;
      MexProgram *program;

      event = mex_epg_event_new_with_date_time (start_date, duration);

      program = parse_program (line);
      if (program == NULL)
        goto program_failed;

      /* we add the duration here as parse_program don't do it and that we
       * need the duration in seconds instead of minutes */
      duration_s = g_strdup_printf ("%d", duration);
      mex_program_set_metadata (program,
                                MEX_CONTENT_METADATA_DURATION,
                                duration_s);
      g_free (duration_s);

      mex_epg_event_set_program (event, program);
      g_object_unref (program);

      mex_epg_event_set_channel (event, req->channel);

      g_ptr_array_add (events, event);
    }

  return TRUE;

program_failed:
  MEX_WARN (EPG, "could not create the program: %s", line);
  return FALSE;
scanf_failed:
  MEX_WARN (EPG, "could not parse date or time: %s", line);
  return FALSE;
no_date:
  MEX_WARN (EPG, "could not find the date: %s", line);
  return FALSE;
no_start_time:
  MEX_WARN (EPG, "could not find the start time: %s", line);
  return FALSE;
no_end_time:
  MEX_WARN (EPG, "could not find the end time: %s", line);
  return FALSE;
no_duration:
  MEX_WARN (EPG, "could not find the duration: %s", line);
  return FALSE;
}