Skip to content

Commit

Permalink
Merge branch 'master' into version1
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil Goodman committed Dec 9, 2013
2 parents 0b484ba + cd5f3ba commit 9ad95ef
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/allscripts_unity_client/utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

module AllscriptsUnityClient
class Utilities
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?)$/
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}))$/
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?)$/
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}))$/

def self.try_to_encode_as_date(possible_date)
if possible_date.nil?
Expand Down
2 changes: 1 addition & 1 deletion lib/allscripts_unity_client/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module AllscriptsUnityClient
VERSION = "1.2.3"
VERSION = "1.2.4"
end
16 changes: 16 additions & 0 deletions spec/utilities_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@
let(:datetime_string_one) { 'Feb 27 2013 12:37PM' }
let(:datetime_string_two) { 'Feb 28 2013 1:34PM' }
let(:datetime_string_three) { '12/25/2013 12:37 PM' }
let(:datetime_string_four) { 'Nov 1 2011 11:31AM' }
let(:datetime_one) { DateTime.parse(datetime_string_one) }
let(:datetime_two) { DateTime.parse(datetime_string_two) }
let(:datetime_three) { DateTime.parse(datetime_string_three) }
let(:datetime_four) { DateTime.parse(datetime_string_four) }
let(:date_string_one) { '20-Jul-2014' }
let(:date_string_two) { '12/25/2013' }
let(:date_string_three) { 'Nov 1 2011' }
let(:date_one) { Date.parse(date_string_one) }
let(:date_two) { Date.parse(date_string_two) }
let(:date_three) { Date.parse(date_string_three) }

describe '.try_to_encode_as_date' do
context 'when given nil' do
Expand Down Expand Up @@ -61,6 +65,12 @@
end
end

context 'when given datetime_string_four' do
it 'returns the string as a DateTime' do
expect(subject.try_to_encode_as_date(datetime_string_four)).to eq(datetime_four)
end
end

context 'when given date_string_one' do
it 'returns the string as a Date' do
expect(subject.try_to_encode_as_date(date_string_one)).to eq(date_one)
Expand All @@ -73,6 +83,12 @@
end
end

context 'when given date_string_three' do
it 'returns the string as a Date' do
expect(subject.try_to_encode_as_date(date_string_three)).to eq(date_three)
end
end

context 'when given a non-date string' do
it 'returns that string' do
expect(subject.try_to_encode_as_date(string)).to eq(string)
Expand Down

0 comments on commit 9ad95ef

Please sign in to comment.