neeto_time_zones 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 013c8849becad4287513786e7efab94203d1af6f59f6900b1a31a53bddd28cc9
4
- data.tar.gz: eb6a68776921b790645e26b4719773769d9a4e3bf9498cf47c5be855f55990e4
3
+ metadata.gz: 222407e5ba8abbf7a0ba84594ff11b1498400c1cd2884aa86229e20709e95ff9
4
+ data.tar.gz: 5d67c60d18e67503e1b9919b845a15ffe44b502b604a29e3c2068ab7cc8e9c03
5
5
  SHA512:
6
- metadata.gz: 6d13164ba3e289dd545dfbc5aa4c4a3ec21b0b98bc82768800915c686ada7424dfd4292d4bf08b1572b31ac3c1cd7df92f13db97b9cc8247c1074ba0986f40e9
7
- data.tar.gz: 244f6b695888eb3dce7a45252871576eed36ddbe8dde449e645caca4320b86b172b135f46e16d9b0864afe6494efcb006db338e27cd6d5243e32d92ebcbaebcd
6
+ metadata.gz: ceb924e0a9465d01b06ca91e3b69c56e50fefbfc50bda9f676462041764e05b2a1c83a5dd941376ba9cc42d7e3045dd68bfcfc81e1254d861b47fdd8325ea56f
7
+ data.tar.gz: a6aa1f392b38c6adfed4998ff65f1e838e267879f68c0898f680e7c5cef2496cf87c5b173adb95ac9e88521056161592885f8f3a5eddef679d93908959034ac0
@@ -0,0 +1,121 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NeetoTimeZones
4
+ class Constants
5
+ DATA_FILES = [
6
+ "africa.json",
7
+ "america.json",
8
+ "asia.json",
9
+ "atlantic.json",
10
+ "australia.json",
11
+ "europe.json",
12
+ "pacific.json",
13
+ "us_canada.json"
14
+ ]
15
+
16
+ # List of timezones supported by ActiveSupport::TimeZone
17
+ TIMEZONES = {
18
+ "Africa/Asmera" => "Africa/Asmara",
19
+ "America/Argentina/ComodRivadavia" => "America/Argentina/Catamarca",
20
+ "America/Buenos_Aires" => "America/Argentina/Buenos_Aires",
21
+ "America/Catamarca" => "America/Argentina/Catamarca",
22
+ "America/Cordoba" => "America/Argentina/Cordoba",
23
+ "America/Fort_Wayne" => "America/Indiana/Indianapolis",
24
+ "America/Godthab" => "America/Nuuk",
25
+ "America/Indianapolis" => "America/Indiana/Indianapolis",
26
+ "America/Jujuy" => "America/Argentina/Jujuy",
27
+ "America/Knox_IN" => "America/Indiana/Knox",
28
+ "America/Louisville" => "America/Kentucky/Louisville",
29
+ "America/Mendoza" => "America/Argentina/Mendoza",
30
+ "America/Rosario" => "America/Argentina/Rosario",
31
+ "Antarctica/South_Pole" => "Antarctica/McMurdo",
32
+ "Asia/Ashkhabad" => "Asia/Ashgabat",
33
+ "Asia/Calcutta" => "Asia/Kolkata",
34
+ "Asia/Chungking" => "Asia/Shanghai",
35
+ "Asia/Dacca" => "Asia/Dhaka",
36
+ "Asia/Katmandu" => "Asia/Kathmandu",
37
+ "Asia/Macao" => "Asia/Macau",
38
+ "Asia/Rangoon" => "Asia/Yangon",
39
+ "Asia/Saigon" => "Asia/Ho_Chi_Minh",
40
+ "Asia/Thimbu" => "Asia/Thimphu",
41
+ "Asia/Ujung_Pandang" => "Asia/Makassar",
42
+ "Asia/Ulan_Bator" => "Asia/Ulaanbaatar",
43
+ "Atlantic/Faeroe" => "Atlantic/Faroe",
44
+ "Australia/ACT" => "Australia/Sydney",
45
+ "Australia/LHI" => "Australia/Lord_Howe",
46
+ "Australia/NSW" => "Australia/Sydney",
47
+ "Australia/North" => "Australia/Darwin",
48
+ "Australia/Queensland" => "Australia/Brisbane",
49
+ "Australia/South" => "Australia/Adelaide",
50
+ "Australia/Tasmania" => "Australia/Hobart",
51
+ "Australia/Victoria" => "Australia/Melbourne",
52
+ "Australia/West" => "Australia/Perth",
53
+ "Brazil/Acre" => "America/Rio_Branco",
54
+ "Brazil/DeNoronha" => "America/Noronha",
55
+ "Brazil/East" => "America/Sao_Paulo",
56
+ "Brazil/West" => "America/Manaus",
57
+ "Canada/Atlantic" => "America/Halifax",
58
+ "Canada/Central" => "America/Winnipeg",
59
+ "Canada/Eastern" => "America/Toronto",
60
+ "Canada/Mountain" => "America/Edmonton",
61
+ "Canada/Newfoundland" => "America/St_Johns",
62
+ "Canada/Pacific" => "America/Vancouver",
63
+ "Canada/Saskatchewan" => "America/Regina",
64
+ "Canada/Yukon" => "America/Whitehorse",
65
+ "Chile/Continental" => "America/Santiago",
66
+ "Chile/EasterIsland" => "Pacific/Easter",
67
+ "Cuba" => "America/Havana",
68
+ "Egypt" => "Africa/Cairo",
69
+ "Eire" => "Europe/Dublin",
70
+ "Europe/Kiev" => "Europe/Kyiv",
71
+ "Europe/Uzhgorod" => "Europe/Uzhhorod",
72
+ "Europe/Zaporozhye" => "Europe/Zaporizhzhia",
73
+ "GB" => "Europe/London",
74
+ "GB-Eire" => "Europe/London",
75
+ "GMT+0" => "Etc/GMT",
76
+ "GMT-0" => "Etc/GMT",
77
+ "GMT0" => "Etc/GMT",
78
+ "Greenwich" => "Etc/GMT",
79
+ "Hongkong" => "Asia/Hong_Kong",
80
+ "Iceland" => "Atlantic/Reykjavik",
81
+ "Iran" => "Asia/Tehran",
82
+ "Israel" => "Asia/Jerusalem",
83
+ "Jamaica" => "America/Jamaica",
84
+ "Japan" => "Asia/Tokyo",
85
+ "Kwajalein" => "Pacific/Kwajalein",
86
+ "Libya" => "Africa/Tripoli",
87
+ "Mexico/BajaNorte" => "America/Tijuana",
88
+ "Mexico/BajaSur" => "America/Mazatlan",
89
+ "Mexico/General" => "America/Mexico_City",
90
+ "NZ" => "Pacific/Auckland",
91
+ "NZ-CHAT" => "Pacific/Chatham",
92
+ "Navajo" => "America/Denver",
93
+ "PRC" => "Asia/Shanghai",
94
+ "Pacific/Enderbury" => "Pacific/Kanton",
95
+ "Pacific/Ponape" => "Pacific/Pohnpei",
96
+ "Pacific/Truk" => "Pacific/Chuuk",
97
+ "Poland" => "Europe/Warsaw",
98
+ "Portugal" => "Europe/Lisbon",
99
+ "ROC" => "Asia/Taipei",
100
+ "ROK" => "Asia/Seoul",
101
+ "Singapore" => "Asia/Singapore",
102
+ "Turkey" => "Europe/Istanbul",
103
+ "UCT" => "Etc/UCT",
104
+ "US/Alaska" => "America/Anchorage",
105
+ "US/Aleutian" => "America/Adak",
106
+ "US/Arizona" => "America/Phoenix",
107
+ "US/Central" => "America/Chicago",
108
+ "US/East-Indiana" => "America/Indiana/Indianapolis",
109
+ "US/Eastern" => "America/New_York",
110
+ "US/Hawaii" => "Pacific/Honolulu",
111
+ "US/Indiana-Starke" => "America/Indiana/Knox",
112
+ "US/Michigan" => "America/Detroit",
113
+ "US/Mountain" => "America/Denver",
114
+ "US/Pacific" => "America/Los_Angeles",
115
+ "US/Samoa" => "Pacific/Pago_Pago",
116
+ "Universal" => "Etc/UTC",
117
+ "W-SU" => "Europe/Moscow",
118
+ "Zulu" => "Etc/UTC"
119
+ }
120
+ end
121
+ end
@@ -4,20 +4,9 @@ require "json"
4
4
 
