timeliness 0.4.5 → 0.5.0
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/CHANGELOG.rdoc +11 -2
- data/lib/timeliness/definitions.rb +3 -1
- data/lib/timeliness/format.rb +2 -1
- data/lib/timeliness/format_set.rb +6 -6
- data/lib/timeliness/parser.rb +14 -7
- data/lib/timeliness/version.rb +1 -1
- data/spec/timeliness_helper.rb +7 -7
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23fc962cb22262464b617a95fc8690f5b94400ee5de69fc110166975bf59fd40
|
4
|
+
data.tar.gz: fead9e440fb74611873e5ab1a89747514072602d961f01a3c1d96c9d1b052610
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee38a67400fbe0b4bb9141eb359f3c8462a0a1d61b8c21b4bed1e7cc655bb4ac91246894abd8a4a25f279d1cfd94c0ef0d03cda034f76cea14adef01af5dba6d
|
7
|
+
data.tar.gz: 7310005faf480be6392f5c7838d2ea4e0ad9391a6cedd77a1f65709c6c93963b11131ccc5b2c9ceafa5a5dc3efde90b30fe0b06b61bbe183b8911ede2019f3bf
|
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
= 0.5.0 - 2024-12-02
|
2
|
+
* Reduce allocations through some internal parsing changes
|
3
|
+
* Changed parse method arg handling to simple using keyword args
|
4
|
+
|
5
|
+
= 0.4.5 - 2023-01-19
|
6
|
+
* Support case insensitive months
|
7
|
+
* Migrated to Github Actions (@petergoldstein)
|
8
|
+
* Various doc, spec, and gemspec fixes and updates (@tagliala)
|
9
|
+
|
1
10
|
= 0.4.4 - 2019-08-06
|
2
11
|
* Raise compilation error if token with capturing arg is used more than once in a format
|
3
12
|
* Some small internal refactorings in format compilation
|
@@ -10,7 +19,7 @@
|
|
10
19
|
= 0.4.2 - 2019-06-15
|
11
20
|
* Fixed thread safe issue that forced you to use one of the date format methods e.g. `use_euro_formats`
|
12
21
|
to initialize the format sets in each new thread. Now a new thread will default to the global default (main thread).
|
13
|
-
* Add `Timeliness.ambiguous_date_format` config setting (:us or :euro) to control global default for date format sets.
|
22
|
+
* Add `Timeliness.ambiguous_date_format` config setting (:us or :euro) to control global default for date format sets.
|
14
23
|
|
15
24
|
= 0.4.1 - 2019-06-11
|
16
25
|
* Add format for ISO 8601 with usec and 'Z' UTC zone offset (jartek)
|
@@ -19,7 +28,7 @@
|
|
19
28
|
|
20
29
|
= 0.4.0 - 2019-02-09
|
21
30
|
* Add threadsafety for use_euro_formats & use_us_formats to allow runtime
|
22
|
-
switching (andruby, timdiggins)
|
31
|
+
switching (andruby, timdiggins)
|
23
32
|
|
24
33
|
= 0.3.10 - 2019-02-06
|
25
34
|
* Fixed file permissions in gem build
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Timeliness
|
2
4
|
module Definitions
|
3
5
|
|
@@ -80,7 +82,7 @@ module Timeliness
|
|
80
82
|
'yyyy-mm-ddThh:nn:sszt', # ISO 8601 with 'Zulu time' (i.e. Z) UTC zone designator
|
81
83
|
'yyyy-mm-ddThh:nn:ss.u', # ISO 8601 with usec
|
82
84
|
'yyyy-mm-ddThh:nn:ss.uzo', # ISO 8601 with usec and offset
|
83
|
-
'yyyy-mm-ddThh:nn:ss.uzt', # ISO 8601 with usec and 'Zulu time' (i.e. Z) UTC zone designator
|
85
|
+
'yyyy-mm-ddThh:nn:ss.uzt', # ISO 8601 with usec and 'Zulu time' (i.e. Z) UTC zone designator
|
84
86
|
'yyyy-mm-dd hh:nn:ss zo', # Ruby time string in later versions
|
85
87
|
'yyyy-mm-dd hh:nn:ss tz', # Ruby time string for UTC in later versions
|
86
88
|
]
|
data/lib/timeliness/format.rb
CHANGED
@@ -46,7 +46,7 @@ module Timeliness
|
|
46
46
|
|
47
47
|
define_process_method(token_order.compact)
|
48
48
|
@regexp_string = format
|
49
|
-
@regexp = Regexp.new("^(
|
49
|
+
@regexp = Regexp.new("^(?>#{format})$")
|
50
50
|
self
|
51
51
|
rescue => ex
|
52
52
|
raise CompilationFailed, "The format '#{format_string}' failed to compile using regexp string #{format}. Error message: #{ex.inspect}"
|
@@ -63,6 +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
|
+
components << '*_' # absorb any excess arguments not used by format
|
66
67
|
instance_eval <<-DEF
|
67
68
|
def process(#{components.join(',')})
|
68
69
|
[#{values.map { |i| i || 'nil' }.join(',')}]
|
@@ -20,8 +20,8 @@ module Timeliness
|
|
20
20
|
format = Format.new(format_string).compile!
|
21
21
|
@formats_hash[format_string] = format
|
22
22
|
@match_indexes[index] = format
|
23
|
-
regexp_string
|
24
|
-
index + format.token_count
|
23
|
+
regexp_string.concat("(?>#{format.regexp_string})|")
|
24
|
+
index + format.token_count
|
25
25
|
}
|
26
26
|
@regexp = %r[\A(?:#{regexp_string.chop})\z]
|
27
27
|
self
|
@@ -31,10 +31,10 @@ module Timeliness
|
|
31
31
|
format = single_format(format_string) if format_string
|
32
32
|
match_regexp = format && format.regexp || @regexp
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
values =
|
34
|
+
match_regexp.match(string) do |match_data|
|
35
|
+
captures = match_data.captures # For a multi-format regexp there are lots of nils
|
36
|
+
index = captures.find_index { |e| !e.nil? } # Find the start of captures for matched format
|
37
|
+
values = captures.values_at(index..(index+7))
|
38
38
|
format ||= @match_indexes[index]
|
39
39
|
format.process(*values)
|
40
40
|
end
|
data/lib/timeliness/parser.rb
CHANGED
@@ -4,11 +4,14 @@ module Timeliness
|
|
4
4
|
|
5
5
|
class << self
|
6
6
|
|
7
|
-
def parse(value,
|
7
|
+
def parse(value, type=nil, **options)
|
8
8
|
return value if acts_like_temporal?(value)
|
9
9
|
return nil unless parseable?(value)
|
10
10
|
|
11
|
-
type
|
11
|
+
if type && !type.is_a?(Symbol)
|
12
|
+
options[:now] = type if type
|
13
|
+
type = nil
|
14
|
+
end
|
12
15
|
|
13
16
|
time_array = _parse(value, type, options)
|
14
17
|
return nil if time_array.nil?
|
@@ -40,7 +43,7 @@ module Timeliness
|
|
40
43
|
Definitions.send("#{type}_format_set").match(string, options[:format])
|
41
44
|
else
|
42
45
|
values = nil
|
43
|
-
Definitions.format_sets(type, string).
|
46
|
+
Definitions.format_sets(type, string).any? { |set| values = set.match(string, options[:format]) }
|
44
47
|
values
|
45
48
|
end
|
46
49
|
rescue
|
@@ -95,8 +98,10 @@ module Timeliness
|
|
95
98
|
|
96
99
|
def current_time_in_zone(zone)
|
97
100
|
case zone
|
98
|
-
when :utc
|
99
|
-
Time.now.
|
101
|
+
when :utc
|
102
|
+
Time.now.getutc
|
103
|
+
when :local
|
104
|
+
Time.now.getlocal
|
100
105
|
when :current
|
101
106
|
Time.current
|
102
107
|
else
|
@@ -107,8 +112,10 @@ module Timeliness
|
|
107
112
|
def shift_time_to_zone(time, zone=nil)
|
108
113
|
zone ||= Timeliness.configuration.default_timezone
|
109
114
|
case zone
|
110
|
-
when :utc
|
111
|
-
time.
|
115
|
+
when :utc
|
116
|
+
time.getutc
|
117
|
+
when :local
|
118
|
+
time.getlocal
|
112
119
|
when :current
|
113
120
|
time.in_time_zone
|
114
121
|
else
|
data/lib/timeliness/version.rb
CHANGED
data/spec/timeliness_helper.rb
CHANGED
@@ -12,20 +12,20 @@ module TimelinessHelpers
|
|
12
12
|
Timeliness::Definitions
|
13
13
|
end
|
14
14
|
|
15
|
-
def parse(
|
16
|
-
Timeliness::Parser.parse(
|
15
|
+
def parse(value, type=nil, **args)
|
16
|
+
Timeliness::Parser.parse(value, type, **args)
|
17
17
|
end
|
18
18
|
|
19
19
|
def current_date(options={})
|
20
20
|
Timeliness::Parser.send(:current_date, options)
|
21
21
|
end
|
22
22
|
|
23
|
-
def should_parse(
|
24
|
-
expect(Timeliness::Parser.parse(
|
23
|
+
def should_parse(value, type=nil, **args)
|
24
|
+
expect(Timeliness::Parser.parse(value, type, **args)).not_to be_nil
|
25
25
|
end
|
26
26
|
|
27
|
-
def should_not_parse(
|
28
|
-
expect(Timeliness::Parser.parse(
|
27
|
+
def should_not_parse(value, type=nil, **args)
|
28
|
+
expect(Timeliness::Parser.parse(value, type, **args)).to be_nil
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -38,4 +38,4 @@ RSpec.configure do |c|
|
|
38
38
|
c.after do
|
39
39
|
Timeliness.configuration = Timeliness::Configuration.new
|
40
40
|
end
|
41
|
-
end
|
41
|
+
end
|
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
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Meehan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
132
|
- !ruby/object:Gem::Version
|
133
133
|
version: '0'
|
134
134
|
requirements: []
|
135
|
-
rubygems_version: 3.
|
135
|
+
rubygems_version: 3.3.27
|
136
136
|
signing_key:
|
137
137
|
specification_version: 4
|
138
138
|
summary: Date/time parsing for the control freak.
|