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 <slavazanko@gmail.com>
This commit is contained in:
Martin Petricek 2009-11-25 13:04:51 +02:00 committed by Slava Zanko
parent 26d2ae5431
commit 7c3196b60e
4 changed files with 36 additions and 12 deletions

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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);