5
5
  module NeetoTimeZones
6
6
  class Utils
7
- DATA_FILES = [
8
- "africa.json",
9
- "america.json",
10
- "asia.json",
11
- "atlantic.json",
12
- "australia.json",
13
- "europe.json",
14
- "pacific.json",
15
- "us_canada.json"
16
- ]
17
-
18
7
  def self.time_zones
19
8
  base_path = File.expand_path("../../data", File.dirname(__FILE__))
20
- time_zone_hash ||= DATA_FILES.flat_map do |file_name|
9
+ time_zone_hash ||= Constants::DATA_FILES.flat_map do |file_name|
21
10
  json_data = File.read(File.join(base_path, file_name))
22
11
  JSON.parse(json_data, symbolize_names: true)
23
12
  end
@@ -27,5 +16,10 @@ module NeetoTimeZones
27
16
  time_zone = time_zones.find { |time_zone| time_zone[:utc].include?(iana_time_zone) }
28
17
  time_zone&.fetch(:label, nil)
29
18
  end
19
+
20
+ # This method sanitizes the browser timezone to the ones supported by ActiveSupport::TimeZone.
21
+ def self.sanitize_timezone(timezone)
22
+ Constants::TIMEZONES[timezone] || timezone
23
+ end
30
24
  end
31
25
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NeetoTimeZones
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
@@ -1,3 +1,4 @@
1
+ require_relative "neeto_time_zones/constants"
1
2
  require_relative "neeto_time_zones/utils"
