diff options
Diffstat (limited to 'src/misc1.c')
-rw-r--r-- | src/misc1.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/misc1.c b/src/misc1.c index 0e182555a..74c8eaa66 100644 --- a/src/misc1.c +++ b/src/misc1.c @@ -2576,3 +2576,34 @@ path_with_url(char_u *fname) ; return path_is_url(p); } + +/* + * Put timestamp "tt" in "buf[buflen]" in a nice format. + */ + void +add_time(char_u *buf, size_t buflen, time_t tt) +{ +#ifdef HAVE_STRFTIME + struct tm tmval; + struct tm *curtime; + + if (vim_time() - tt >= 100) + { + curtime = vim_localtime(&tt, &tmval); + if (vim_time() - tt < (60L * 60L * 12L)) + /* within 12 hours */ + (void)strftime((char *)buf, buflen, "%H:%M:%S", curtime); + else + /* longer ago */ + (void)strftime((char *)buf, buflen, "%Y/%m/%d %H:%M:%S", curtime); + } + else +#endif + { + long seconds = (long)(vim_time() - tt); + + vim_snprintf((char *)buf, buflen, + NGETTEXT("%ld second ago", "%ld seconds ago", seconds), + seconds); + } +} |