string_date_accessors 0.0.6 → 0.0.7

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 CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.0.7
@@ -25,13 +25,19 @@ module StringDateAccessors
25
25
  def self.formatted(input)
26
26
  date = Date.strptime(input, date_format)
27
27
  zone = date.to_time.zone
28
- DateTime.strptime("#{input} #{zone}", "#{datetime_format} %Z").to_time
28
+ datetime_utc = DateTime.strptime("#{input} #{zone}", "#{datetime_format} %Z").to_time.utc
29
+ Time.utc(datetime_utc.year,
30
+ datetime_utc.month,
31
+ datetime_utc.day,
32
+ datetime_utc.hour,
33
+ datetime_utc.min,
34
+ datetime_utc.sec)
29
35
  rescue ArgumentError, NoMethodError => e
30
36
  date ? date : input
31
37
  end
32
38
 
33
39
  def invalid_date_accessors
34
- string_date_accessors_set.reject {|attribute| send(attribute).is_a?(Date)}
40
+ string_date_accessors_set.reject {|attribute| send(attribute).respond_to?(:strftime)}
35
41
  end
36
42
 
37
43
  def string_date_accessors_set
@@ -1,12 +1,12 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  class ModelBase
4
- attr_accessor :punched_on, :patched_up_on
4
+ attr_accessor :punched_on, :patched_up_on, :fell_at
5
5
  end
6
6
 
7
7
  class StringDateInheritor < ModelBase
8
8
  include StringDateAccessors
9
- string_date_accessors :punched_on, :patched_up_on
9
+ string_date_accessors :punched_on, :patched_up_on, :fell_at
10
10
  end
11
11
 
12
12
  describe StringDateAccessors do
@@ -16,11 +16,11 @@ describe StringDateAccessors do
16
16
 
17
17
  describe "formatted" do
18
18
  context "datetime" do
19
- it "should add the current timezone" do
19
+ it "should convert to UTC" do
20
20
  input = '21/05/10 10:30'
21
21
  StringDateAccessors.datetime_format = '%d/%m/%y %H:%M'
22
22
  Time.stub(:zone).and_return('(GMT+00:00) London')
23
- StringDateAccessors.formatted(input).zone.should == '+01:00'
23
+ StringDateAccessors.formatted(input).zone.should == 'UTC'
24
24
  end
25
25
  end
26
26
  end
@@ -43,6 +43,7 @@ describe StringDateAccessors do
43
43
  its(:day) { should == 11 }
44
44
  its(:month) { should == 12 }
45
45
  its(:year) { should == 2009 }
46
+ it { should be_a(Time) }
46
47
  end
47
48
 
48
49
  context "entering date strings with slashes" do
@@ -55,6 +56,7 @@ describe StringDateAccessors do
55
56
  its(:day) { should == 11 }
56
57
  its(:month) { should == 12 }
57
58
  its(:year) { should == 2009 }
59
+ it { should be_a(Date) }
58
60
  end
59
61
  end
60
62
 
@@ -63,11 +65,13 @@ describe StringDateAccessors do
63
65
  inheritor = StringDateInheritor.new
64
66
  inheritor.punched_on = 'bad'
65
67
  inheritor.patched_up_on = '2009/12/25'
68
+ inheritor.fell_at = '25/05/10 15:00'
66
69
  inheritor
67
70
  end
68
71
 
69
72
  its(:invalid_date_accessors) { should include(:punched_on) }
70
73
  its(:invalid_date_accessors) { should_not include(:patched_up_on) }
74
+ its(:invalid_date_accessors) { should_not include(:fell_at) }
71
75
  end
72
76
 
73
77
  describe "date accessor" do
@@ -81,6 +85,7 @@ describe StringDateAccessors do
81
85
  its(:day) { should == 11 }
82
86
  its(:month) { should == 12 }
83
87
  its(:year) { should == 2011 }
88
+ it { should be_a(Date) }
84
89
  end
85
90
 
86
91
  context "entering Date objects" do
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{string_date_accessors}
8
- s.version = "0.0.6"
8
+ s.version = "0.0.7"
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"]
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 6
9
- version: 0.0.6
8
+ - 7
9
+ version: 0.0.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Andrew Bruce