timezone 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/timezone/version.rb +1 -1
- data/lib/timezone/zone.rb +15 -3
- data/test/timezone_test.rb +14 -2
- metadata +4 -4
data/lib/timezone/version.rb
CHANGED
data/lib/timezone/zone.rb
CHANGED
@@ -2,11 +2,12 @@ require 'json'
|
|
2
2
|
require 'date'
|
3
3
|
require 'time'
|
4
4
|
require 'net/http'
|
5
|
-
require '
|
6
|
-
require '
|
5
|
+
require File.expand_path(File.dirname(__FILE__) + '/error')
|
6
|
+
require File.expand_path(File.dirname(__FILE__) + '/configure')
|
7
7
|
|
8
8
|
module Timezone
|
9
9
|
class Zone
|
10
|
+
include Comparable
|
10
11
|
attr_accessor :rules, :zone
|
11
12
|
|
12
13
|
# Create a new Timezone object.
|
@@ -51,7 +52,18 @@ module Timezone
|
|
51
52
|
rule = rules.detect{ |rule| _parsetime(rule['_from']) <= reference && _parsetime(rule['_to']) >= reference }
|
52
53
|
reference + rule['offset']
|
53
54
|
end
|
54
|
-
|
55
|
+
|
56
|
+
# Get the current UTC offset in seconds for this timezone.
|
57
|
+
#
|
58
|
+
# timezone.utc_offset
|
59
|
+
def utc_offset
|
60
|
+
@rules.last['offset']-(@rules.last['dst'] ? 3600 : 0)
|
61
|
+
end
|
62
|
+
|
63
|
+
def <=> zone #:nodoc:
|
64
|
+
utc_offset <=> zone.utc_offset
|
65
|
+
end
|
66
|
+
|
55
67
|
private
|
56
68
|
|
57
69
|
def timezone_id lat, lon #:nodoc:
|
data/test/timezone_test.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../lib/timezone')
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/../lib/timezone/zone')
|
3
|
-
require File.expand_path(File.dirname(__FILE__) + '/../lib/timezone/error')
|
4
|
-
require File.expand_path(File.dirname(__FILE__) + '/../lib/timezone/configure')
|
5
3
|
require 'test/unit'
|
6
4
|
|
7
5
|
class TimezoneTest < Test::Unit::TestCase
|
@@ -24,6 +22,20 @@ class TimezoneTest < Test::Unit::TestCase
|
|
24
22
|
end
|
25
23
|
end
|
26
24
|
|
25
|
+
def time_timezone_equivalence
|
26
|
+
gmt = Timezone::Zone.new :zone => 'GMT'
|
27
|
+
australia = Timezone::Zone.new :zone => 'Australia/Sydney'
|
28
|
+
assert gmt == gmt
|
29
|
+
assert gmt <= australia
|
30
|
+
assert gmt < australia
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_getting_utc_offset
|
34
|
+
assert_equal 36000, Timezone::Zone.new(:zone => 'Australia/Sydney').utc_offset
|
35
|
+
assert_equal -28800, Timezone::Zone.new(:zone => 'America/Los_Angeles').utc_offset
|
36
|
+
assert_equal 20700, Timezone::Zone.new(:zone => 'Asia/Kathmandu').utc_offset
|
37
|
+
end
|
38
|
+
|
27
39
|
def test_loading_GMT_timezone
|
28
40
|
timezone = Timezone::Zone.new :zone => 'GMT'
|
29
41
|
assert_equal Time.now.utc.to_i, timezone.time(Time.now).to_i
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: timezone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Pan Thomakos
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-02-
|
13
|
+
date: 2011-02-22 00:00:00 -08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -520,9 +520,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
520
520
|
requirements: []
|
521
521
|
|
522
522
|
rubyforge_project: timezone
|
523
|
-
rubygems_version: 1.5.
|
523
|
+
rubygems_version: 1.5.2
|
524
524
|
signing_key:
|
525
525
|
specification_version: 3
|
526
|
-
summary: timezone-0.1.
|
526
|
+
summary: timezone-0.1.1
|
527
527
|
test_files:
|
528
528
|
- test/timezone_test.rb
|