From 39e5e1913f432136b8746d64e37494eefa1f07c8 Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 2 Dec 2021 22:06:40 +0800 Subject: [PATCH] Add command :Datetime to show current time or translate a Unix timestamp --- autoload/utils.vim | 8 ++++++-- plugin/command.vim | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/autoload/utils.vim b/autoload/utils.vim index 8486773..d1933a2 100644 --- a/autoload/utils.vim +++ b/autoload/utils.vim @@ -145,8 +145,12 @@ function! utils#Get_titlestr() abort return l:title_str endfunction -" Output current time in ISO format. -function! utils#iso_time() abort +" Output current time or unix timestamp in human-readable format. +function! utils#iso_time(timestamp) abort + if a:timestamp + return strftime('%Y-%m-%d %H:%M:%S%z', a:timestamp) + endif + return strftime('%Y-%m-%d %H:%M:%S%z') endfunction diff --git a/plugin/command.vim b/plugin/command.vim index a8e2998..d751831 100644 --- a/plugin/command.vim +++ b/plugin/command.vim @@ -5,3 +5,6 @@ command! -bar -bang -nargs=+ -complete=file Edit call utils#MultiEdit([] call utils#Cabbrev('edit', 'Edit') call utils#Cabbrev('man', 'Man') + +" show current date and time in human readable format +command! -nargs=? Datetime echo utils#iso_time()