Commit e4a012d5 authored by Alex Ives's avatar Alex Ives

Remove timecop dependency

parent 1e7f33ac
Pipeline #101028149 failed with stage
in 1 minute and 2 seconds
......@@ -6,7 +6,6 @@ group :test do
gem 'rake'
gem 'rspec'
gem 'rubocop'
gem 'timecop'
end
group :release do
......
......@@ -7,12 +7,11 @@ def get_zones(file)
JSON.parse(File.read(file))
end
def format_zones_json(zones, argument)
def format_zones_json(zones, argument, time=Time.now)
time_a = (argument || '').split(':')
time = Time.now
# 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))
time = Time.new(2000, 'jan', 1, (time_a[0] || time.hour), (time_a[1] || time.min), 0, time.strftime('%:z'))
time = time.utc
items = zones.map do |member, offset|
......
require_relative '../lib/view.rb'
require 'timecop'
describe 'get_zones' do
it 'reads the provided file from disk' do
......@@ -13,6 +12,7 @@ describe 'get_zones' do
end
describe 'format_zones_json' do
let(:frozen_time) { Time.new(2016, 'jan', 06, 17, 00, 00, '+00:00') }
let(:zones) do
{
'First' => -1,
......@@ -20,33 +20,28 @@ describe 'format_zones_json' do
'Third' => -5
}
end
it 'returns the current time in the various zones if nothing is supplied' do
Timecop.freeze('13:00:00') do
formatted = JSON.parse(format_zones_json(zones, nil))['items']
expect(formatted.length).to eq(3)
expect(formatted[0]['title']).to match(/^18:00 - .*$/)
expect(formatted[1]['title']).to match(/^05:00 - .*$/)
expect(formatted[2]['title']).to match(/^14:00 - .*$/)
end
formatted = JSON.parse(format_zones_json(zones, nil, frozen_time))['items']
expect(formatted.length).to eq(3)
expect(formatted[0]['title']).to match(/^16:00 - .*$/)
expect(formatted[1]['title']).to match(/^03:00 - .*$/)
expect(formatted[2]['title']).to match(/^12:00 - .*$/)
end
it 'returns the current time, but with hours changed if given hours' do
Timecop.freeze('2019-12-05 13:00:00 -0600') do
formatted = JSON.parse(format_zones_json(zones, '10'))['items']
expect(formatted.length).to eq(3)
expect(formatted[0]['title']).to match(/^15:00 - .*$/)
expect(formatted[1]['title']).to match(/^02:00 - .*$/)
expect(formatted[2]['title']).to match(/^11:00 - .*$/)
end
formatted = JSON.parse(format_zones_json(zones, '10', frozen_time))['items']
expect(formatted.length).to eq(3)
expect(formatted[0]['title']).to match(/^09:00 - .*$/)
expect(formatted[1]['title']).to match(/^20:00 - .*$/)
expect(formatted[2]['title']).to match(/^05:00 - .*$/)
end
it 'returns the time provided in the requested time zones' do
Timecop.freeze('2019-12-05 13:00:00 -0600') do
formatted = JSON.parse(format_zones_json(zones, '10:30'))['items']
expect(formatted.length).to eq(3)
expect(formatted[0]['title']).to match(/^15:30 - .*$/)
expect(formatted[1]['title']).to match(/^02:30 - .*$/)
expect(formatted[2]['title']).to match(/^11:30 - .*$/)
end
formatted = JSON.parse(format_zones_json(zones, '10:30', frozen_time))['items']
expect(formatted.length).to eq(3)
expect(formatted[0]['title']).to match(/^09:30 - .*$/)
expect(formatted[1]['title']).to match(/^20:30 - .*$/)
expect(formatted[2]['title']).to match(/^05:30 - .*$/)
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