Last active
November 12, 2015 17:27
-
-
Save fnordfish/2ad3909044a6fbe7d09e to your computer and use it in GitHub Desktop.
generate a list of all current UTC offsets for a given country
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env duct # ruby | |
| # Usage: | |
| # duct current_uts_offsets.rb <Country as its ISO 3166 code> <strftime-format> | |
| # Example: | |
| # duct current_uts_offsets.rb US | |
| # #=> US: -0500 -0600 -0700 -0800 -0900 -1000 | |
| # duct current_uts_offsets.rb RU '%:z' | |
| # #=> RU: +02:00 +03:00 +04:00 +05:00 +06:00 +07:00 +08:00 +09:00 +10:00 +11:00 +12:00 | |
| require 'time' | |
| require 'tzinfo' | |
| require 'active_support/time' | |
| identifier = ARGV[0] || "US" | |
| format = ARGV[1] || "%z" | |
| now = Time.now.utc | |
| zones = TZInfo::Country.get(identifier).zone_identifiers.map { |z| | |
| now.in_time_zone(z).strftime(format) | |
| }.uniq | |
| puts "#{identifier}: #{zones.join(" ")}" | |
| __END__ | |
| @@ Gemfile | |
| source 'https://rubygems.org' | |
| gem 'activesupport', '~> 3.2.22' | |
| gem 'tzinfo', '~> 1.2.2' | |
| gem 'tzinfo-data' | |
| @@ Gemfile.lock | |
| GEM | |
| remote: https://rubygems.org/ | |
| specs: | |
| activesupport (3.2.22) | |
| i18n (~> 0.6, >= 0.6.4) | |
| multi_json (~> 1.0) | |
| i18n (0.7.0) | |
| multi_json (1.11.2) | |
| thread_safe (0.3.5) | |
| tzinfo (1.2.2) | |
| thread_safe (~> 0.1) | |
| tzinfo-data (1.2015.7) | |
| tzinfo (>= 1.0.0) | |
| PLATFORMS | |
| ruby | |
| DEPENDENCIES | |
| activesupport (~> 3.2.22) | |
| tzinfo (~> 1.2.2) | |
| tzinfo-data | |
| BUNDLED WITH | |
| 1.10.6 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Figured, that activesupport 3.2 can work with tzinfo 1.2 and also tzinfo-data can be added to make current IANA database available.
Bad news: activerecord 3.2 has a "tzinfo (~> 0.3.29)" pin