change time/date format in '+FORMAT'

This commit is contained in:
t-mangoe 2021-11-13 09:21:15 +09:00
parent 53f557b78a
commit 90aaa4d0b6
2 changed files with 2 additions and 2 deletions

View file

@ -250,7 +250,7 @@ module ColorLS
end
def mtime_info(file_mtime)
mtime = @time_style.empty? ? file_mtime.asctime : file_mtime.strftime(@time_style)
mtime = @time_style.start_with?('+') ? file_mtime.strftime(@time_style.delete_prefix('+')) : file_mtime.asctime
now = Time.now
return mtime.colorize(@colors[:hour_old]) if now - file_mtime < 60 * 60
return mtime.colorize(@colors[:day_old]) if now - file_mtime < 24 * 60 * 60

View file

@ -552,7 +552,7 @@ RSpec.describe ColorLS::Flags do
end
context 'with --time-style option' do
let(:args) { ['-l', '--time-style=%y-%m-%d %k:%M', "#{FIXTURES}/a.txt"] }
let(:args) { ['-l', '--time-style=+%y-%m-%d %k:%M', "#{FIXTURES}/a.txt"] }
mtime = File.mtime("#{FIXTURES}/a.txt")