Commit bfd6ea99 authored by Alex Ives's avatar Alex Ives 🛑

Allow times to have am/pm on them ex: 1p or 1:30pm or 10AM

parent e75d7165
Pipeline #112104144 failed with stages
in 38 seconds
......@@ -11,15 +11,16 @@ def format_zones_json(zones, argument, time=Time.now)
filter = ''
time_a = []
argument.split(' ').each do |arg|
if arg.match(/\d+:?\d?+/)
time_a = arg.split(':')
if arg.match(/(\d+):?(\d+)?(am?|pm?)?/i)
time_a = arg.match(/(\d+):?(\d+)?(am?|pm?)?/i).to_a
time_a[1] = time_a[1].to_i + 12 if time_a[3]&.match(/pm?/i)
else
filter = arg
end
end if argument && !argument.empty?
# throwaway way to make a new date object in local time that we can convert to UTC based optionally with minutes/hours
time = Time.new(2000, 'jan', 1, (time_a[0] || time.hour), (time_a[1] || time.min), 0, time.strftime('%:z'))
time = Time.new(2000, 'jan', 1, (time_a[1] || time.hour), (time_a[2] || time.min), 0, time.strftime('%:z'))
time_string = time.strftime('%H:%M')
time = time.utc
......
......@@ -72,4 +72,14 @@ describe 'format_zones_json' do
formatted = JSON.parse(format_zones_json(zones, '10:30 second', frozen_time))['items']
expect(formatted[0]['title']).to match(/^20:30 - Second$/)
end
it 'can have pm at on the short time' do
formatted = JSON.parse(format_zones_json(zones, '1p first', frozen_time))['items']
expect(formatted[0]['title']).to match(/^12:00 - First$/)
end
it 'can have pm at on the long time' do
formatted = JSON.parse(format_zones_json(zones, '1:30PM first', frozen_time))['items']
expect(formatted[0]['title']).to match(/^12:30 - First$/)
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment