Commit cad0d3cb authored by Alex Ives's avatar Alex Ives

Add ability to set timezones to in LINT

parent a0a3815b
Pipeline #108976697 passed with stages
in 1 minute and 5 seconds
......@@ -2,10 +2,10 @@ require 'json'
require_relative './view.rb'
def get_new_zone(name, offset)
if offset&.match(/^-?\d+$/) && offset.to_i <= 12 && offset.to_i >= -12
if offset&.sub('+', '')&.match(/^-?\d+$/) && offset.to_i <= 14 && offset.to_i >= -12
{
title: "Add/update zone #{name}/#{offset}",
subtitle: "Add/update zone '#{name}' with offset #{offset}",
subtitle: "Add/update zone '#{name}' with offset #{offset}, ⌘+⏎ to remove",
arg: "#{name}, #{offset}",
valid: true,
mods: {
......@@ -18,7 +18,7 @@ def get_new_zone(name, offset)
elsif offset
{
title: "ERROR: Add/update zone #{name}/#{offset}",
subtitle: "Invalid offset, must be an integer between -12 and 12 but is #{offset}",
subtitle: "Invalid offset, must be an integer between -12 and +14 but is #{offset}",
arg: "#{name}, #{offset}",
valid: false,
mods: {
......
......@@ -5,6 +5,14 @@ describe 'get_new_zone' do
expect(get_new_zone('Test', '-1')[:valid]).to be true
end
it 'works with a + in the number' do
expect(get_new_zone('Test', '+11')[:valid]).to be true
end
it 'works with 14 (Line Islands Time)' do
expect(get_new_zone('Test', '14')[:valid]).to be true
end
it 'returns an additon with an autocomplete' do
expect(get_new_zone('Test', nil)[:valid]).to be false
expect(get_new_zone('Test', nil)[:autocomplete]).to eq('Test, ')
......@@ -12,11 +20,11 @@ describe 'get_new_zone' do
it 'returns an error if it is not a valid offset' do
expect(get_new_zone('Test', 'test')[:valid]).to be false
expect(get_new_zone('Test', '13')[:valid]).to be false
expect(get_new_zone('Test', '15')[:valid]).to be false
expect(get_new_zone('Test', '-13')[:valid]).to be false
expect(get_new_zone('Test', '13')[:title]).to eq('ERROR: Add/update zone Test/13')
expect(get_new_zone('Test', '13')[:subtitle]).to eq('Invalid offset, must be an integer between -12 and 12 but is 13')
expect(get_new_zone('Test', '-13')[:title]).to eq('ERROR: Add/update zone Test/-13')
expect(get_new_zone('Test', '-13')[:subtitle]).to eq('Invalid offset, must be an integer between -12 and +14 but is -13')
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