diff options
Diffstat (limited to 'libcaja-private/caja-file.c')
-rw-r--r-- | libcaja-private/caja-file.c | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/libcaja-private/caja-file.c b/libcaja-private/caja-file.c index 694e5dd4..ea8486e8 100644 --- a/libcaja-private/caja-file.c +++ b/libcaja-private/caja-file.c @@ -4808,40 +4808,32 @@ caja_file_fit_date_as_string (CajaFile *file, void *measure_context) { time_t file_time_raw; - struct tm *file_time; const char **formats; const char *width_template; const char *format; char *date_string; - char *result; - GDate *today; - GDate *file_date; - guint32 file_date_age; + gchar *result = NULL; int i; + GDateTime *date_time, *today; + GTimeSpan file_date_age; if (!caja_file_get_date (file, date_type, &file_time_raw)) { return NULL; } - file_time = localtime (&file_time_raw); + date_time = g_date_time_new_from_unix_local (file_time_raw); if (date_format_pref == CAJA_DATE_FORMAT_LOCALE) { - return eel_strdup_strftime ("%c", file_time); + result = g_date_time_format (date_time, "%c"); + goto out; } else if (date_format_pref == CAJA_DATE_FORMAT_ISO) { - return eel_strdup_strftime ("%Y-%m-%d %H:%M:%S", file_time); + result = g_date_time_format (date_time, "%Y-%m-%d %H:%M:%S"); + goto out; } - file_date = eel_g_date_new_tm (file_time); - - today = g_date_new (); - g_date_set_time_t (today, time (NULL)); - - /* Overflow results in a large number; fine for our purposes. */ - file_date_age = (g_date_get_julian (today) - - g_date_get_julian (file_date)); - - g_date_free (file_date); - g_date_free (today); + today = g_date_time_new_now_local (); + file_date_age = g_date_time_difference (today, date_time); + g_date_time_unref (today); /* Format varies depending on how old the date is. This minimizes * the length (and thus clutter & complication) of typical dates @@ -4851,9 +4843,9 @@ caja_file_fit_date_as_string (CajaFile *file, * internationalization's sake. */ - if (file_date_age == 0) { + if (file_date_age < G_TIME_SPAN_DAY) { formats = TODAY_TIME_FORMATS; - } else if (file_date_age == 1) { + } else if (file_date_age < 2 * G_TIME_SPAN_DAY) { formats = YESTERDAY_TIME_FORMATS; } else { formats = CURRENT_WEEK_TIME_FORMATS; @@ -4876,15 +4868,16 @@ caja_file_fit_date_as_string (CajaFile *file, * shortest format */ - date_string = eel_strdup_strftime (format, file_time); + date_string = g_date_time_format (date_time, format); if (truncate_callback == NULL) { - return date_string; + result = date_string; + break; } result = (* truncate_callback) (date_string, width, measure_context); g_free (date_string); - return result; + break; } format = _(formats [i + 1]); @@ -4900,8 +4893,13 @@ caja_file_fit_date_as_string (CajaFile *file, } } - return eel_strdup_strftime (format, file_time); + if (result == NULL) { + result = g_date_time_format (date_time, format); + } +out: + g_date_time_unref (date_time); + return result; } /** |