2
3
 
3
4
  module NeetoTimeZones
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neeto_time_zones
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Calvin Chiramal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-02 00:00:00.000000000 Z
11
+ date: 2024-09-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -33,8 +33,8 @@ files:
33
33
  - data/europe.json
34
34
  - data/pacific.json
35
35
  - data/us_canada.json
36
- - lib/README.md
37
36
  - lib/neeto_time_zones.rb
37
+ - lib/neeto_time_zones/constants.rb
38
38
  - lib/neeto_time_zones/utils.rb
39
39
  - lib/neeto_time_zones/version.rb
40
40
  homepage: https://github.com/bigbinary/neeto-time-zones
data/lib/README.md DELETED
@@ -1,35 +0,0 @@
1
- # NeetoTimeZones
2
-
3
- A simple and lightweight Ruby gem for working with time zones. This gem provides utility functions for timezones.
4
-
5
- ## Installation
6
-
7
- Install the gem and add to the application's Gemfile by executing:
8
-
9
- bundle add neeto_time_zones
10
-
11
- If bundler is not being used to manage dependencies, install the gem by executing:
12
-
13
- gem install neeto_time_zones
14
-
15
- ## Usage
16
-
17
- ### iana_timezone_to_human_readable
18
-
19
- ```ruby
20
- NeetoTimeZones::Utils.iana_timezone_to_human_readable("Asia/Calcutta") # => Indian Standard Time
21
- NeetoTimeZones::Utils.iana_timezone_to_human_readable("America/New_York") # => Eastern Standard Time
22
- NeetoTimeZones::Utils.iana_timezone_to_human_readable("Europe/Berlin") # => Central Standard Time
23
- ```
24
-
25
- ## Development
26
-
27
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
-
29
- ## Contributing
30
-
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/bigbinary/neeto_time_zones.
32
-
33
- ## License
34
-
35
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).