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]>2022-07-19 23:40:12 +0200
commit64b7d2640fc91c28db3a16239f8fe5f6243bec26 (patch)
treeb12ae2b4f01c57cd205f4a3ba02b447eb9605296 /libcaja-private/caja-file.c
parenteb89ab06d009e620e037b7e9ea3a75fc450a0a75 (diff)
downloadcaja-64b7d2640fc91c28db3a16239f8fe5f6243bec26.tar.bz2
caja-64b7d2640fc91c28db3a16239f8fe5f6243bec26.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 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;
}
/**