neeto_time_zones 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 013c8849becad4287513786e7efab94203d1af6f59f6900b1a31a53bddd28cc9
4
- data.tar.gz: eb6a68776921b790645e26b4719773769d9a4e3bf9498cf47c5be855f55990e4
3
+ metadata.gz: 52a854e7953c495b3c0d506404d1d2a7d261ca94148d54a4a40c7a243d20a033
4
+ data.tar.gz: a41c0489065e0b52d326e66316eb87d03fdc34530488f513cf3272adfc71de91
5
5
  SHA512:
6
- metadata.gz: 6d13164ba3e289dd545dfbc5aa4c4a3ec21b0b98bc82768800915c686ada7424dfd4292d4bf08b1572b31ac3c1cd7df92f13db97b9cc8247c1074ba0986f40e9
7
- data.tar.gz: 244f6b695888eb3dce7a45252871576eed36ddbe8dde449e645caca4320b86b172b135f46e16d9b0864afe6494efcb006db338e27cd6d5243e32d92ebcbaebcd
6
+ metadata.gz: 7a8c02686e17ff383c48f6724d3ba611e6082d4b3ea68d027b2ffd2c97b6b695f8a5f571c6a397478260df48523afa45a9b174199b0ae8ef1c78439ee77c3a17
7
+ data.tar.gz: 4f1af2a73b45a067138b33c283332ba61d3a23d630e5c9e0a77cd2ce26460f831c84b3a60fc5beba756c031a64b826333173b8e695cef437016fc9f109903fb8
@@ -0,0 +1,123 @@
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/Kyiv",
72
+ "Europe/Zaporozhye" => "Europe/Kyiv",
73
+ "Europe/Uzhhorod" => "Europe/Kyiv",
74
+ "Europe/Zaporizhzhia" => "Europe/Kyiv",
75
+ "GB" => "Europe/London",
76
+ "GB-Eire" => "Europe/London",
77
+ "GMT+0" => "Etc/GMT",
78
+ "GMT-0" => "Etc/GMT",
79
+ "GMT0" => "Etc/GMT",
80
+ "Greenwich" => "Etc/GMT",
81
+ "Hongkong" => "Asia/Hong_Kong",
82
+ "Iceland" => "Atlantic/Reykjavik",
83
+ "Iran" => "Asia/Tehran",
84
+ "Israel" => "Asia/Jerusalem",
85
+ "Jamaica" => "America/Jamaica",
86
+ "Japan" => "Asia/Tokyo",
87
+ "Kwajalein" => "Pacific/Kwajalein",
88
+ "Libya" => "Africa/Tripoli",
89
+ "Mexico/BajaNorte" => "America/Tijuana",
90
+ "Mexico/BajaSur" => "America/Mazatlan",
91
+ "Mexico/General" => "America/Mexico_City",
92
+ "NZ" => "Pacific/Auckland",
93
+ "NZ-CHAT" => "Pacific/Chatham",
94
+ "Navajo" => "America/Denver",
95
+ "PRC" => "Asia/Shanghai",
96
+ "Pacific/Enderbury" => "Pacific/Kanton",
97
+ "Pacific/Ponape" => "Pacific/Pohnpei",
98
+ "Pacific/Truk" => "Pacific/Chuuk",
99
+ "Poland" => "Europe/Warsaw",
100
+ "Portugal" => "Europe/Lisbon",
101
+ "ROC" => "Asia/Taipei",
102
+ "ROK" => "Asia/Seoul",
103
+ "Singapore" => "Asia/Singapore",
104
+ "Turkey" => "Europe/Istanbul",
105
+ "UCT" => "Etc/UCT",
106
+ "US/Alaska" => "America/Anchorage",
107
+ "US/Aleutian" => "America/Adak",
108
+ "US/Arizona" => "America/Phoenix",
109
+ "US/Central" => "America/Chicago",
110
+ "US/East-Indiana" => "America/Indiana/Indianapolis",
111
+ "US/Eastern" => "America/New_York",
112
+ "US/Hawaii" => "Pacific/Honolulu",
113
+ "US/Indiana-Starke" => "America/Indiana/Knox",
114
+ "US/Michigan" => "America/Detroit",
115
+ "US/Mountain" => "America/Denver",
116
+ "US/Pacific" => "America/Los_Angeles",
117
+ "US/Samoa" => "Pacific/Pago_Pago",
118
+ "Universal" => "Etc/UTC",
119
+ "W-SU" => "Europe/Moscow",
120
+ "Zulu" => "Etc/UTC"
121
+ }
122
+ end
123
+ 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,20 @@ 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] || ActiveSupport::TimeZone[timezone]&.tzinfo&.name || timezone
23
+ end
24
+
25
+ def self.sanitize_time_zone!(time_zone)
26
+ sanitized_time_zone = Constants::TIMEZONES[time_zone] || ActiveSupport::TimeZone[time_zone]&.tzinfo&.name
27
+
28
+ if sanitized_time_zone.nil?
29
+ raise ArgumentError, "Invalid timezone: #{time_zone}"
30
+ else
31
+ sanitized_time_zone
32
+ end
33
+ end
30
34
  end
31
35
  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.3"
5
5
  end
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "neeto_time_zones/constants"
1
4
  require_relative "neeto_time_zones/utils"
2
5
 
3
6
  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.3
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-11-25 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).