timeliness 0.3.10 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61304e47092ed4394992d7be784270fdb300cbfb82209398795fe50d37c9bc88
4
- data.tar.gz: 64d5a8f434688d5094210fb9d3f0563ea0d86052bd9e09a74d2f4a9e873d1df4
3
+ metadata.gz: 9692d6a370b0240cc872d67dbc79deaf5429b276ba3a8aa45049f9b77a70456c
4
+ data.tar.gz: c63f8a093f2e85909a7ecd4a894bc59d6929da07c3fd3ed445932a9e8474f535
5
5
  SHA512:
6
- metadata.gz: 70299983eed5a69131fa0411c553affae6ff98ff0896e5ef26a1a7b7e846b4091daa752a6798d51d328dd349fef2814db6381fe801945bd51eff8a820bb89eff
7
- data.tar.gz: '046963beb68a47fd1445872417342f4e5dff465376730ebf6aadff3259d3571e9c6845b9af85994247b593480ae778373279a42b99c6b7854c8befb520caacff'
6
+ metadata.gz: ff9b6afda36bd0829dca9b8133e4db5f2a6eeff6d076cec28a12c8a83fd5e1c2b0973cdb7b1b328bf6556755232a4d8c82ecaa362d5224806f8eefd185d5bee5
7
+ data.tar.gz: ffa9fd84e51518e61e4689ddb31bda87f4d297d6ed56a99e20e34563ba18a97412d6e95af2d2c5843498fa75fd3a26d7a82357405e56bfc99cfe314a3b5d67d3
@@ -1,7 +1,22 @@
1
1
  language: ruby
2
+ before_install:
3
+ - gem install bundler
4
+ cache: bundler
5
+
2
6
  rvm:
3
- - 1.9.3
4
- - ruby-head
5
- - jruby-19mode
6
- - rbx-19mode
7
+ # - jruby
8
+ # - truffleruby
9
+ # - rbx-3
10
+ - "2.3.8"
11
+ - "2.4.5"
12
+ - "2.5.3"
13
+ - "2.6.1"
14
+
7
15
  script: 'bundle exec rspec'
16
+
17
+ notifications:
18
+ email:
19
+ recipients:
20
+ - adam.meehan@gmail.com
21
+ on_failure: change
22
+ on_success: never
@@ -1,3 +1,20 @@
1
+ = 0.4.0 - 2019-02-09
2
+ * Add threadsafety for use_euro_formats & use_us_formats to allow runtime
3
+ switching (andruby, timdiggins)
4
+
5
+ = 0.3.10 - 2019-02-06
6
+ * Fixed file permissions in gem build
7
+
8
+ = 0.3.9 - 2019-02-03 [YANKED]
9
+ * Fix for parsing invalid datetime string with valid timezone raising exception (lni_T)
10
+ * Add license name in gemspec (Robert Reiz)
11
+ * Fix typo in README format example
12
+
13
+ = 0.3.8 - 2016-01-06
14
+ * Add formats for standard Ruby string representations of Time
15
+ * Updated specs to RSpec v3
16
+ * Added some gem specific exception classes
17
+
1
18
  = 0.3.7 - 2012-10-03
2
19
  * Change to a hot switch between US and Euro formats without a compile.
3
20
  * Fix date parsing with bad month name defaulting to 1 if year and day present.
@@ -1,4 +1,4 @@
1
- = Timeliness
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
3
  * Source: http://github.com/adzap/timeliness
4
4
  * Bugs: http://github.com/adzap/timeliness/issues
@@ -14,7 +14,7 @@ Date/time parser for Ruby with the following features:
14
14
  * I18n support (for months), if I18n gem loaded.
15
15
  * Fewer WTFs than Time/Date parse method.
16
16
  * Has no dependencies.
17
- * Works with Ruby MRI 1.8.*, 1.9.2, Rubinius and JRuby.
17
+ * Works with Ruby MRI >= 2.2
18
18
 
