From 7c3196b60e5ffbdf6d7e9f1ab97854412870619f Mon Sep 17 00:00:00 2001 From: Martin Petricek Date: Wed, 25 Nov 2009 13:04:51 +0200 Subject: [PATCH] Ticket #1767: Custom/locale-based date format Fixed showing of datetime format in various locales (such as Polish locale) Added new options in config file: [Misc] ... timeformat_recent=%d.%m.%y %H:%M timeformat_old=%d.%m.%y %H:%M ... where timeformat_recent - for files with mtime between now and "6 moths old" (like "Nov 2 00:56") timeformat_old - for other files (like "Jun 23 2007") Signed-off-by: Slava Zanko --- doc/man/mc.1.in | 12 ++++++++++++ lib/util.c | 17 ++++++----------- lib/util.h | 2 +- src/setup.c | 17 +++++++++++++++++ 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/doc/man/mc.1.in b/doc/man/mc.1.in index 48881962d..88e019e4d 100644 --- a/doc/man/mc.1.in +++ b/doc/man/mc.1.in @@ -3714,6 +3714,18 @@ When you use the C\-o keystroke to go back to the user screen, if this one is set, you will get a fresh shell. Otherwise, pressing any key will bring you back to the Midnight Commander. .TP +.I timeformat_recent +Change the time format used to display dates less than 6 months from +now. +See strftime or date man page for the format specification. If this +option is absent, default timeformat is used. +.TP +.I timeformat_old +Change the time format used to display dates older than 6 months from +now or for dates in the future. +See strftime or date man page for the format specification. If this +option is absent, default timeformat is used. +.TP .I torben_fj_mode If this flag is set, then the home and end keys will work slightly different on the panels, instead of moving the selection to the first diff --git a/lib/util.c b/lib/util.c index dd40aa82a..012feebd2 100644 --- a/lib/util.c +++ b/lib/util.c @@ -54,12 +54,6 @@ #include "src/main.h" /* eight_bit_clean */ #endif -/*In order to use everywhere the same setup - for the locale we use defines */ -#define FMTYEAR _("%b %e %Y") -#define FMTTIME _("%b %e %H:%M") - - int easy_patterns = 1; /* @@ -69,7 +63,8 @@ int easy_patterns = 1; */ int kilobyte_si = 0; - +char *user_recent_timeformat = NULL; /* time format string for recent dates */ +char *user_old_timeformat = NULL; /* time format string for older dates */ extern void str_replace(char *s, char from, char to) { @@ -654,9 +649,9 @@ i18n_checktimelength (void) char buf [MB_LEN_MAX * MAX_I18NTIMELENGTH + 1]; size_t a, b; - strftime (buf, sizeof(buf) - 1, FMTTIME, lt); + strftime (buf, sizeof(buf) - 1, user_recent_timeformat, lt); a = str_term_width1 (buf); - strftime (buf, sizeof(buf) - 1, FMTYEAR, lt); + strftime (buf, sizeof(buf) - 1, user_old_timeformat, lt); b = str_term_width1 (buf); length = max (a, b); @@ -686,9 +681,9 @@ file_date (time_t when) to allow for NFS server/client clock disagreement. Show the year instead of the time of day. */ - fmt = FMTYEAR; + fmt = user_old_timeformat; else - fmt = FMTTIME; + fmt = user_recent_timeformat; FMT_LOCALTIME(timebuf, sizeof (timebuf), fmt, when); diff --git a/lib/util.h b/lib/util.h index 885b18442..606449c79 100644 --- a/lib/util.h +++ b/lib/util.h @@ -108,7 +108,7 @@ void init_uid_gid_cache (void); char *get_group (int); char *get_owner (int); -#define MAX_I18NTIMELENGTH 14 +#define MAX_I18NTIMELENGTH 20 #define MIN_I18NTIMELENGTH 10 #define STD_I18NTIMELENGTH 12 diff --git a/src/setup.c b/src/setup.c index baaec358b..97d3b5025 100644 --- a/src/setup.c +++ b/src/setup.c @@ -234,6 +234,16 @@ static const struct { { 0, 0 } }; +extern char *user_recent_timeformat; +extern char *user_old_timeformat; + +/* + In order to use everywhere the same setup + for the locale we use defines +*/ +#define FMTYEAR _("%b %e %Y") +#define FMTTIME _("%b %e %H:%M") + static const struct { const char *opt_name; char **opt_addr; @@ -787,6 +797,10 @@ load_setup (void) boot_current_is_left = mc_config_get_int (mc_panels_config, "Dirs", "current_is_left", 1); + /* Load time formats */ + user_recent_timeformat = mc_config_get_string (mc_main_config, "Misc", "timeformat_recent", FMTTIME); + user_old_timeformat = mc_config_get_string (mc_main_config, "Misc", "timeformat_old", FMTYEAR); + #ifdef USE_NETCODE ftpfs_proxy_host = mc_config_get_string (mc_main_config, "Misc", "ftp_proxy_host", "gate"); #endif @@ -859,6 +873,9 @@ done_setup (void) mc_config_deinit (mc_main_config); mc_config_deinit (mc_panels_config); + g_free(user_recent_timeformat); + g_free(user_old_timeformat); + for (i = 0; str_options[i].opt_name != NULL; i++) g_free (*str_options[i].opt_addr); -- 2.11.4.GIT