string_date_accessors 0.0.3 → 0.0.4
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.
- data/VERSION +1 -1
- data/lib/string_date_accessors.rb +18 -6
- data/spec/string_date_accessors_spec.rb +32 -3
- data/string_date_accessors.gemspec +2 -2
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
@@ -1,11 +1,19 @@
|
|
1
1
|
require 'date'
|
2
2
|
module StringDateAccessors
|
3
|
-
def self.
|
4
|
-
@
|
3
|
+
def self.date_format=(string)
|
4
|
+
@date_format = string
|
5
5
|
end
|
6
6
|
|
7
|
-
def self.
|
8
|
-
@
|
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
|
-
|
24
|
+
DateTime.strptime(input, datetime_format)
|
17
25
|
rescue ArgumentError
|
18
|
-
|
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.
|
14
|
+
StringDateAccessors.date_format = '%Y/%m/%d'
|
15
15
|
end
|
16
16
|
|
17
17
|
describe "UK format" do
|
18
18
|
before do
|
19
|
-
StringDateAccessors.
|
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.
|
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-
|
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
|
-
-
|
9
|
-
version: 0.0.
|
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-
|
17
|
+
date: 2010-03-28 00:00:00 +00:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|