timezone 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -41,3 +41,10 @@ Finally, pass the coordinates to your timezone initialization function.
41
41
  => "Australia/Adelaide"
42
42
  timezone.time Time.now
43
43
  => 2011-02-12 12:02:13 UTC
44
+
45
+ ## Getting the complete list of timezones.
46
+
47
+ Retrieving the complete list of timezones is quite simple:
48
+
49
+ timezones = Timezone::Zone.names
50
+ => ["Africa/Abidjan", "Africa/Accra", "Africa/Addis_Ababa", "Africa/Algiers", ...]
@@ -1,3 +1,3 @@
1
1
  module Timezone
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -10,6 +10,8 @@ module Timezone
10
10
  include Comparable
11
11
  attr_accessor :rules, :zone
12
12
 
13
+ ZONE_FILE_PATH = File.expand_path(File.dirname(__FILE__)+'/../../data')
14
+
13
15
  # Create a new Timezone object.
14
16
  #
15
17
  # Timezone.new(options)
@@ -30,14 +32,34 @@ module Timezone
30
32
 
31
33
  raise Timezone::Error::NilZone, 'No zone was found. Please specify a zone.' if options[:zone].nil?
32
34
 
33
- file = File.join File.expand_path(File.dirname(__FILE__)+'/../../data'), "#{options[:zone]}.json"
34
- raise Timezone::Error::InvalidZone, "'#{options[:zone]}' is not a valid zone." unless File.exists?(file)
35
+ data = Zone.get_zone_data(options[:zone])
35
36
 
36
- data = JSON.parse(open(file).read)
37
37
  @rules = data['zone']
38
38
  @zone = data['_zone'] || options[:zone]
39
39
  end
40
40
 
41
+
42
+ class << self
43
+
44
+ # Retrieve the data from a particular time zone
45
+ def get_zone_data(zone)
46
+ file = File.join(ZONE_FILE_PATH, "#{zone}.json")
47
+ begin
48
+ return JSON.parse(open(file).read)
49
+ rescue
50
+ raise Timezone::Error::InvalidZone, "'#{zone}' is not a valid zone."
51
+ end
52
+ end
53
+
54
+ # Instantly grab all possible time zone names.
55
+ def names
56
+ Dir[File.join(ZONE_FILE_PATH, "**/**/*.json")].collect do |file|
57
+ file.gsub("#{ZONE_FILE_PATH}/", '').gsub(/\.json/, '')
58
+ end
59
+ end
60
+
61
+ end
62
+
41
63
  # Determine the time in the timezone.
42
64
  #
43
65
  # timezone.time(reference)
@@ -22,6 +22,13 @@ class TimezoneTest < Test::Unit::TestCase
22
22
  end
23
23
  end
24
24
 
25
+ def test_timezone_names
26
+ zones = Timezone::Zone.names
27
+ assert zones.is_a?(Array)
28
+ assert zones.count > 0
29
+ assert zones.include? "Australia/Sydney"
30
+ end
31
+
25
32
  def time_timezone_equivalence
26
33
  gmt = Timezone::Zone.new :zone => 'GMT'
27
34
  australia = Timezone::Zone.new :zone => 'Australia/Sydney'
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.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-06-06 00:00:00.000000000 -07:00
13
- default_executable:
12
+ date: 2011-10-21 00:00:00.000000000Z
14
13
  dependencies: []
15
14
  description: A simple way to get accurate current and historical timezone information
16
15
  based on zone or latitude and longitude coordinates. This gem uses the tz database
@@ -495,7 +494,6 @@ files:
495
494
  - lib/timezone/zone.rb
496
495
  - test/timezone_test.rb
497
496
  - timezone.gemspec
498
- has_rdoc: true
499
497
  homepage: http://github.com/panthomakos/timezone
500
498
  licenses: []
501
499
  post_install_message:
@@ -517,9 +515,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
517
515
  version: '0'
518
516
  requirements: []
519
517
  rubyforge_project: timezone
520
- rubygems_version: 1.6.2
518
+ rubygems_version: 1.8.6
521
519
  signing_key:
522
520
  specification_version: 3
523
- summary: timezone-0.1.2
521
+ summary: timezone-0.1.3
524
522
  test_files:
525
523
  - test/timezone_test.rb