19
19
  Extracted from the {validates_timeliness gem}[http://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
@@ -2,7 +2,6 @@ $:.unshift(File.expand_path('lib'))
2
2
 
3
3
  require 'benchmark'
4
4
  require 'time'
5
- require 'parsedate' unless RUBY_VERSION =~ /^1\.9\./
6
5
  require 'timeliness'
7
6
 
8
7
  if defined?(JRUBY_VERSION)
@@ -2,6 +2,7 @@ require 'date'
2
2
  require 'forwardable'
3
3
 
4
4
  require 'timeliness/helpers'
5
+ require 'timeliness/threadsafe_attr'
5
6
  require 'timeliness/definitions'
6
7
  require 'timeliness/format'
7
8
  require 'timeliness/format_set'
@@ -151,8 +151,9 @@ module Timeliness
151
151
  DuplicateFormat = Class.new(StandardError)
152
152
 
153
153
  class << self
154
+ extend ThreadsafeAttr
154
155
  attr_accessor :time_formats, :date_formats, :datetime_formats, :format_tokens, :format_components, :timezone_mapping
155
- attr_reader :date_format_set, :time_format_set, :datetime_format_set
156
+ threadsafe_attr_accessor :date_format_set, :time_format_set, :datetime_format_set
156
157
 
157
158
  # Adds new formats. Must specify format type and can specify a :before
158
159
  # option to nominate which format the new formats should be inserted in
@@ -189,28 +190,28 @@ module Timeliness
189
190
  # Removes US date formats so that ambiguous dates are parsed as European format
190
191
  #
191
192
  def use_euro_formats
192
- @date_format_set = @euro_date_format_set
193
- @datetime_format_set = @euro_datetime_format_set
193
+ self.date_format_set = @euro_date_format_set
194
+ self.datetime_format_set = @euro_datetime_format_set
194
195
  end
195
196
 
196
197
  # Restores default to parse ambiguous dates as US format
197
198
  #
198
199
  def use_us_formats
199
- @date_format_set = @us_date_format_set
200
- @datetime_format_set = @us_datetime_format_set
200
+ self.date_format_set = @us_date_format_set
201
+ self.datetime_format_set = @us_datetime_format_set
201
202
  end
202
203
 
203
204
  def compile_formats
204
205
  @sorted_token_keys = nil
205
- @time_format_set = FormatSet.compile(time_formats)
206
+ self.time_format_set = FormatSet.compile(time_formats)
206
207
 
207
208
  @us_date_format_set = FormatSet.compile(date_formats)
208
209
  @us_datetime_format_set = FormatSet.compile(datetime_formats)
209
210
  @euro_date_format_set = FormatSet.compile(date_formats.select { |format| US_FORMAT_REGEXP !~ format })
210
211
  @euro_datetime_format_set = FormatSet.compile(datetime_formats.select { |format| US_FORMAT_REGEXP !~ format })
211
212
 
212
- @date_format_set = @us_date_format_set
213
- @datetime_format_set = @us_datetime_format_set
213
+ self.date_format_set = @us_date_format_set
214
+ self.datetime_format_set = @us_datetime_format_set
214
215
  end
215
216
 
216
217
  def sorted_token_keys
@@ -223,24 +224,24 @@ module Timeliness
223
224
  def format_sets(type, string)
224
225
  case type
225
226
  when :date
226
- [ @date_format_set, @datetime_format_set ]
227
+ [ date_format_set, datetime_format_set ]
227
228
  when :datetime
228
229
  if string.length < 11
229
- [ @date_format_set, @datetime_format_set ]
230
+ [ date_format_set, datetime_format_set ]
230
231
  else
231
- [ @datetime_format_set, @date_format_set ]
232
+ [ datetime_format_set, date_format_set ]
232
233
  end
233
234
  when :time
234
235
  if string.length < 11
235
- [ @time_format_set ]
236
+ [ time_format_set ]
236
237
  else
237
- [ @datetime_format_set, @time_format_set ]
238
+ [ datetime_format_set, time_format_set ]
238
239
  end
239
240
  else
240
241
  if string.length < 11
241
- [ @date_format_set, @time_format_set, @datetime_format_set ]
242
+ [ date_format_set, time_format_set, datetime_format_set ]
242
243
  else
243
- [ @datetime_format_set, @date_format_set, @time_format_set ]
244
+ [ datetime_format_set, date_format_set, time_format_set ]
244
245
  end
245
246
  end
246
247
  end
@@ -0,0 +1,24 @@
1
+ module Timeliness
2
+ module ThreadsafeAttr
3
+ def threadsafe_attr_accessor(*attrs)
4
+ attrs.each do |attr|
5
+ storage_name = "#{name}.#{attr}".freeze
6
+ reader attr, storage_name
7
+ writer attr, storage_name
8
+ end
9
+ end
10
+
11
+ private
12
+ def reader(attr, storage_name)
13
+ define_method(attr) do
14
+ Thread.current[storage_name]
15
+ end
16
+ end
17
+
18
+ def writer(attr, storage_name)
19
+ define_method("#{attr}=") do |value|
20
+ Thread.current[storage_name] = value
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module Timeliness
2
- VERSION = '0.3.10'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -101,4 +101,16 @@ describe Timeliness::Definitions do
101
101
  definitions.use_us_formats
102
102
  end
103
103
  end
104
+
105
+ context "threadsafety" do
106
+ it "should allow threadsafe use of regional formats" do
107
+ eu_date = "30/06/2016"
108
+ us_date = "06/30/2016"
109
+ threads = []
110
+ threads << Thread.new { Timeliness.use_euro_formats; sleep(0.005); Timeliness.parse(eu_date) }
111
+ threads << Thread.new { sleep(0.001); Timeliness.use_us_formats; Timeliness.parse(us_date) }
112
+ threads.each { |t| t.join }
113
+ threads.each { |t| expect(t.value).to eql(Time.new(2016,06,30)) }
114
+ end
115
+ end
104
116
  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.3.10
4
+ version: 0.4.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: 2019-02-05 00:00:00.000000000 Z
11
+ date: 2019-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -102,6 +102,7 @@ files:
102
102
  - lib/timeliness/format_set.rb
103
103
  - lib/timeliness/helpers.rb
104
104
  - lib/timeliness/parser.rb
105
+ - lib/timeliness/threadsafe_attr.rb
105
106
  - lib/timeliness/version.rb
106
107
  - spec/spec_helper.rb
107
108
  - spec/timeliness/core_ext/string_spec.rb