string_date_accessors 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -1,11 +1,19 @@
1
1
  require 'date'
2
2
  module StringDateAccessors
3
- def self.format=(string)
4
- @format = string
3
+ def self.date_format=(string)
4
+ @date_format = string
5
5
  end
6
6
 
7
- def self.format
8
- @format
7
+ def self.date_format
8
+ @date_format
9
+ end
10
+
11
+ def self.datetime_format=(string)
12
+ @datetime_format = string
13
+ end
14
+
15
+ def self.datetime_format
16
+ @datetime_format
9
17
  end
10
18
 
11
19
  def self.included(klass)
@@ -13,9 +21,13 @@ module StringDateAccessors
13
21
  end
14
22
 
15
23
  def self.formatted(input)
16
- Date.strptime(input, format)
24
+ DateTime.strptime(input, datetime_format)
17
25
  rescue ArgumentError
18
- input
26
+ begin
27
+ Date.strptime(input, date_format)
28
+ rescue ArgumentError
29
+ input
30
+ end
19
31
  end
20
32
 
21
33
  def invalid_date_accessors
@@ -11,15 +11,30 @@ end
11
11
 
12
12
  describe StringDateAccessors do
13
13
  before do
14
- StringDateAccessors.format = '%Y/%m/%d'
14
+ StringDateAccessors.date_format = '%Y/%m/%d'
15
15
  end
16
16
 
17
17
  describe "UK format" do
18
18
  before do
19
- StringDateAccessors.format = '%d/%m/%y'
19
+ StringDateAccessors.date_format = '%d/%m/%y'
20
+ StringDateAccessors.datetime_format = '%d/%m/%y %H:%M'
20
21
  end
21
22
 
22
- context "entering strings with slashes" do
23
+ context "entering time strings with slashes" do
24
+ subject do
25
+ inheritor = StringDateInheritor.new
26
+ inheritor.punched_on = '11/12/09 15:03'
27
+ inheritor.punched_on
28
+ end
29
+
30
+ its(:min) { should == 3 }
31
+ its(:hour) { should == 15 }
32
+ its(:day) { should == 11 }
33
+ its(:month) { should == 12 }
34
+ its(:year) { should == 2009 }
35
+ end
36
+
37
+ context "entering date strings with slashes" do
23
38
  subject do
24
39
  inheritor = StringDateInheritor.new
25
40
  inheritor.punched_on = '11/12/09'
@@ -69,6 +84,20 @@ describe StringDateAccessors do
69
84
  its(:year) { should == 2011 }
70
85
  end
71
86
 
87
+ context "entering DateTime objects" do
88
+ subject do
89
+ inheritor = StringDateInheritor.new
90
+ inheritor.punched_on = DateTime.new(2011, 12, 11, 15, 30)
91
+ inheritor.punched_on
92
+ end
93
+
94
+ its(:min) { should == 30 }
95
+ its(:hour) { should == 15 }
96
+ its(:day) { should == 11 }
97
+ its(:month) { should == 12 }
98
+ its(:year) { should == 2011 }
99
+ end
100
+
72
101
  context "entering blank strings" do
73
102
  subject do
74
103
  inheritor = StringDateInheritor.new
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{string_date_accessors}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andrew Bruce"]
12
- s.date = %q{2010-03-27}
12
+ s.date = %q{2010-03-28}
13
13
  s.description = %q{
14
14
  This gem is useful if you don't want to use Rails' standard date helpers and would rather
15
15
  set a text format for reading and writing dates.
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Andrew Bruce
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-27 00:00:00 +00:00
17
+ date: 2010-03-28 00:00:00 +00:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency