gboolean nautilus_file_date_in_between (guint64 unix_file_time, GDateTime *initial_date, GDateTime *end_date) { GDateTime *date; gboolean in_between; /* Silently ignore errors */ if (unix_file_time == 0) { return FALSE; } date = g_date_time_new_from_unix_local (unix_file_time); /* For the end date, we want to make end_date inclusive, * for that the difference between the start of the day and the in_between * has to be more than -1 day */ in_between = g_date_time_difference (date, initial_date) > 0 && g_date_time_difference (end_date, date) / G_TIME_SPAN_DAY > -1; g_date_time_unref (date); return in_between; }
static void fire_or_rearm_alarm (GoaAlarm *self) { GTimeSpan time_until_fire; GTimeSpan previous_time_until_fire; GDateTime *now; now = g_date_time_new_now_local (); time_until_fire = g_date_time_difference (self->priv->time, now); if (self->priv->previous_wakeup_time == NULL) { self->priv->previous_wakeup_time = now; /* If, according to the time, we're past when we should have fired, * then fire the alarm. */ if (time_until_fire <= 0) fire_alarm (self); } else { previous_time_until_fire = g_date_time_difference (self->priv->time, self->priv->previous_wakeup_time); g_date_time_unref (self->priv->previous_wakeup_time); self->priv->previous_wakeup_time = now; /* If, according to the time, we're past when we should have fired, * and this is the first wakeup where that's been true then fire * the alarm. The first check makes sure we don't fire prematurely, * and the second check makes sure we don't fire more than once */ if (time_until_fire <= 0 && previous_time_until_fire > 0) { fire_alarm (self); /* If, according to the time, we're before when we should fire, * and we previously fired the alarm, then we've jumped back in * time and need to rearm the alarm. */ } else if (time_until_fire > 0 && previous_time_until_fire <= 0) { rearm_alarm (self); } } }
static guint calculate_seconds_until_next_minute (void) { guint seconds; GTimeSpan diff; GDateTime * now; GDateTime * next; GDateTime * start_of_next; now = g_date_time_new_now_local (); next = g_date_time_add_minutes (now, 1); start_of_next = g_date_time_new_local (g_date_time_get_year (next), g_date_time_get_month (next), g_date_time_get_day_of_month (next), g_date_time_get_hour (next), g_date_time_get_minute (next), 1); diff = g_date_time_difference (start_of_next, now); seconds = (diff + (G_TIME_SPAN_SECOND - 1)) / G_TIME_SPAN_SECOND; /* cleanup */ g_date_time_unref (start_of_next); g_date_time_unref (next); g_date_time_unref (now); return seconds; }
static int _manual_pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t * const stanza, void * const userdata) { char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); char *type = xmpp_stanza_get_type(stanza); // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); handle_ping_error_result(from, error_message); free(error_message); return 0; } GDateTime *sent = (GDateTime *)userdata; GDateTime *now = g_date_time_new_now_local(); GTimeSpan elapsed = g_date_time_difference(now, sent); int elapsed_millis = elapsed / 1000; g_date_time_unref(sent); g_date_time_unref(now); handle_ping_result(from, elapsed_millis); return 0; }
/** * calculate and assign the surface interval between dives */ dif_dive_collection_t *dif_dive_collection_calculate_surface_interval(dif_dive_collection_t *dc) { dc = dif_dive_collection_sort_dives(dc); GList *dives = dc->dives; dif_dive_t *previousDive = NULL; while (dives != NULL) { dif_dive_t *thisDive = dives->data; if (thisDive->duration == 0 && thisDive->samples) { thisDive = dif_dive_sort_samples(thisDive); dif_sample_t *firstSample = g_list_first(thisDive->samples)->data; dif_sample_t *lastSample = g_list_last(thisDive->samples)->data; thisDive->duration = lastSample->timestamp - firstSample->timestamp; } if (previousDive == NULL) { thisDive->surfaceInterval = -1; } else { GDateTime *previousTime = previousDive->datetime; previousTime = g_date_time_add_seconds(previousTime, previousDive->duration); GTimeSpan diff = g_date_time_difference(thisDive->datetime, previousTime); thisDive->surfaceInterval = diff/G_TIME_SPAN_SECOND; if (thisDive->surfaceInterval > SURFACE_INTERVAL_MAX) { thisDive->surfaceInterval = -1; } } previousDive = thisDive; dives = g_list_next(dives); } return dc; }
gchar* mathg_my_timer_to_string (mathgMyTimer *self) { gchar* result = NULL; GDateTime* _tmp0_ = NULL; gchar* s = NULL; GDateTime* _tmp1_ = NULL; GDateTime* _tmp2_ = NULL; GTimeSpan _tmp3_ = 0LL; gchar* _tmp4_ = NULL; GDateTime* _tmp5_ = NULL; gboolean _tmp6_ = FALSE; GDateTime* _tmp9_ = NULL; _tmp0_ = g_date_time_new_now_local (); _g_date_time_unref0 ((*self).stop); (*self).stop = _tmp0_; _tmp1_ = (*self).stop; _tmp2_ = (*self).start; _tmp3_ = g_date_time_difference (_tmp1_, _tmp2_); _tmp4_ = g_strdup_printf ("%" G_GINT64_FORMAT, (gint64) ((_tmp3_ + 500L) / 1000L)); s = _tmp4_; _tmp6_ = (*self).reset; if (_tmp6_) { GDateTime* _tmp7_ = NULL; _tmp7_ = (*self).stop; _tmp5_ = _tmp7_; } else { GDateTime* _tmp8_ = NULL; _tmp8_ = (*self).start; _tmp5_ = _tmp8_; } _tmp9_ = _g_date_time_ref0 (_tmp5_); _g_date_time_unref0 ((*self).start); (*self).start = _tmp9_; result = s; return result; }
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 }
gchar * get_text_for_date_range (GPtrArray *date_range, gboolean prefix_with_since) { gint days; gint normalized; GDateTime *initial_date; GDateTime *end_date; gchar *formatted_date; gchar *label; if (!date_range) { return NULL; } initial_date = g_ptr_array_index (date_range, 0); end_date = g_ptr_array_index (date_range, 1); days = g_date_time_difference (end_date, initial_date) / G_TIME_SPAN_DAY; formatted_date = g_date_time_format (initial_date, "%x"); if (days < 1) { label = g_strdup (formatted_date); } else { if (days < 7) { /* days */ normalized = days; } else if (days < 30) { /* weeks */ normalized = days / 7; } else if (days < 365) { /* months */ normalized = days / 30; } else { /* years */ normalized = days / 365; } #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-nonliteral" label = g_strdup_printf (get_text_for_days_ago (days, prefix_with_since), normalized); #pragma GCC diagnostic pop } g_free (formatted_date); return label; }
static void time_converter(GBinding* bind, const GValue* from, GValue* to, gpointer udata) { gchar* label = NULL; GDateTime* now_time; GDateTime* stream_started_time; GTimeSpan dif; if (g_value_get_pointer(from) != NULL) { now_time = g_date_time_new_now_utc(); stream_started_time = (GDateTime*) g_value_get_pointer(from); dif = g_date_time_difference(now_time, stream_started_time); if (dif > G_TIME_SPAN_HOUR) label = g_strdup_printf("%2.1fh", (gdouble) dif / G_TIME_SPAN_HOUR); else label = g_strdup_printf("%ldm", dif / G_TIME_SPAN_MINUTE); g_date_time_unref(now_time); } g_value_take_string(to, label); }
static void mex_epg_grid_get_preferred_width (ClutterActor *actor, gfloat for_height, gfloat *min_width_p, gfloat *nat_width_p) { MexEpgGrid *grid = MEX_EPG_GRID (actor); MexEpgGridPrivate *priv = grid->priv; MxPadding padding; GTimeSpan diff; mx_widget_get_padding (MX_WIDGET (actor), &padding); if (priv->first_date == NULL || priv->last_date == NULL) diff = 0; else diff = g_date_time_difference (priv->last_date, priv->first_date); if (min_width_p) *min_width_p = 0; if (nat_width_p) *nat_width_p = time_span_to_pixels (grid, diff) + padding.left + padding.right; }
static void show_week_label (UmHistoryDialog *um) { gchar *label, *from, *to; GDateTime *date; GTimeSpan span; span = g_date_time_difference (um->current_week, um->week); if (span == 0) { label = g_strdup (_("This Week")); } else if (span == G_TIME_SPAN_DAY * 7) { label = g_strdup (_("Last Week")); } else { date = g_date_time_add_days (um->week, 6); from = g_date_time_format (um->week, "%b %e"); if (g_date_time_get_year (um->week) == g_date_time_get_year (um->current_week)) { to = g_date_time_format (date, "%b %e"); } else { to = g_date_time_format (date, "%b %e, %Y"); } label = g_strconcat (from, " - ", to, NULL); g_date_time_unref (date); g_free (from); g_free (to); } gtk_label_set_label (GTK_LABEL (get_widget (um, "week-label")), label); g_free (label); }
void print_days_until_birthday (void) { /*Calculate how many days there are between now and my birthday. (If you get something out of this glib-cookbook then feel free to send me a present after that many days go by. ;) */ GTimeZone *tz; GDateTime *now; GDateTime *bday; GTimeSpan diff; tz = (GTimeZone *)g_time_zone_new_local(); now = (GDateTime *)g_date_time_new_now(tz); bday = (GDateTime *)g_date_time_new(tz, g_date_time_get_year(now) + 1, 6, 25, 0, 0, 0); diff = g_date_time_difference(bday, now); g_print("There are %ld days until Jamil's birthday.\n", diff / G_TIME_SPAN_DAY); g_date_time_unref(now); g_date_time_unref(bday); g_time_zone_unref(tz); }
static void chat_text_maybe_append_date_and_time (EmpathyChatTextView *view, gint64 timestamp) { EmpathyChatTextViewPriv *priv = GET_PRIV (view); GDateTime *date, *last_date; gboolean append_date = FALSE; gboolean append_time = FALSE; GTimeSpan delta; /* Get the date from last message */ last_date = g_date_time_new_from_unix_utc (priv->last_timestamp); /* Get the date of the message we are appending */ date = g_date_time_new_from_unix_utc (timestamp); delta = g_date_time_difference (date, last_date); /* If last message was from another day we append date and time */ if (delta >= G_TIME_SPAN_DAY) { append_date = TRUE; append_time = TRUE; } g_date_time_unref (last_date); g_date_time_unref (date); /* If last message is 'old' append the time */ if (delta >= TIMESTAMP_INTERVAL) { append_time = TRUE; } if (append_date || (!priv->only_if_date && append_time)) { chat_text_view_append_timestamp (view, timestamp, append_date); } }
static void schedule_wakeups_with_timeout_source (GoaAlarm *self) { GDateTime *now; GSource *source; GTimeSpan time_span; guint interval; self->priv->type = GOA_ALARM_TYPE_TIMEOUT; now = g_date_time_new_now_local (); time_span = g_date_time_difference (self->priv->time, now); g_date_time_unref (now); time_span = CLAMP (time_span, 1000 *G_TIME_SPAN_MILLISECOND, G_MAXUINT *G_TIME_SPAN_MILLISECOND); interval = (guint) time_span / G_TIME_SPAN_MILLISECOND; /* We poll every 10 seconds or so because we want to catch time skew */ interval = MIN (interval, MAX_TIMEOUT_INTERVAL); source = g_timeout_source_new (interval); self->priv->scheduled_wakeup_source = source; g_source_set_callback (self->priv->scheduled_wakeup_source, (GSourceFunc) on_timeout_source_ready, self, (GDestroyNotify) clear_wakeup_source_pointer); g_source_attach (self->priv->scheduled_wakeup_source, self->priv->context); g_source_unref (source); }
/** * 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; }
/* * Formulas taken from https://www.esrl.noaa.gov/gmd/grad/solcalc/calcdetails.html * * The returned values are fractional hours, so 6am would be 6.0 and 4:30pm * would be 16.5. * * The values returned by this function might not make sense for locations near * the polar regions. For example, in the north of Lapland there might not be * a sunrise at all. */ gboolean gsd_night_light_get_sunrise_sunset (GDateTime *dt, gdouble pos_lat, gdouble pos_long, gdouble *sunrise, gdouble *sunset) { g_autoptr(GDateTime) dt_zero = g_date_time_new_utc (1900, 1, 1, 0, 0, 0); GTimeSpan ts = g_date_time_difference (dt, dt_zero); g_return_val_if_fail (pos_lat <= 90.f && pos_lat >= -90.f, FALSE); g_return_val_if_fail (pos_long <= 180.f && pos_long >= -180.f, FALSE); gdouble tz_offset = (gdouble) g_date_time_get_utc_offset (dt) / G_USEC_PER_SEC / 60 / 60; // B5 gdouble date_as_number = ts / G_USEC_PER_SEC / 24 / 60 / 60 + 2; // B7 gdouble time_past_local_midnight = 0; // E2, unused in this calculation gdouble julian_day = date_as_number + 2415018.5 + time_past_local_midnight - tz_offset / 24; gdouble julian_century = (julian_day - 2451545) / 36525; gdouble geom_mean_long_sun = fmod (280.46646 + julian_century * (36000.76983 + julian_century * 0.0003032), 360); // I2 gdouble geom_mean_anom_sun = 357.52911 + julian_century * (35999.05029 - 0.0001537 * julian_century); // J2 gdouble eccent_earth_orbit = 0.016708634 - julian_century * (0.000042037 + 0.0000001267 * julian_century); // K2 gdouble sun_eq_of_ctr = sin (deg2rad (geom_mean_anom_sun)) * (1.914602 - julian_century * (0.004817 + 0.000014 * julian_century)) + sin (deg2rad (2 * geom_mean_anom_sun)) * (0.019993 - 0.000101 * julian_century) + sin (deg2rad (3 * geom_mean_anom_sun)) * 0.000289; // L2 gdouble sun_true_long = geom_mean_long_sun + sun_eq_of_ctr; // M2 gdouble sun_app_long = sun_true_long - 0.00569 - 0.00478 * sin (deg2rad (125.04 - 1934.136 * julian_century)); // P2 gdouble mean_obliq_ecliptic = 23 + (26 + ((21.448 - julian_century * (46.815 + julian_century * (0.00059 - julian_century * 0.001813)))) / 60) / 60; // Q2 gdouble obliq_corr = mean_obliq_ecliptic + 0.00256 * cos (deg2rad (125.04 - 1934.136 * julian_century)); // R2 gdouble sun_declin = rad2deg (asin (sin (deg2rad (obliq_corr)) * sin (deg2rad (sun_app_long)))); // T2 gdouble var_y = tan (deg2rad (obliq_corr/2)) * tan (deg2rad (obliq_corr / 2)); // U2 gdouble eq_of_time = 4 * rad2deg (var_y * sin (2 * deg2rad (geom_mean_long_sun)) - 2 * eccent_earth_orbit * sin (deg2rad (geom_mean_anom_sun)) + 4 * eccent_earth_orbit * var_y * sin (deg2rad (geom_mean_anom_sun)) * cos (2 * deg2rad (geom_mean_long_sun)) - 0.5 * var_y * var_y * sin (4 * deg2rad (geom_mean_long_sun)) - 1.25 * eccent_earth_orbit * eccent_earth_orbit * sin (2 * deg2rad (geom_mean_anom_sun))); // V2 gdouble ha_sunrise = rad2deg (acos (cos (deg2rad (90.833)) / (cos (deg2rad (pos_lat)) * cos (deg2rad (sun_declin))) - tan (deg2rad (pos_lat)) * tan (deg2rad (sun_declin)))); // W2 gdouble solar_noon = (720 - 4 * pos_long - eq_of_time + tz_offset * 60) / 1440; // X2 gdouble sunrise_time = solar_noon - ha_sunrise * 4 / 1440; // Y2 gdouble sunset_time = solar_noon + ha_sunrise * 4 / 1440; // Z2 /* convert to hours */ if (sunrise != NULL) *sunrise = sunrise_time * 24; if (sunset != NULL) *sunset = sunset_time * 24; return TRUE; }
/** * CacheUtilCheckDuration: * @check_date: Date that may or may not fall inside @duration. * @duration: Timespan for @check_date to fall in. * @start_date: Start of @duration. * * Returns: #TRUE if @start_date <= @check_date <= @start_date + @duration. */ gboolean CacheUtilCheckDuration(GDateTime *check_date, GTimeSpan duration, GDateTime *start_date) { GTimeSpan date_diff = g_date_time_difference(check_date, start_date); if (date_diff >= 0 && date_diff <= duration) { return TRUE; } else { return FALSE; } }
static void create_header (MexEpgGrid *grid) { MexEpgGridPrivate *priv = grid->priv; GTimeSpan diff; GDateTime *time_, *old_time; gint n_headers, i; gchar *time_str; diff = g_date_time_difference (priv->last_date, priv->first_date); n_headers = (diff * 1e-6 / 60. / 30) + 1; /* number of 30mins slices */ if (MEX_DEBUG_ENABLED (EPG)) { gchar *first_str, *last_str; first_str = mex_date_to_string (priv->first_date); last_str = mex_date_to_string (priv->last_date); MEX_NOTE (EPG, "Creating header between %s and %s (%d columns)", first_str, last_str, n_headers); g_free (first_str); g_free (last_str); } g_ptr_array_set_size (priv->header, n_headers); time_ = g_date_time_ref (priv->first_date); for (i = 0; i < n_headers; i++) { ClutterActor *frame, *label; /* a Frame for 30 mins, each frame has a label in it */ frame = mx_frame_new (); clutter_actor_set_parent (frame, CLUTTER_ACTOR (grid)); mx_stylable_set_style_class (MX_STYLABLE (frame), "EpgHeader"); clutter_actor_set_size (frame, 6 * priv->pixels_for_5_mins, HEADER_HEIGHT); time_str = g_date_time_format (time_, "%H:%M"); label = mx_label_new_with_text (time_str); mx_bin_set_child (MX_BIN (frame), label); mx_bin_set_alignment (MX_BIN (frame), MX_ALIGN_START, MX_ALIGN_MIDDLE); g_ptr_array_index (priv->header, i) = frame; g_free (time_str); old_time = time_; time_ = g_date_time_add_minutes (time_, 30); g_date_time_unref (old_time); } g_date_time_unref (time_); }
void sv_ev_roster_received(void) { if (prefs_get_boolean(PREF_ROSTER)) { ui_show_roster(); } char *account_name = session_get_account_name(); #ifdef HAVE_LIBGPGME // check pgp key valid if specified ProfAccount *account = accounts_get_account(account_name); if (account && account->pgp_keyid) { char *err_str = NULL; if (!p_gpg_valid_key(account->pgp_keyid, &err_str)) { cons_show_error("Invalid PGP key ID specified: %s, %s", account->pgp_keyid, err_str); } free(err_str); } account_free(account); #endif // send initial presence resource_presence_t conn_presence = accounts_get_login_presence(account_name); char *last_activity_str = accounts_get_last_activity(account_name); if (last_activity_str) { GDateTime *nowdt = g_date_time_new_now_utc(); GTimeVal lasttv; gboolean res = g_time_val_from_iso8601(last_activity_str, &lasttv); if (res) { GDateTime *lastdt = g_date_time_new_from_timeval_utc(&lasttv); GTimeSpan diff_micros = g_date_time_difference(nowdt, lastdt); int diff_secs = (diff_micros / 1000) / 1000; if (prefs_get_boolean(PREF_LASTACTIVITY)) { cl_ev_presence_send(conn_presence, NULL, diff_secs); } else { cl_ev_presence_send(conn_presence, NULL, 0); } g_date_time_unref(lastdt); } else { cl_ev_presence_send(conn_presence, NULL, 0); } free(last_activity_str); g_date_time_unref(nowdt); } else { cl_ev_presence_send(conn_presence, NULL, 0); } const char *fulljid = connection_get_fulljid(); plugins_on_connect(account_name, fulljid); }
static void age_renderer_func (GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data) { GtkRecentInfo *ri = NULL; GDateTime *now = user_data; GDateTime *last_used; GTimeSpan age; char *text; const char *date_format; const char *p; gtk_tree_model_get (model, iter, RECENT_COL_INFO, &ri, -1); last_used = g_date_time_new_from_unix_local (gtk_recent_info_get_modified (ri)); gtk_recent_info_unref (ri); age = g_date_time_difference (now, last_used); if (age < G_TIME_SPAN_DAY && g_date_time_get_day_of_month (now) == g_date_time_get_day_of_month (last_used)) { if (go_locale_24h ()) /* * xgettext: This is a time format for * g_date_time_format used in locales that use a * 24 hour clock. You probably do not need to change * this. The default will show things like "09:50" * and "21:50". */ date_format = _("%H:%M"); else /* * xgettext: This is a time format for * g_date_time_format used in locales that use * a 12 hour clock. You probably do not need * to change this. The default will show * things like " 9:50 am" and " 9:50 pm". */ date_format = _("%l:%M %P"); } else { date_format = "%x"; } p = text = g_date_time_format (last_used, date_format); while (g_ascii_isspace (*p)) p++; g_object_set (cell, "text", p, "xalign", 0.5, NULL); g_free (text); g_date_time_unref (last_used); }
void win_show_status_string(ProfWin *window, const char * const from, const char * const show, const char * const status, GDateTime *last_activity, const char * const pre, const char * const default_show) { theme_item_t presence_colour; if (show != NULL) { presence_colour = theme_main_presence_attrs(show); } else if (strcmp(default_show, "online") == 0) { presence_colour = THEME_ONLINE; } else { presence_colour = THEME_OFFLINE; } win_save_vprint(window, '-', NULL, NO_EOL, presence_colour, "", "%s %s", pre, from); if (show != NULL) win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", show); else win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", default_show); if (last_activity != NULL) { GDateTime *now = g_date_time_new_now_local(); GTimeSpan span = g_date_time_difference(now, last_activity); g_date_time_unref(now); int hours = span / G_TIME_SPAN_HOUR; span = span - hours * G_TIME_SPAN_HOUR; int minutes = span / G_TIME_SPAN_MINUTE; span = span - minutes * G_TIME_SPAN_MINUTE; int seconds = span / G_TIME_SPAN_SECOND; if (hours > 0) { win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dh%dm%ds", hours, minutes, seconds); } else { win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dm%ds", minutes, seconds); } } if (status != NULL) win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", status); win_save_print(window, '-', NULL, NO_DATE, presence_colour, "", ""); }
/** * Ends the clock and prints the elapsed time and then frees everything * @param my_clock is a clock_t * structure with begin already filled * @param message is a message that we want to include into the displayed * result in order to know what was measured. */ void end_clock(a_clock_t *my_clock, gchar *message) { GTimeSpan difference = 0; if (my_clock != NULL && my_clock->begin != NULL) { my_clock->end = g_date_time_new_now_local(); difference = g_date_time_difference(my_clock->end, my_clock->begin); g_date_time_unref(my_clock->begin); g_date_time_unref(my_clock->end); free_variable(my_clock); print_debug(_("Elapsed time (%s): %d µs\n"), message, difference); } }
void win_show_contact(ProfWin *window, PContact contact) { const char *barejid = p_contact_barejid(contact); const char *name = p_contact_name(contact); const char *presence = p_contact_presence(contact); const char *status = p_contact_status(contact); GDateTime *last_activity = p_contact_last_activity(contact); win_print_time(window, '-'); win_presence_colour_on(window, presence); if (name != NULL) { wprintw(window->win, "%s", name); } else { wprintw(window->win, "%s", barejid); } wprintw(window->win, " is %s", presence); if (last_activity != NULL) { GDateTime *now = g_date_time_new_now_local(); GTimeSpan span = g_date_time_difference(now, last_activity); wprintw(window->win, ", idle "); int hours = span / G_TIME_SPAN_HOUR; span = span - hours * G_TIME_SPAN_HOUR; if (hours > 0) { wprintw(window->win, "%dh", hours); } int minutes = span / G_TIME_SPAN_MINUTE; span = span - minutes * G_TIME_SPAN_MINUTE; wprintw(window->win, "%dm", minutes); int seconds = span / G_TIME_SPAN_SECOND; wprintw(window->win, "%ds", seconds); } if (status != NULL) { wprintw(window->win, ", \"%s\"", p_contact_status(contact)); } wprintw(window->win, "\n"); win_presence_colour_off(window, presence); }
void win_show_contact(ProfWin *window, PContact contact) { const char *barejid = p_contact_barejid(contact); const char *name = p_contact_name(contact); const char *presence = p_contact_presence(contact); const char *status = p_contact_status(contact); GDateTime *last_activity = p_contact_last_activity(contact); theme_item_t presence_colour = theme_main_presence_attrs(presence); if (name) { win_print(window, '-', 0, NULL, NO_EOL, presence_colour, "", name); } else { win_print(window, '-', 0, NULL, NO_EOL, presence_colour, "", barejid); } win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence); if (last_activity) { GDateTime *now = g_date_time_new_now_local(); GTimeSpan span = g_date_time_difference(now, last_activity); g_date_time_unref(now); int hours = span / G_TIME_SPAN_HOUR; span = span - hours * G_TIME_SPAN_HOUR; int minutes = span / G_TIME_SPAN_MINUTE; span = span - minutes * G_TIME_SPAN_MINUTE; int seconds = span / G_TIME_SPAN_SECOND; if (hours > 0) { win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dh%dm%ds", hours, minutes, seconds); } else { win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dm%ds", minutes, seconds); } } if (status) { win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", p_contact_status(contact)); } win_print(window, '-', 0, NULL, NO_DATE, presence_colour, "", ""); }
void CalendarDatePrivate::applyDateBrowseAction(int yearChange, int monthChange) { GtkWidget* swipebox = NULL; switch (m_viewType) { case VIEWTYPE_DAY: swipebox = m_swipeBox[0]; break; case VIEWTYPE_MONTH: swipebox = m_swipeBox[1]; break; case VIEWTYPE_YEAR: swipebox = m_swipeBox[2]; break; default: break; } g_return_if_fail(NULL != swipebox); gint oldYear = m_selectedYear; gint oldMonth = m_selectedMonth; gint oldDayOfMonth = m_selectedDayOfMonth; gint newMonth = oldMonth + monthChange; if (12 < newMonth) { yearChange = yearChange + 1; newMonth = 1; } else if (1 > newMonth) { yearChange = yearChange - 1; newMonth = 12; } gint newYear = oldYear + yearChange; gint newDayOfMonth = oldDayOfMonth; int newMonthLength = month_length[leap(newYear)][newMonth]; if (newMonthLength < newDayOfMonth) { newDayOfMonth = newMonthLength; } GDateTime * oldDate = g_date_time_new_local(oldYear, oldMonth, oldDayOfMonth, 0, 0, 0); GDateTime * newDate = g_date_time_new_local(newYear, newMonth, newDayOfMonth, 0, 0, 0); setDate(newDate, FALSE, g_date_time_difference(oldDate, newDate)); g_date_time_unref(newDate); g_date_time_unref(oldDate); }
static gboolean should_purge_file (GFile *file, GCancellable *cancellable, GDateTime *old) { GFileInfo *info; GDateTime *date; gboolean should_purge; should_purge = FALSE; info = g_file_query_info (file, G_FILE_ATTRIBUTE_TRASH_DELETION_DATE "," G_FILE_ATTRIBUTE_UNIX_UID "," G_FILE_ATTRIBUTE_TIME_CHANGED, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, NULL); date = g_file_info_get_deletion_date (info); if (date == NULL) { guint uid; guint64 ctime; uid = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_UID); if (uid != getuid ()) { should_purge = FALSE; goto out; } ctime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_CHANGED); date = g_date_time_new_from_unix_local ((gint64) ctime); } should_purge = g_date_time_difference (old, date) >= 0; g_date_time_unref (date); out: g_object_unref (info); return should_purge; }
char * cc_util_get_smart_date (GDateTime *date) { gchar *label; GDateTime *today, *local; GTimeSpan span; /* Set today date */ local = g_date_time_new_now_local (); today = g_date_time_new_local (g_date_time_get_year (local), g_date_time_get_month (local), g_date_time_get_day_of_month (local), 0, 0, 0); span = g_date_time_difference (today, date); if (span <= 0) { label = g_strdup (_("Today")); } else if (span <= G_TIME_SPAN_DAY) { label = g_strdup (_("Yesterday")); } else { if (g_date_time_get_year (date) == g_date_time_get_year (today)) { /* Translators: This is a date format string in the style of "Feb 24". */ label = g_date_time_format (date, _("%b %e")); } else { /* Translators: This is a date format string in the style of "Feb 24, 2013". */ label = g_date_time_format (date, _("%b %e, %Y")); } } g_date_time_unref (local); g_date_time_unref (today); return label; }
static GstClockTime get_time (GstRTSPRangeUnit unit, const GstRTSPTime * t1, const GstRTSPTime2 * t2) { GstClockTime res; switch (t1->type) { case GST_RTSP_TIME_SECONDS: { res = get_seconds (t1); break; } case GST_RTSP_TIME_UTC: { GDateTime *dt, *bt; GTimeSpan span; /* make time base, we use 1900 */ bt = g_date_time_new_utc (1900, 1, 1, 0, 0, 0.0); /* convert to GDateTime without the seconds */ dt = g_date_time_new_utc (t2->year, t2->month, t2->day, 0, 0, 0.0); /* get amount of microseconds */ span = g_date_time_difference (dt, bt); g_date_time_unref (bt); g_date_time_unref (dt); /* add seconds */ res = get_seconds (t1) + (span * 1000); break; } case GST_RTSP_TIME_FRAMES: res = get_seconds (t1); res += get_frames (t2, unit); break; default: case GST_RTSP_TIME_NOW: case GST_RTSP_TIME_END: res = GST_CLOCK_TIME_NONE; break; } return res; }
static void update_last_used (CEPageDetails *page, NMConnection *connection) { gchar *last_used = NULL; GDateTime *now = NULL; GDateTime *then = NULL; gint days; GTimeSpan diff; guint64 timestamp; NMSettingConnection *s_con; s_con = nm_connection_get_setting_connection (connection); if (s_con == NULL) goto out; timestamp = nm_setting_connection_get_timestamp (s_con); if (timestamp == 0) { last_used = g_strdup (_("Never")); goto out; } /* calculate the amount of time that has elapsed */ now = g_date_time_new_now_utc (); then = g_date_time_new_from_unix_utc (timestamp); diff = g_date_time_difference (now, then); days = diff / G_TIME_SPAN_DAY; if (days == 0) last_used = g_strdup (_("Today")); else if (days == 1) last_used = g_strdup (_("Yesterday")); else last_used = g_strdup_printf (ngettext ("%i day ago", "%i days ago", days), days); out: panel_set_device_widget_details (CE_PAGE (page)->builder, "last_used", last_used); if (now != NULL) g_date_time_unref (now); if (then != NULL) g_date_time_unref (then); g_free (last_used); }
static gchar * get_last_used_string (NMConnection *connection) { gchar *last_used = NULL; GDateTime *now = NULL; GDateTime *then = NULL; gint days; GTimeSpan diff; guint64 timestamp; NMSettingConnection *s_con; s_con = nm_connection_get_setting_connection (connection); if (s_con == NULL) goto out; timestamp = nm_setting_connection_get_timestamp (s_con); if (timestamp == 0) { last_used = g_strdup (_("never")); goto out; } /* calculate the amount of time that has elapsed */ now = g_date_time_new_now_utc (); then = g_date_time_new_from_unix_utc (timestamp); diff = g_date_time_difference (now, then); days = diff / G_TIME_SPAN_DAY; if (days == 0) last_used = g_strdup (_("today")); else if (days == 1) last_used = g_strdup (_("yesterday")); else last_used = g_strdup_printf (ngettext ("%i day ago", "%i days ago", days), days); out: if (now != NULL) g_date_time_unref (now); if (then != NULL) g_date_time_unref (then); return last_used; }