Commit e75d7165 authored by Alex Ives's avatar Alex Ives

Take both a filter and a time

parent c2595faa
Pipeline #112096559 failed with stages
in 40 seconds
......@@ -8,12 +8,15 @@ def get_zones(file)
end
def format_zones_json(zones, argument, time=Time.now)
time_a = (argument || '').split(':')
filter = ''
if(!time_a.empty? && !time_a[0].match(/\d+/))
filter = argument
time_a = []
argument.split(' ').each do |arg|
if arg.match(/\d+:?\d?+/)
time_a = arg.split(':')
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'))
......
......@@ -62,4 +62,14 @@ describe 'format_zones_json' do
formatted = JSON.parse(format_zones_json(zones, 'Nothing will match this', frozen_time))['items']
expect(formatted.length).to eq(0)
end
it 'takes a filter followed by a time' do
formatted = JSON.parse(format_zones_json(zones, 'second 10', frozen_time))['items']
expect(formatted[0]['title']).to match(/^20:00 - Second$/)
end
it 'takes a time followed by a filter' do
formatted = JSON.parse(format_zones_json(zones, '10:30 second', frozen_time))['items']
expect(formatted[0]['title']).to match(/^20:30 - Second$/)
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