string_date_accessors 0.0.5 → 0.0.6
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/README.rdoc +4 -4
- data/VERSION +1 -1
- data/lib/string_date_accessors.rb +6 -7
- data/spec/string_date_accessors_spec.rb +11 -0
- data/string_date_accessors.gemspec +2 -2
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
Get and set dates as strings on ActiveRecord-like objects.
|
4
4
|
|
5
5
|
This gem is useful if you don't want to use Rails' standard date helpers and would rather
|
6
|
-
set a text format for reading and writing dates.
|
6
|
+
set a text format for reading and writing dates and datetimes.
|
7
7
|
|
8
8
|
== Usage
|
9
9
|
|
@@ -11,7 +11,7 @@ set a text format for reading and writing dates.
|
|
11
11
|
require 'ostruct'
|
12
12
|
require 'string_date_accessors'
|
13
13
|
|
14
|
-
StringDateAccessors.
|
14
|
+
StringDateAccessors.date_format = '%d/%m/%y'
|
15
15
|
|
16
16
|
class Lady < OpenStruct
|
17
17
|
include StringDateAccessors
|
@@ -41,7 +41,7 @@ set a text format for reading and writing dates.
|
|
41
41
|
|
42
42
|
== Installation
|
43
43
|
|
44
|
-
It's on gemcutter (gem install string_date_accessors).
|
44
|
+
It's on gemcutter (gem install string_date_accessors). It requires active_support.
|
45
45
|
|
46
46
|
== Note on Patches/Pull Requests
|
47
47
|
|
@@ -56,4 +56,4 @@ It's on gemcutter (gem install string_date_accessors).
|
|
56
56
|
|
57
57
|
== Copyright
|
58
58
|
|
59
|
-
Copyright (c)
|
59
|
+
Copyright (c) 2010 Andrew Bruce. See LICENSE for details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'rubygems'
|
1
2
|
require 'date'
|
2
3
|
require 'active_support'
|
3
4
|
module StringDateAccessors
|
@@ -22,13 +23,11 @@ module StringDateAccessors
|
|
22
23
|
end
|
23
24
|
|
24
25
|
def self.formatted(input)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
input
|
31
|
-
end
|
26
|
+
date = Date.strptime(input, date_format)
|
27
|
+
zone = date.to_time.zone
|
28
|
+
DateTime.strptime("#{input} #{zone}", "#{datetime_format} %Z").to_time
|
29
|
+
rescue ArgumentError, NoMethodError => e
|
30
|
+
date ? date : input
|
32
31
|
end
|
33
32
|
|
34
33
|
def invalid_date_accessors
|
@@ -14,6 +14,17 @@ describe StringDateAccessors do
|
|
14
14
|
StringDateAccessors.date_format = '%Y/%m/%d'
|
15
15
|
end
|
16
16
|
|
17
|
+
describe "formatted" do
|
18
|
+
context "datetime" do
|
19
|
+
it "should add the current timezone" do
|
20
|
+
input = '21/05/10 10:30'
|
21
|
+
StringDateAccessors.datetime_format = '%d/%m/%y %H:%M'
|
22
|
+
Time.stub(:zone).and_return('(GMT+00:00) London')
|
23
|
+
StringDateAccessors.formatted(input).zone.should == '+01:00'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
17
28
|
describe "UK format" do
|
18
29
|
before do
|
19
30
|
StringDateAccessors.date_format = '%d/%m/%y'
|
@@ -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.6"
|
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-
|
12
|
+
s.date = %q{2010-05-23}
|
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
|
+
- 6
|
9
|
+
version: 0.0.6
|
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-
|
17
|
+
date: 2010-05-23 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|