timezone 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -14,7 +14,8 @@ Then install your bundle.
14
14
 
15
15
  ## Getting Started
16
16
 
17
- Getting the current time or any historical time in any timezone, with daylight savings time taken into consideration, is easy:
17
+ Getting the current time or any historical time in any timezone, with daylight
18
+ savings time taken into consideration, is easy:
18
19
 
19
20
  timezone = Timezone::Zone.new :zone => 'America/Los_Angeles'
20
21
  timezone.time Time.now
@@ -22,7 +23,19 @@ Getting the current time or any historical time in any timezone, with daylight s
22
23
  timezone.time Time.utc(2010, 1, 1, 0, 0, 0)
23
24
  => 2009-12-31 16:00:00 UTC
24
25
 
25
- Time is always returned in the UTC timezone, but it accurately reflects the actual time in the specified timezone. The reason for this is that this function also takes into account daylight savings time, which can alter the timezone offset and hence put Ruby in the wrong timezone.
26
+ Time is always returned in the UTC timezone, but it accurately reflects the
27
+ actual time in the specified timezone. The reason for this is that this function
28
+ also takes into account daylight savings time, which can alter the timezone
29
+ offset and hence put Ruby in the wrong timezone.
30
+
31
+ You can also query a `Timezone::Zone` object to determine if it was in Daylight
32
+ Savings Time:
33
+
34
+ timezone = Timezone::Zone.new :zone => 'America/Los_Angeles'
35
+ timezone.dst?(Time.now)
36
+ => true
37
+ timezone.dst?(Time.utc(2010, 1, 1, 0, 0, 0))
38
+ => false
26
39
 
27
40
  ## Getting the timezone for a specific latitude and longitude
28
41
 
@@ -1,3 +1,3 @@
1
1
  module Timezone
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
data/lib/timezone/zone.rb CHANGED
@@ -56,6 +56,11 @@ module Timezone
56
56
  reference.utc + rule_for_reference(reference)['offset']
57
57
  end
58
58
 
59
+ # Whether or not the time in the timezone is in DST.
60
+ def dst?(reference)
61
+ rule_for_reference(reference)['dst']
62
+ end
63
+
59
64
  # Get the current UTC offset in seconds for this timezone.
60
65
  #
61
66
  # timezone.utc_offset(reference)
@@ -100,6 +105,7 @@ module Timezone
100
105
  list = self.names.select { |name| zones.include? name } # only select zones if they exist
101
106
 
102
107
  @zones = []
108
+ now = Time.now
103
109
  list.each do |zone|
104
110
  item = Zone.new(zone: zone)
105
111
  @zones << {
@@ -107,7 +113,7 @@ module Timezone
107
113
  :title => Configure.replacements[item.zone] || item.zone,
108
114
  :offset => item.utc_offset,
109
115
  :utc_offset => (item.utc_offset/(60*60)),
110
- :dst => item.time(Time.now).dst?
116
+ :dst => item.dst?(now)
111
117
  }
112
118
  end
113
119
  @zones.sort_by! { |zone| zone[Configure.order_list_by] }
@@ -1,6 +1,7 @@
1
1
  require 'timezone'
2
2
  require 'timezone/zone'
3
3
  require 'test/unit'
4
+ require 'timecop'
4
5
 
5
6
  class TimezoneTest < Test::Unit::TestCase
6
7
  def test_valid_timezone
@@ -29,6 +30,15 @@ class TimezoneTest < Test::Unit::TestCase
29
30
  assert list.first[:zone] == "Australia/Sydney"
30
31
  end
31
32
 
33
+ def test_timezone_list
34
+ Timecop.freeze(Time.new(2012,2,2,0,0,0)) do
35
+ assert !Timezone::Zone.list('EST5EDT').first[:dst]
36
+ end
37
+ Timecop.freeze(Time.new(2013,6,6,0,0,0)) do
38
+ assert Timezone::Zone.list('EST5EDT').first[:dst]
39
+ end
40
+ end
41
+
32
42
  def test_timezone_custom_list_order
33
43
  Timezone::Configure.order_list_by = :title
34
44
  Timezone::Configure.replace "America/Chicago", with: "Chicago"
data/timezone.gemspec CHANGED
@@ -23,4 +23,5 @@ Gem::Specification.new do |s|
23
23
 
24
24
  s.add_development_dependency('rake')
25
25
  s.add_development_dependency('minitest', '~> 4.0')
26
+ s.add_development_dependency('timecop')
26
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timezone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-11 00:00:00.000000000 Z
12
+ date: 2013-10-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
45
  version: '4.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: timecop
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
46
62
  description: A simple way to get accurate current and historical timezone information
47
63
  based on zone or latitude and longitude coordinates. This gem uses the tz database
48
64
  (http://www.twinsun.com/tz/tz-link.htm) for historical timezone information. It
@@ -581,7 +597,7 @@ rubyforge_project: timezone
581
597
  rubygems_version: 1.8.23
582
598
  signing_key:
583
599
  specification_version: 3
584
- summary: timezone-0.3.0
600
+ summary: timezone-0.3.1
585
601
  test_files:
586
602
  - test/data/Helsinki_rules_without_timestamps.json
587
603
  - test/data/asia