summaryrefslogtreecommitdiff
path: root/libcaja-private/caja-file.c
diff options
context:
space:
mode:
authorrbuj <[email protected]>2019-04-30 13:12:04 +0200
committerraveit65 <[email protected]>2019-05-04 19:23:16 +0200
commit476f56a25be636970b336d525a7766b6d1eb3fff (patch)
tree44ee464da369bcd56331fe8b1f5e5aa64c535f94 /libcaja-private/caja-file.c
parent02646f7773b7b9b46df570e06084e428817889f0 (diff)
downloadcaja-476f56a25be636970b336d525a7766b6d1eb3fff.tar.bz2
caja-476f56a25be636970b336d525a7766b6d1eb3fff.tar.xz
eel: remove date & time functions
Do not need to extend glib library, since it now incorporates these functions. Extended date format modifiers are available on glib v2.56. eel-glib-extensions.h/c: GDate * eel_g_date_new_tm (struct tm *time_pieces); char * eel_strdup_strftime (const char *format, struct tm *time_pieces); gint64 eel_get_system_time (void); Do not need to test the extensions in eel_self_check_glib_extensions (void). eel-glib-extensions.c: static void check_tm_to_g_date (time_t time) static char * test_strftime (...) Do not need to check if strftime implements extended date format modifiers on the system (available on glibc v2.27). configure.ac
Diffstat (limited to 'libcaja-private/caja-file.c')
-rw-r--r--libcaja-private/caja-file.c48
1 files changed, 23 insertions, 25 deletions
diff --git a/libcaja-private/caja-file.c b/libcaja-private/caja-file.c
index 9a7d8719..3be71387 100644
--- a/libcaja-private/caja-file.c
+++ b/libcaja-private/caja-file.c
@@ -4806,40 +4806,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
@@ -4849,9 +4841,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;
@@ -4874,15 +4866,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]);
@@ -4898,8 +4891,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;
}
/**