timeliness 0.3.7 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.travis.yml +7 -0
- data/lib/timeliness/definitions.rb +8 -4
- data/lib/timeliness/format.rb +3 -3
- data/lib/timeliness/format_set.rb +1 -1
- data/lib/timeliness/parser.rb +11 -2
- data/lib/timeliness/version.rb +1 -1
- data/spec/spec_helper.rb +86 -27
- data/spec/timeliness/core_ext/string_spec.rb +14 -16
- data/spec/timeliness/definitions_spec.rb +14 -16
- data/spec/timeliness/format_set_spec.rb +13 -15
- data/spec/timeliness/format_spec.rb +18 -20
- data/spec/timeliness/parser_spec.rb +119 -91
- data/spec/timeliness_helper.rb +37 -0
- data/timeliness.gemspec +6 -0
- metadata +80 -10
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5416676829597b429ae232b78e90623d8e1aabc2
|
4
|
+
data.tar.gz: 0ab3eb69ceead65aa57c127daf153c7ebe8702f6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 417eee657c054357f1be5d59a461d993c95a58248dfaa942198625627d79516204917d27973ac5b17ff44429ae749abe8a727665ad50656e264745e18c6d7e4c
|
7
|
+
data.tar.gz: 0b6316ca2d841d7f827409e2ebcd31b9162cfa6dc29d8d686501b27b71edc34e114de8569aa4e008fe42e025974404ade97208bc4e9d815715da0c629f16e025
|
data/.travis.yml
ADDED
@@ -78,7 +78,9 @@ module Timeliness
|
|
78
78
|
'yyyy-mm-ddThh:nn:ssZ', # ISO 8601 without zone offset
|
79
79
|
'yyyy-mm-ddThh:nn:sszo', # ISO 8601 with zone offset
|
80
80
|
'yyyy-mm-ddThh:nn:ss.u', # ISO 8601 with usec
|
81
|
-
'yyyy-mm-ddThh:nn:ss.uzo' # ISO 8601 with usec and offset
|
81
|
+
'yyyy-mm-ddThh:nn:ss.uzo', # ISO 8601 with usec and offset
|
82
|
+
'yyyy-mm-dd hh:nn:ss zo', # Ruby time string in later versions
|
83
|
+
'yyyy-mm-dd hh:nn:ss tz', # Ruby time string for UTC in later versions
|
82
84
|
]
|
83
85
|
|
84
86
|
# All tokens available for format construction. The token array is made of
|
@@ -145,6 +147,8 @@ module Timeliness
|
|
145
147
|
}
|
146
148
|
|
147
149
|
US_FORMAT_REGEXP = /\Am{1,2}[^m]/
|
150
|
+
FormatNotFound = Class.new(StandardError)
|
151
|
+
DuplicateFormat = Class.new(StandardError)
|
148
152
|
|
149
153
|
class << self
|
150
154
|
attr_accessor :time_formats, :date_formats, :datetime_formats, :format_tokens, :format_components, :timezone_mapping
|
@@ -160,10 +164,10 @@ module Timeliness
|
|
160
164
|
formats = send("#{type}_formats")
|
161
165
|
options = add_formats.last.is_a?(Hash) ? add_formats.pop : {}
|
162
166
|
before = options[:before]
|
163
|
-
raise "Format for :before option #{
|
167
|
+
raise FormatNotFound, "Format for :before option #{before.inspect} was not found." if before && !formats.include?(before)
|
164
168
|
|
165
169
|
add_formats.each do |format|
|
166
|
-
raise "Format #{format} is already included in #{type} formats" if formats.include?(format)
|
170
|
+
raise DuplicateFormat, "Format #{format.inspect} is already included in #{type.inspect} formats" if formats.include?(format)
|
167
171
|
|
168
172
|
index = before ? formats.index(before) : -1
|
169
173
|
formats.insert(index, format)
|
@@ -176,7 +180,7 @@ module Timeliness
|
|
176
180
|
def remove_formats(type, *remove_formats)
|
177
181
|
remove_formats.each do |format|
|
178
182
|
unless send("#{type}_formats").delete(format)
|
179
|
-
raise "Format #{format} not found in #{type} formats"
|
183
|
+
raise FormatNotFound, "Format #{format.inspect} not found in #{type.inspect} formats"
|
180
184
|
end
|
181
185
|
end
|
182
186
|
compile_formats
|
data/lib/timeliness/format.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Timeliness
|
2
|
-
class CompilationError < StandardError; end
|
3
|
-
|
4
2
|
class Format
|
5
3
|
include Helpers
|
6
4
|
|
5
|
+
CompilationFailed = Class.new(StandardError)
|
6
|
+
|
7
7
|
attr_reader :format_string, :regexp, :regexp_string, :token_count
|
8
8
|
|
9
9
|
def initialize(format_string)
|
@@ -41,7 +41,7 @@ module Timeliness
|
|
41
41
|
@regexp = Regexp.new("^(#{format})$")
|
42
42
|
self
|
43
43
|
rescue => ex
|
44
|
-
raise
|
44
|
+
raise CompilationFailed, "The format '#{format_string}' failed to compile using regexp string #{format}. Error message: #{ex.inspect}"
|
45
45
|
end
|
46
46
|
|
47
47
|
# Redefined on compile
|
@@ -23,7 +23,7 @@ module Timeliness
|
|
23
23
|
regexp_string = "#{regexp_string}(#{format.regexp_string})|"
|
24
24
|
index + format.token_count + 1 # add one for wrapper capture
|
25
25
|
}
|
26
|
-
@regexp =
|
26
|
+
@regexp = %r[\A(?:#{regexp_string.chop})\z]
|
27
27
|
self
|
28
28
|
end
|
29
29
|
|
data/lib/timeliness/parser.rb
CHANGED
@@ -5,7 +5,8 @@ module Timeliness
|
|
5
5
|
class << self
|
6
6
|
|
7
7
|
def parse(value, *args)
|
8
|
-
return value
|
8
|
+
return value if acts_like_temporal?(value)
|
9
|
+
return nil unless parseable?(value)
|
9
10
|
|
10
11
|
type, options = type_and_options_from_args(args)
|
11
12
|
|
@@ -47,6 +48,14 @@ module Timeliness
|
|
47
48
|
|
48
49
|
private
|
49
50
|
|
51
|
+
def parseable?(value)
|
52
|
+
value.is_a?(String)
|
53
|
+
end
|
54
|
+
|
55
|
+
def acts_like_temporal?(value)
|
56
|
+
value.is_a?(Time) || value.is_a?(Date) || value.respond_to?(:acts_like_date?) || value.respond_to?(:acts_like_time?)
|
57
|
+
end
|
58
|
+
|
50
59
|
def type_and_options_from_args(args)
|
51
60
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
52
61
|
type_or_now = args.first
|
@@ -129,7 +138,7 @@ module Timeliness
|
|
129
138
|
|
130
139
|
# Taken from ActiveSupport and simplified
|
131
140
|
def time_with_datetime_fallback(utc_or_local, year, month=1, day=1, hour=0, min=0, sec=0, usec=0)
|
132
|
-
|
141
|
+
return nil if hour > 23 || min > 59 || sec > 59
|
133
142
|
::Time.send(utc_or_local, year, month, day, hour, min, sec, usec)
|
134
143
|
rescue
|
135
144
|
offset = utc_or_local == :local ? (::Time.local(2007).utc_offset.to_r/86400) : 0
|
data/lib/timeliness/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,37 +1,96 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
4
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
5
|
+
# files.
|
6
|
+
#
|
7
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
8
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
9
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
10
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
11
|
+
# a separate helper file that requires the additional dependencies and performs
|
12
|
+
# the additional setup, and require it from the spec files that actually need
|
13
|
+
# it.
|
14
|
+
#
|
15
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
16
|
+
# users commonly want.
|
17
|
+
#
|
18
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
19
|
+
RSpec.configure do |config|
|
20
|
+
# rspec-expectations config goes here. You can use an alternate
|
21
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
22
|
+
# assertions if you prefer.
|
23
|
+
config.expect_with :rspec do |expectations|
|
24
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
25
|
+
# and `failure_message` of custom matchers include text for helper methods
|
26
|
+
# defined using `chain`, e.g.:
|
27
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
28
|
+
# # => "be bigger than 2 and smaller than 4"
|
29
|
+
# ...rather than:
|
30
|
+
# # => "be bigger than 2"
|
31
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
11
32
|
end
|
12
33
|
|
13
|
-
|
14
|
-
|
34
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
35
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
36
|
+
config.mock_with :rspec do |mocks|
|
37
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
38
|
+
# a real object. This is generally recommended, and will default to
|
39
|
+
# `true` in RSpec 4.
|
40
|
+
mocks.verify_partial_doubles = true
|
15
41
|
end
|
16
42
|
|
17
|
-
|
18
|
-
|
19
|
-
|
43
|
+
# The settings below are suggested to provide a good initial experience
|
44
|
+
# with RSpec, but feel free to customize to your heart's content.
|
45
|
+
=begin
|
46
|
+
# These two settings work together to allow you to limit a spec run
|
47
|
+
# to individual examples or groups you care about by tagging them with
|
48
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
49
|
+
# get run.
|
50
|
+
config.filter_run :focus
|
51
|
+
config.run_all_when_everything_filtered = true
|
20
52
|
|
21
|
-
|
22
|
-
|
23
|
-
|
53
|
+
# Allows RSpec to persist some state between runs in order to support
|
54
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
55
|
+
# you configure your source control system to ignore this file.
|
56
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
24
57
|
|
25
|
-
|
26
|
-
|
27
|
-
|
58
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
59
|
+
# recommended. For more details, see:
|
60
|
+
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
61
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
62
|
+
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
63
|
+
config.disable_monkey_patching!
|
28
64
|
|
29
|
-
|
30
|
-
|
65
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
66
|
+
# be too noisy due to issues in dependencies.
|
67
|
+
config.warnings = true
|
68
|
+
|
69
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
70
|
+
# file, and it's useful to allow more verbose output when running an
|
71
|
+
# individual spec file.
|
72
|
+
if config.files_to_run.one?
|
73
|
+
# Use the documentation formatter for detailed output,
|
74
|
+
# unless a formatter has already been configured
|
75
|
+
# (e.g. via a command-line flag).
|
76
|
+
config.default_formatter = 'doc'
|
31
77
|
end
|
32
|
-
end
|
33
78
|
|
34
|
-
|
35
|
-
|
36
|
-
|
79
|
+
# Print the 10 slowest examples and example groups at the
|
80
|
+
# end of the spec run, to help surface which specs are running
|
81
|
+
# particularly slow.
|
82
|
+
config.profile_examples = 10
|
83
|
+
|
84
|
+
# Run specs in random order to surface order dependencies. If you find an
|
85
|
+
# order dependency and want to debug it, you can fix the order by providing
|
86
|
+
# the seed, which is printed after each run.
|
87
|
+
# --seed 1234
|
88
|
+
config.order = :random
|
89
|
+
|
90
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
91
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
92
|
+
# test failures related to randomization by passing the same `--seed` value
|
93
|
+
# as the one that triggered the failure.
|
94
|
+
Kernel.srand config.seed
|
95
|
+
=end
|
37
96
|
end
|
@@ -1,71 +1,69 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe Timeliness::CoreExt, 'String' do
|
4
2
|
# Test values taken from ActiveSupport unit tests for compatibility
|
5
3
|
|
6
4
|
describe "#to_time" do
|
7
5
|
it 'should convert valid string to Time object in default zone' do
|
8
|
-
"2005-02-27 23:50".to_time.
|
6
|
+
expect("2005-02-27 23:50".to_time).to eq Time.utc(2005, 2, 27, 23, 50)
|
9
7
|
end
|
10
8
|
|
11
9
|
it 'should convert ISO 8601 string to Time object' do
|
12
|
-
"2005-02-27T23:50:19.275038".to_time.
|
10
|
+
expect("2005-02-27T23:50:19.275038".to_time).to eq Time.utc(2005, 2, 27, 23, 50, 19, 275038)
|
13
11
|
end
|
14
12
|
|
15
13
|
context "with :local" do
|
16
14
|
it 'should convert valid string to local time' do
|
17
|
-
"2005-02-27 23:50".to_time(:local).
|
15
|
+
expect("2005-02-27 23:50".to_time(:local)).to eq Time.local(2005, 2, 27, 23, 50)
|
18
16
|
end
|
19
17
|
|
20
18
|
it 'should convert ISO 8601 string to local time' do
|
21
|
-
"2005-02-27T23:50:19.275038".to_time(:local).
|
19
|
+
expect("2005-02-27T23:50:19.275038".to_time(:local)).to eq Time.local(2005, 2, 27, 23, 50, 19, 275038)
|
22
20
|
end
|
23
21
|
end
|
24
22
|
|
25
23
|
it 'should convert valid future string to Time object' do
|
26
|
-
"2039-02-27 23:50".to_time(:local).
|
24
|
+
expect("2039-02-27 23:50".to_time(:local)).to eq Time.local(2039, 2, 27, 23, 50)
|
27
25
|
end
|
28
26
|
|
29
27
|
it 'should convert valid future string to Time object' do
|
30
|
-
"2039-02-27 23:50".to_time.
|
28
|
+
expect("2039-02-27 23:50".to_time).to eq DateTime.civil(2039, 2, 27, 23, 50)
|
31
29
|
end
|
32
30
|
|
33
31
|
it 'should convert empty string to nil' do
|
34
|
-
''.to_time.
|
32
|
+
expect(''.to_time).to be_nil
|
35
33
|
end
|
36
34
|
end
|
37
35
|
|
38
36
|
describe "#to_datetime" do
|
39
37
|
it 'should convert valid string to DateTime object' do
|
40
|
-
"2039-02-27 23:50".to_datetime.
|
38
|
+
expect("2039-02-27 23:50".to_datetime).to eq DateTime.civil(2039, 2, 27, 23, 50)
|
41
39
|
end
|
42
40
|
|
43
41
|
it 'should convert to DateTime object with UTC offset' do
|
44
|
-
"2039-02-27 23:50".to_datetime.offset.
|
42
|
+
expect("2039-02-27 23:50".to_datetime.offset).to eq 0
|
45
43
|
end
|
46
44
|
|
47
45
|
it 'should convert ISO 8601 string to DateTime object' do
|
48
46
|
datetime = DateTime.civil(2039, 2, 27, 23, 50, 19 + Rational(275038, 1000000), "-04:00")
|
49
|
-
"2039-02-27T23:50:19.275038-04:00".to_datetime.
|
47
|
+
expect("2039-02-27T23:50:19.275038-04:00".to_datetime).to eq datetime
|
50
48
|
end
|
51
49
|
|
52
50
|
it 'should use Rubys default start value' do
|
53
51
|
# Taken from ActiveSupport unit tests. Not sure on the implication.
|
54
|
-
"2039-02-27 23:50".to_datetime.start.
|
52
|
+
expect("2039-02-27 23:50".to_datetime.start).to eq ::Date::ITALY
|
55
53
|
end
|
56
54
|
|
57
55
|
it 'should convert empty string to nil' do
|
58
|
-
''.to_datetime.
|
56
|
+
expect(''.to_datetime).to be_nil
|
59
57
|
end
|
60
58
|
end
|
61
59
|
|
62
60
|
describe "#to_date" do
|
63
61
|
it 'should convert string to Date object' do
|
64
|
-
"2005-02-27".to_date.
|
62
|
+
expect("2005-02-27".to_date).to eq Date.new(2005, 2, 27)
|
65
63
|
end
|
66
64
|
|
67
65
|
it 'should convert empty string to nil' do
|
68
|
-
''.to_date.
|
66
|
+
expect(''.to_date).to be_nil
|
69
67
|
end
|
70
68
|
end
|
71
69
|
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe Timeliness::Definitions do
|
4
2
|
|
5
3
|
context "add_formats" do
|
@@ -9,7 +7,7 @@ describe Timeliness::Definitions do
|
|
9
7
|
|
10
8
|
it "should add format to format array" do
|
11
9
|
definitions.add_formats(:time, "h o'clock")
|
12
|
-
definitions.time_formats.
|
10
|
+
expect(definitions.time_formats).to include("h o'clock")
|
13
11
|
end
|
14
12
|
|
15
13
|
it "should parse new format after its added" do
|
@@ -19,18 +17,18 @@ describe Timeliness::Definitions do
|
|
19
17
|
end
|
20
18
|
|
21
19
|
it "should raise error if format exists" do
|
22
|
-
expect { definitions.add_formats(:time, "hh:nn:ss") }.to raise_error
|
20
|
+
expect { definitions.add_formats(:time, "hh:nn:ss") }.to raise_error(Timeliness::Definitions::DuplicateFormat)
|
23
21
|
end
|
24
22
|
|
25
23
|
context "with :before option" do
|
26
24
|
it "should add new format with higher precedence" do
|
27
25
|
definitions.add_formats(:time, "ss:hh:nn", :before => 'hh:nn:ss')
|
28
26
|
time_array = parser._parse('59:23:58', :time)
|
29
|
-
time_array.
|
27
|
+
expect(time_array).to eq [nil,nil,nil,23,58,59,nil,nil]
|
30
28
|
end
|
31
29
|
|
32
30
|
it "should raise error if :before format does not exist" do
|
33
|
-
expect { definitions.add_formats(:time, "ss:hh:nn", :before => 'nn:hh:ss') }.to raise_error
|
31
|
+
expect { definitions.add_formats(:time, "ss:hh:nn", :before => 'nn:hh:ss') }.to raise_error(Timeliness::Definitions::FormatNotFound)
|
34
32
|
end
|
35
33
|
end
|
36
34
|
|
@@ -47,13 +45,13 @@ describe Timeliness::Definitions do
|
|
47
45
|
|
48
46
|
it "should remove a single format from the formats array for type" do
|
49
47
|
definitions.remove_formats(:time, 'h.nn_ampm')
|
50
|
-
definitions.time_formats.
|
48
|
+
expect(definitions.time_formats).not_to include('h.nn_ampm')
|
51
49
|
end
|
52
50
|
|
53
51
|
it "should remove multiple formats from formats array for type" do
|
54
52
|
definitions.remove_formats(:time, 'h:nn', 'h.nn_ampm')
|
55
|
-
definitions.time_formats.
|
56
|
-
definitions.time_formats.
|
53
|
+
expect(definitions.time_formats).not_to include('h:nn')
|
54
|
+
expect(definitions.time_formats).not_to include('h.nn_ampm')
|
57
55
|
end
|
58
56
|
|
59
57
|
it "should prevent parsing of removed format" do
|
@@ -63,7 +61,7 @@ describe Timeliness::Definitions do
|
|
63
61
|
end
|
64
62
|
|
65
63
|
it "should raise error if format does not exist" do
|
66
|
-
expect { definitions.remove_formats(:time, "ss:hh:nn") }.to raise_error()
|
64
|
+
expect { definitions.remove_formats(:time, "ss:hh:nn") }.to raise_error(Timeliness::Definitions::FormatNotFound)
|
67
65
|
end
|
68
66
|
|
69
67
|
after do
|
@@ -74,14 +72,14 @@ describe Timeliness::Definitions do
|
|
74
72
|
|
75
73
|
context "use_euro_formats" do
|
76
74
|
it "should allow ambiguous date to be parsed as European format" do
|
77
|
-
parser._parse('01/02/2000', :date).
|
75
|
+
expect(parser._parse('01/02/2000', :date)).to eq [2000,1,2,nil,nil,nil,nil,nil]
|
78
76
|
definitions.use_euro_formats
|
79
|
-
parser._parse('01/02/2000', :date).
|
77
|
+
expect(parser._parse('01/02/2000', :date)).to eq [2000,2,1,nil,nil,nil,nil,nil]
|
80
78
|
end
|
81
79
|
|
82
80
|
it "should not parse formats on switch to euro after initial compile" do
|
83
81
|
definitions.compile_formats
|
84
|
-
Timeliness::FormatSet.
|
82
|
+
expect(Timeliness::FormatSet).not_to receive(:compile)
|
85
83
|
definitions.use_euro_formats
|
86
84
|
end
|
87
85
|
end
|
@@ -92,14 +90,14 @@ describe Timeliness::Definitions do
|
|
92
90
|
end
|
93
91
|
|
94
92
|
it "should allow ambiguous date to be parsed as European format" do
|
95
|
-
parser._parse('01/02/2000', :date).
|
93
|
+
expect(parser._parse('01/02/2000', :date)).to eq [2000,2,1,nil,nil,nil,nil,nil]
|
96
94
|
definitions.use_us_formats
|
97
|
-
parser._parse('01/02/2000', :date).
|
95
|
+
expect(parser._parse('01/02/2000', :date)).to eq [2000,1,2,nil,nil,nil,nil,nil]
|
98
96
|
end
|
99
97
|
|
100
98
|
it "should not parse formats on switch to euro after initial compile" do
|
101
99
|
definitions.compile_formats
|
102
|
-
Timeliness::FormatSet.
|
100
|
+
expect(Timeliness::FormatSet).not_to receive(:compile)
|
103
101
|
definitions.use_us_formats
|
104
102
|
end
|
105
103
|
end
|
@@ -1,12 +1,10 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe Timeliness::FormatSet do
|
4
2
|
context "#compile!" do
|
5
3
|
let(:set) { Timeliness::FormatSet.new(['yyyy-mm-dd', 'dd/mm/yyyy']) }
|
6
4
|
|
7
5
|
it 'should set the regexp for the set' do
|
8
6
|
set.compile!
|
9
|
-
set.regexp.
|
7
|
+
expect(set.regexp).not_to be_nil
|
10
8
|
end
|
11
9
|
end
|
12
10
|
|
@@ -28,8 +26,8 @@ describe Timeliness::FormatSet do
|
|
28
26
|
format_tests.each do |format, values|
|
29
27
|
it "should correctly match times in format '#{format}'" do
|
30
28
|
regexp = compile_regexp(format)
|
31
|
-
values[:pass].each {|value| value.
|
32
|
-
values[:fail].each {|value| value.
|
29
|
+
values[:pass].each {|value| expect(value).to match(regexp)}
|
30
|
+
values[:fail].each {|value| expect(value).not_to match(regexp)}
|
33
31
|
end
|
34
32
|
end
|
35
33
|
end
|
@@ -51,8 +49,8 @@ describe Timeliness::FormatSet do
|
|
51
49
|
format_tests.each do |format, values|
|
52
50
|
it "should correctly match dates in format '#{format}'" do
|
53
51
|
regexp = compile_regexp(format)
|
54
|
-
values[:pass].each {|value| value.
|
55
|
-
values[:fail].each {|value| value.
|
52
|
+
values[:pass].each {|value| expect(value).to match(regexp)}
|
53
|
+
values[:fail].each {|value| expect(value).not_to match(regexp)}
|
56
54
|
end
|
57
55
|
end
|
58
56
|
end
|
@@ -65,8 +63,8 @@ describe Timeliness::FormatSet do
|
|
65
63
|
format_tests.each do |format, values|
|
66
64
|
it "should correctly match datetimes in format '#{format}'" do
|
67
65
|
regexp = compile_regexp(format)
|
68
|
-
values[:pass].each {|value| value.
|
69
|
-
values[:fail].each {|value| value.
|
66
|
+
values[:pass].each {|value| expect(value).to match(regexp)}
|
67
|
+
values[:fail].each {|value| expect(value).not_to match(regexp)}
|
70
68
|
end
|
71
69
|
end
|
72
70
|
end
|
@@ -77,21 +75,21 @@ describe Timeliness::FormatSet do
|
|
77
75
|
let(:set) { Timeliness::FormatSet.compile(['yyyy-mm-dd', 'dd/mm/yyyy']) }
|
78
76
|
|
79
77
|
it 'should return array if string matches a format in set' do
|
80
|
-
set.match('2000-01-02').
|
78
|
+
expect(set.match('2000-01-02')).to be_kind_of(Array)
|
81
79
|
end
|
82
80
|
|
83
81
|
it 'should return nil if string does not matches a format in set' do
|
84
|
-
set.match('2nd Feb 2000').
|
82
|
+
expect(set.match('2nd Feb 2000')).to be_nil
|
85
83
|
end
|
86
84
|
|
87
85
|
it 'should only use specific format string for match if provided' do
|
88
|
-
set.match('2000-01-02', 'yyyy-mm-dd').
|
89
|
-
set.match('2000-01-02', 'dd/mm/yyyy').
|
86
|
+
expect(set.match('2000-01-02', 'yyyy-mm-dd')).to be_kind_of(Array)
|
87
|
+
expect(set.match('2000-01-02', 'dd/mm/yyyy')).to be_nil
|
90
88
|
end
|
91
89
|
|
92
90
|
it 'should compile unknown format for one off match' do
|
93
|
-
set.match('20001011').
|
94
|
-
set.match('20001011', 'yyyymmdd').
|
91
|
+
expect(set.match('20001011')).to be_nil
|
92
|
+
expect(set.match('20001011', 'yyyymmdd')).to be_kind_of(Array)
|
95
93
|
end
|
96
94
|
end
|
97
95
|
|