weatherzone 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/weatherzone.rb CHANGED
@@ -22,5 +22,5 @@ require 'weatherzone/helpers/date_parser'
22
22
  require 'weatherzone/helpers/units'
23
23
 
24
24
  module Weatherzone
25
- VERSION = '0.8.2'
25
+ VERSION = '0.8.3'
26
26
  end
@@ -19,11 +19,15 @@ module Weatherzone
19
19
  has_attribute :tz, :on_elements => methods
20
20
  define_method "#{method_name}_utc" do
21
21
  tz = TZInfo::Timezone.get("Australia/#{send("#{method_name}_tz")}")
22
- tz.local_to_utc(Time.parse(instance_variable_get("@#{method_name}")))
22
+ if value = instance_variable_get("@#{method_name}")
23
+ tz.local_to_utc(Time.parse(value))
24
+ end
23
25
  end
24
26
  define_method method_name do
25
- tz = TZInfo::Timezone.get("Australia/#{send("#{method_name}_tz")}")
26
- tz.utc_to_local send("#{method_name}_utc")
27
+ if value = send("#{method_name}_utc")
28
+ tz = TZInfo::Timezone.get("Australia/#{send("#{method_name}_tz")}")
29
+ tz.utc_to_local value
30
+ end
27
31
  end
28
32
  end
29
33
  end
@@ -2,10 +2,15 @@ require File.dirname(__FILE__) + '/test_helper.rb'
2
2
 
3
3
  class TestDateParser < Test::Unit::TestCase
4
4
 
5
- class SomeResource
5
+ class SomeResource < Weatherzone::Resource
6
6
  include Weatherzone::Helpers::DateParser
7
- attr_writer :created_at
7
+ attr_writer :created_at, :issue_time_local
8
8
  interpret_as_date :created_at
9
+ interpret_as_time :issue_time_local
10
+
11
+ def issue_time_local_tz
12
+ "EST"
13
+ end
9
14
  end
10
15
 
11
16
  def test_parses_date
@@ -14,10 +19,30 @@ class TestDateParser < Test::Unit::TestCase
14
19
  assert_equal Date.parse("12/04/1972"), resource.created_at
15
20
  end
16
21
 
17
- def test_doesnt_bork_on_nils
22
+ def test_doesnt_raise_on_nil_dates
18
23
  resource = SomeResource.new
19
24
  resource.created_at = nil
20
25
  assert_equal nil, resource.created_at
21
26
  end
27
+
28
+ def test_parses_time
29
+ time = "2009-08-12T09:17:00"
30
+
31
+ tz = TZInfo::Timezone.get("Australia/EST")
32
+ expected_utc = tz.local_to_utc(Time.parse(time))
33
+
34
+ resource = SomeResource.new
35
+ resource.issue_time_local = time
36
+
37
+ assert_equal expected_utc, resource.issue_time_local_utc
38
+ assert_equal tz.utc_to_local(expected_utc), resource.issue_time_local
39
+ end
40
+
41
+ def test_doesnt_raise_on_nil_times
42
+ resource = SomeResource.new
43
+ resource.issue_time_local = nil
44
+ assert_equal nil, resource.issue_time_local_utc
45
+ assert_equal nil, resource.issue_time_local
46
+ end
22
47
 
23
48
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 8
8
- - 2
9
- version: 0.8.2
8
+ - 3
9
+ version: 0.8.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ben Askins