timeliness 0.4.4 → 0.4.5
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 +4 -4
- data/.github/workflows/ci.yml +23 -0
- data/.travis.yml +12 -9
- data/LICENSE +1 -1
- data/README.rdoc +9 -9
- data/Rakefile +3 -2
- data/lib/timeliness/format.rb +1 -1
- data/lib/timeliness/format_set.rb +1 -1
- data/lib/timeliness/helpers.rb +1 -1
- data/lib/timeliness/parser.rb +1 -1
- data/lib/timeliness/version.rb +1 -1
- data/spec/timeliness/format_spec.rb +20 -0
- data/spec/timeliness/parser_spec.rb +3 -3
- data/timeliness.gemspec +0 -2
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84ca036a36065acf094c147e896f73f7ed729c36859688bfb1f1e7a68f3617a9
|
4
|
+
data.tar.gz: 0a30d2da9fd78e795c9fe915ca40918b77f14b4944cf30a7476e8fbe0f6ea9ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8b18ee49649d7a1a58abeb8d981929807b37b750b3bd4b2f305ac9df7dac467cb2505fa8f2a9309a6b61f86728d16d7bd32de8a7d99960360f26599aacdd3fc
|
7
|
+
data.tar.gz: 3567ce98af3d217e3935560e0e924a6a39c083e32dee114bfc717c0a26933e2e3fb88a912444df8bb21c80f2f4633e9043225ff88759a3e52b963e453cd9a80b
|
@@ -0,0 +1,23 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
|
10
|
+
strategy:
|
11
|
+
fail-fast: false
|
12
|
+
matrix:
|
13
|
+
ruby: ["2.5", "2.6", "2.7", "3.0", "3.1", ruby-head, jruby-9.2, jruby-9.3, jruby-head]
|
14
|
+
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v2
|
17
|
+
- name: Set up Ruby
|
18
|
+
uses: ruby/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
bundler-cache: true # 'bundle install' and cache gems
|
21
|
+
ruby-version: ${{ matrix.ruby }}
|
22
|
+
- name: Run tests
|
23
|
+
run: bundle exec rspec
|
data/.travis.yml
CHANGED
@@ -1,16 +1,19 @@
|
|
1
|
+
dist: focal
|
2
|
+
os: linux
|
1
3
|
language: ruby
|
2
|
-
before_install:
|
3
|
-
- gem install bundler
|
4
|
+
before_install: gem install bundler
|
4
5
|
cache: bundler
|
5
6
|
|
6
7
|
rvm:
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
- "
|
11
|
-
-
|
12
|
-
|
13
|
-
|
8
|
+
- "2.5.8"
|
9
|
+
- "2.6.6"
|
10
|
+
- "2.7.2"
|
11
|
+
- "3.0.0"
|
12
|
+
- ruby-head
|
13
|
+
|
14
|
+
jobs:
|
15
|
+
allow_failures:
|
16
|
+
- rvm: ruby-head
|
14
17
|
|
15
18
|
script: 'bundle exec rspec'
|
16
19
|
|
data/LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
= Timeliness {<img src="https://travis-ci.org/adzap/timeliness.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/adzap/timeliness]
|
2
2
|
|
3
|
-
* Source:
|
4
|
-
* Bugs:
|
3
|
+
* Source: https://github.com/adzap/timeliness
|
4
|
+
* Bugs: https://github.com/adzap/timeliness/issues
|
5
5
|
|
6
6
|
== Description
|
7
7
|
|
@@ -16,7 +16,7 @@ Date/time parser for Ruby with the following features:
|
|
16
16
|
* Has no dependencies.
|
17
17
|
* Works with Ruby MRI >= 2.2
|
18
18
|
|
19
|
-
Extracted from the {validates_timeliness gem}[
|
19
|
+
Extracted from the {validates_timeliness gem}[https://github.com/adzap/validates_timeliness], it has been rewritten cleaner and much faster. It's most suitable for when
|
20
20
|
you need to control the parsing behaviour. It's faster than the Time/Date class parse methods, so it
|
21
21
|
has general appeal.
|
22
22
|
|
@@ -51,14 +51,14 @@ ignored.
|
|
51
51
|
|
52
52
|
=== Specify the Current Date
|
53
53
|
|
54
|
-
Notice a time only string will return with a date value. The date value can be configured globally
|
54
|
+
Notice a time only string will return with a date value. The date value can be configured globally
|
55
55
|
with this setting:
|
56
56
|
|
57
57
|
Timeliness.date_for_time_type = [2010, 1, 1]
|
58
58
|
|
59
59
|
or using a lambda thats evaluated when parsed
|
60
60
|
|
61
|
-
Timeliness.date_for_time_type = lambda { Time.now }
|
61
|
+
Timeliness.date_for_time_type = lambda { Time.now }
|
62
62
|
|
63
63
|
It can also be specified with :now option:
|
64
64
|
|
@@ -143,7 +143,7 @@ You just need to add this line to an initializer or other application file:
|
|
143
143
|
|
144
144
|
== Formats
|
145
145
|
|
146
|
-
The gem has default formats included which can be easily added to using the format syntax. Also
|
146
|
+
The gem has default formats included which can be easily added to using the format syntax. Also
|
147
147
|
formats can be easily removed so that they are no longer considered valid.
|
148
148
|
|
149
149
|
Below are the default formats. If you think they are easy to read then you will be happy to know
|
@@ -228,7 +228,7 @@ Here is what each format token means:
|
|
228
228
|
All other characters are considered literal. For the technically minded, these formats are compiled
|
229
229
|
into a single regular expression
|
230
230
|
|
231
|
-
To see all defined formats look at the {source code}[
|
231
|
+
To see all defined formats look at the {source code}[https://github.com/adzap/timeliness/tree/master/lib/timeliness/formats.rb].
|
232
232
|
|
233
233
|
|
234
234
|
== Settings
|
@@ -252,7 +252,7 @@ You can switch back to US formats with
|
|
252
252
|
|
253
253
|
==== Thread Safety
|
254
254
|
|
255
|
-
The switching of formats is threadsafe (since v0.4.0), however for each new thread the format default will be
|
255
|
+
The switching of formats is threadsafe (since v0.4.0), however for each new thread the format default will be
|
256
256
|
the gem default, being the US format. To control default for your app and each new thread, use the config
|
257
257
|
|
258
258
|
Timeliness.ambiguous_date_format = :euro
|
@@ -301,7 +301,7 @@ Now you get:
|
|
301
301
|
|
302
302
|
== Credits
|
303
303
|
|
304
|
-
* Adam Meehan (adam.meehan@gmail.com,
|
304
|
+
* Adam Meehan (adam.meehan@gmail.com, https://github.com/adzap)
|
305
305
|
|
306
306
|
|
307
307
|
== License
|
data/Rakefile
CHANGED
@@ -15,10 +15,11 @@ end
|
|
15
15
|
|
16
16
|
desc 'Generate documentation for plugin.'
|
17
17
|
Rake::RDocTask.new(:rdoc) do |rdoc|
|
18
|
+
rdoc.main = 'README.rdoc'
|
18
19
|
rdoc.rdoc_dir = 'rdoc'
|
19
20
|
rdoc.title = 'Timeliness'
|
20
|
-
rdoc.options << '--line-numbers'
|
21
|
-
rdoc.rdoc_files.include('README')
|
21
|
+
rdoc.options << '--line-numbers'
|
22
|
+
rdoc.rdoc_files.include('README.rdoc')
|
22
23
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
24
|
end
|
24
25
|
|
data/lib/timeliness/format.rb
CHANGED
@@ -63,7 +63,7 @@ module Timeliness
|
|
63
63
|
position, code = Definitions.format_components[component]
|
64
64
|
values[position] = code || "#{component}.to_i" if position
|
65
65
|
end
|
66
|
-
instance_eval
|
66
|
+
instance_eval <<-DEF
|
67
67
|
def process(#{components.join(',')})
|
68
68
|
[#{values.map { |i| i || 'nil' }.join(',')}]
|
69
69
|
end
|
data/lib/timeliness/helpers.rb
CHANGED
@@ -23,7 +23,7 @@ module Timeliness
|
|
23
23
|
|
24
24
|
def month_index(month)
|
25
25
|
return month.to_i if month.to_i > 0 || /0+/ =~ month
|
26
|
-
month.length > 3 ? month_names
|
26
|
+
(month.length > 3 ? month_names : abbr_month_names).index { |str| month.casecmp?(str) }
|
27
27
|
end
|
28
28
|
|
29
29
|
def month_names
|
data/lib/timeliness/parser.rb
CHANGED
@@ -40,7 +40,7 @@ module Timeliness
|
|
40
40
|
Definitions.send("#{type}_format_set").match(string, options[:format])
|
41
41
|
else
|
42
42
|
values = nil
|
43
|
-
Definitions.format_sets(type, string).find {|set| values = set.match(string, options[:format]) }
|
43
|
+
Definitions.format_sets(type, string).find { |set| values = set.match(string, options[:format]) }
|
44
44
|
values
|
45
45
|
end
|
46
46
|
rescue
|
data/lib/timeliness/version.rb
CHANGED
@@ -91,6 +91,26 @@ describe Timeliness::Format do
|
|
91
91
|
expect(format.process('2', 'Enero', '2000')).to eq [2000,1,2,nil,nil,nil,nil,nil]
|
92
92
|
end
|
93
93
|
|
94
|
+
context "with upper case month abbreviations" do
|
95
|
+
before(:all) do
|
96
|
+
I18n.backend.store_translations :es, date: { abbr_month_names: %w{ ~ ENE FEB MAR } }
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'should parse abbreviated month for current locale case insensitively' do
|
100
|
+
expect(format_for('d-mmm-yyyy').process('01', 'mar', '2023')).to eq [2023,3,1,nil,nil,nil,nil,nil]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context "with upper case month names" do
|
105
|
+
before(:all) do
|
106
|
+
I18n.backend.store_translations :es, date: { month_names: %w{ ~ ENERO FEBRERO MARZO } }
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should parse full month for current locale case insensitively' do
|
110
|
+
expect(format_for('d-mmm-yyyy').process('01', 'mArZo', '2023')).to eq [2023,3,1,nil,nil,nil,nil,nil]
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
94
114
|
after(:all) do
|
95
115
|
I18n.locale = :en
|
96
116
|
end
|
@@ -6,7 +6,7 @@ describe Timeliness::Parser do
|
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
-
around
|
9
|
+
around do |example|
|
10
10
|
current_zone = Time.zone
|
11
11
|
example.call
|
12
12
|
Time.zone = current_zone
|
@@ -104,13 +104,13 @@ describe Timeliness::Parser do
|
|
104
104
|
it 'should return value shifted by positive offset in default timezone' do
|
105
105
|
value = parse("2000-06-01T12:00:00+02:00")
|
106
106
|
expect(value).to eq Time.zone.local(2000,6,1,3,0,0)
|
107
|
-
expect(value.utc_offset).to eq
|
107
|
+
expect(value.utc_offset).to eq(-7.hours)
|
108
108
|
end
|
109
109
|
|
110
110
|
it 'should return value shifted by negative offset in default timezone' do
|
111
111
|
value = parse("2000-06-01T12:00:00-01:00")
|
112
112
|
expect(value).to eq Time.zone.local(2000,6,1,6,0,0)
|
113
|
-
expect(value.utc_offset).to eq
|
113
|
+
expect(value.utc_offset).to eq(-7.hours)
|
114
114
|
end
|
115
115
|
end
|
116
116
|
end
|
data/timeliness.gemspec
CHANGED
@@ -13,8 +13,6 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.description = %q{Fast date/time parser with customisable formats, timezone and I18n support.}
|
14
14
|
s.license = "MIT"
|
15
15
|
|
16
|
-
s.rubyforge_project = %q{timeliness}
|
17
|
-
|
18
16
|
s.add_development_dependency 'activesupport', '>= 3.2'
|
19
17
|
s.add_development_dependency 'tzinfo', '>= 0.3.31'
|
20
18
|
s.add_development_dependency 'rspec', '~> 3.4'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timeliness
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Meehan
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -88,6 +88,7 @@ extra_rdoc_files:
|
|
88
88
|
- README.rdoc
|
89
89
|
- CHANGELOG.rdoc
|
90
90
|
files:
|
91
|
+
- ".github/workflows/ci.yml"
|
91
92
|
- ".travis.yml"
|
92
93
|
- CHANGELOG.rdoc
|
93
94
|
- LICENSE
|
@@ -116,7 +117,7 @@ homepage: http://github.com/adzap/timeliness
|
|
116
117
|
licenses:
|
117
118
|
- MIT
|
118
119
|
metadata: {}
|
119
|
-
post_install_message:
|
120
|
+
post_install_message:
|
120
121
|
rdoc_options: []
|
121
122
|
require_paths:
|
122
123
|
- lib
|
@@ -131,9 +132,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
132
|
- !ruby/object:Gem::Version
|
132
133
|
version: '0'
|
133
134
|
requirements: []
|
134
|
-
|
135
|
-
|
136
|
-
signing_key:
|
135
|
+
rubygems_version: 3.1.6
|
136
|
+
signing_key:
|
137
137
|
specification_version: 4
|
138
138
|
summary: Date/time parsing for the control freak.
|
139
139
|
test_files: []
|