allscripts_unity_client 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -187,6 +187,11 @@ unity_client = AllscriptsUnityClient.create({
187
187
  })
188
188
  ```
189
189
 
190
+ ### Locale
191
+
192
+ This gem uses the [american_date](http://rubygems.org/gems/american_date) gem to force `Date.parse` to
193
+ accept USA locale dates by default. There are currently no plans to support other locales. Pull requests welcome.
194
+
190
195
  ## Examples
191
196
 
192
197
  ### GetServerInfo SOAP
@@ -28,6 +28,7 @@ Gem::Specification.new do |gem|
28
28
  gem.add_runtime_dependency "tzinfo", "~> 0.3.29"
29
29
  gem.add_runtime_dependency "nokogiri", "< 1.6", ">= 1.4.0"
30
30
  gem.add_runtime_dependency "nori", "~> 2.3.0"
31
+ gem.add_runtime_dependency "american_date", "~> 1.1.0"
31
32
 
32
33
  gem.add_development_dependency "factory_girl", "~> 4.2.0"
33
34
  gem.add_development_dependency "rake", "~> 10.1.0"
@@ -1,10 +1,11 @@
1
1
  require "nori"
2
2
  require "date"
3
+ require "american_date"
3
4
 
4
5
  module AllscriptsUnityClient
5
6
  class Utilities
6
- DATETIME_REGEX = /^((\d{1,2}[-\/]\d{1,2}[-\/]\d{4})|(\d{4}[-\/]\d{1,2}[-\/]\d{1,2})|([A-Za-z]{3,4} \d{1,2} \d{2,4}))(T| )\d{1,2}:\d{2}(:\d{2})?(\.\d+)? ?(PM|AM|pm|am)?((-|\+)\d{2}:?\d{2})?Z?$/
7
- DATE_REGEX = /^((\d{1,2}[-\/]\d{1,2}[-\/]\d{4})|(\d{4}[-\/]\d{1,2}[-\/]\d{1,2})|(\d{1,2}-[A-Za-z]{3,4}-\d{4}))$/
7
+ DATETIME_REGEX = /^((\d{1,2}[-\/]\d{1,2}[-\/]\d{4})|(\d{4}[-\/]\d{1,2}[-\/]\d{1,2})|(\d{1,2}-[A-Za-z]{3,4}-\d{4})|([A-Za-z]{3,4} \d{1,2} \d{2,4}))(T| +)(\d{1,2}:\d{2}(:\d{2})?(\.\d+)? ?(PM|AM|pm|am)?((-|\+)\d{2}:?\d{2})?Z?)$/
8
+ DATE_REGEX = /^((\d{1,2}[-\/]\d{1,2}[-\/]\d{4})|(\d{4}[-\/]\d{1,2}[-\/]\d{1,2})|(\d{1,2}-[A-Za-z]{3,4}-\d{4})|([A-Za-z]{3,4} \d{1,2} \d{2,4}))$/
8
9
 
9
10
  def self.try_to_encode_as_date(possible_date)
10
11
  if possible_date.nil?
@@ -1,3 +1,3 @@
1
1
  module AllscriptsUnityClient
2
- VERSION = "1.1.1"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -15,6 +15,17 @@ describe 'Utilities' do
15
15
  let(:string_keyed_hash) { FixtureLoader.load_yaml("string_keyed_hash.yml") }
16
16
  let(:symbol_keyed_hash) { FixtureLoader.load_yaml("symbol_keyed_hash.yml") }
17
17
 
18
+ let(:datetime_string_one) { 'Feb 27 2013 12:37PM' }
19
+ let(:datetime_string_two) { 'Feb 28 2013 1:34PM' }
20
+ let(:datetime_string_three) { '12/25/2013 12:37 PM' }
21
+ let(:datetime_one) { DateTime.parse(datetime_string_one) }
22
+ let(:datetime_two) { DateTime.parse(datetime_string_two) }
23
+ let(:datetime_three) { DateTime.parse(datetime_string_three) }
24
+ let(:date_string_one) { '20-Jul-2014' }
25
+ let(:date_string_two) { '12/25/2013' }
26
+ let(:date_one) { Date.parse(date_string_one) }
27
+ let(:date_two) { Date.parse(date_string_two) }
28
+
18
29
  describe '.try_to_encode_as_date' do
19
30
  context 'when given nil' do
20
31
  it { expect(subject.try_to_encode_as_date(nil)).to be_nil }
@@ -32,6 +43,36 @@ describe 'Utilities' do
32
43
  end
33
44
  end
34
45
 
46
+ context 'when given datetime_string_one' do
47
+ it 'returns the string as a DateTime' do
48
+ expect(subject.try_to_encode_as_date(datetime_string_one)).to eq(datetime_one)
49
+ end
50
+ end
51
+
52
+ context 'when given datetime_string_two' do
53
+ it 'returns the string as a DateTime' do
54
+ expect(subject.try_to_encode_as_date(datetime_string_two)).to eq(datetime_two)
55
+ end
56
+ end
57
+
58
+ context 'when given datetime_string_three' do
59
+ it 'returns the string as a DateTime' do
60
+ expect(subject.try_to_encode_as_date(datetime_string_three)).to eq(datetime_three)
61
+ end
62
+ end
63
+
64
+ context 'when given date_string_one' do
65
+ it 'returns the string as a Date' do
66
+ expect(subject.try_to_encode_as_date(date_string_one)).to eq(date_one)
67
+ end
68
+ end
69
+
70
+ context 'when given date_string_two' do
71
+ it 'returns the string as a Date' do
72
+ expect(subject.try_to_encode_as_date(date_string_two)).to eq(date_two)
73
+ end
74
+ end
75
+
35
76
  context 'when given a non-date string' do
36
77
  it 'returns that string' do
37
78
  expect(subject.try_to_encode_as_date(string)).to eq(string)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: allscripts_unity_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -114,6 +114,22 @@ dependencies:
114
114
  - - ~>
115
115
  - !ruby/object:Gem::Version
116
116
  version: 2.3.0
117
+ - !ruby/object:Gem::Dependency
118
+ name: american_date
119
+ requirement: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: 1.1.0
125
+ type: :runtime
126
+ prerelease: false
127
+ version_requirements: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ~>
131
+ - !ruby/object:Gem::Version
132
+ version: 1.1.0
117
133
  - !ruby/object:Gem::Dependency
118
134
  name: factory_girl
119
135
  requirement: !ruby/object:Gem::Requirement