omg-activesupport 8.0.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +86 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +40 -0
- data/lib/active_support/actionable_error.rb +50 -0
- data/lib/active_support/all.rb +5 -0
- data/lib/active_support/array_inquirer.rb +50 -0
- data/lib/active_support/backtrace_cleaner.rb +163 -0
- data/lib/active_support/benchmark.rb +21 -0
- data/lib/active_support/benchmarkable.rb +53 -0
- data/lib/active_support/broadcast_logger.rb +251 -0
- data/lib/active_support/builder.rb +8 -0
- data/lib/active_support/cache/coder.rb +153 -0
- data/lib/active_support/cache/entry.rb +134 -0
- data/lib/active_support/cache/file_store.rb +244 -0
- data/lib/active_support/cache/mem_cache_store.rb +290 -0
- data/lib/active_support/cache/memory_store.rb +262 -0
- data/lib/active_support/cache/null_store.rb +62 -0
- data/lib/active_support/cache/redis_cache_store.rb +492 -0
- data/lib/active_support/cache/serializer_with_fallback.rb +152 -0
- data/lib/active_support/cache/strategy/local_cache.rb +201 -0
- data/lib/active_support/cache/strategy/local_cache_middleware.rb +45 -0
- data/lib/active_support/cache.rb +1104 -0
- data/lib/active_support/callbacks.rb +944 -0
- data/lib/active_support/class_attribute.rb +26 -0
- data/lib/active_support/code_generator.rb +79 -0
- data/lib/active_support/concern.rb +217 -0
- data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +72 -0
- data/lib/active_support/concurrency/null_lock.rb +13 -0
- data/lib/active_support/concurrency/share_lock.rb +225 -0
- data/lib/active_support/configurable.rb +159 -0
- data/lib/active_support/configuration_file.rb +60 -0
- data/lib/active_support/core_ext/array/access.rb +100 -0
- data/lib/active_support/core_ext/array/conversions.rb +213 -0
- data/lib/active_support/core_ext/array/extract.rb +21 -0
- data/lib/active_support/core_ext/array/extract_options.rb +31 -0
- data/lib/active_support/core_ext/array/grouping.rb +109 -0
- data/lib/active_support/core_ext/array/inquiry.rb +19 -0
- data/lib/active_support/core_ext/array/wrap.rb +48 -0
- data/lib/active_support/core_ext/array.rb +9 -0
- data/lib/active_support/core_ext/benchmark.rb +13 -0
- data/lib/active_support/core_ext/big_decimal/conversions.rb +14 -0
- data/lib/active_support/core_ext/big_decimal.rb +3 -0
- data/lib/active_support/core_ext/class/attribute.rb +122 -0
- data/lib/active_support/core_ext/class/attribute_accessors.rb +6 -0
- data/lib/active_support/core_ext/class/subclasses.rb +24 -0
- data/lib/active_support/core_ext/class.rb +4 -0
- data/lib/active_support/core_ext/date/acts_like.rb +10 -0
- data/lib/active_support/core_ext/date/blank.rb +18 -0
- data/lib/active_support/core_ext/date/calculations.rb +161 -0
- data/lib/active_support/core_ext/date/conversions.rb +98 -0
- data/lib/active_support/core_ext/date/zones.rb +8 -0
- data/lib/active_support/core_ext/date.rb +7 -0
- data/lib/active_support/core_ext/date_and_time/calculations.rb +374 -0
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +58 -0
- data/lib/active_support/core_ext/date_and_time/zones.rb +40 -0
- data/lib/active_support/core_ext/date_time/acts_like.rb +16 -0
- data/lib/active_support/core_ext/date_time/blank.rb +18 -0
- data/lib/active_support/core_ext/date_time/calculations.rb +215 -0
- data/lib/active_support/core_ext/date_time/compatibility.rb +18 -0
- data/lib/active_support/core_ext/date_time/conversions.rb +106 -0
- data/lib/active_support/core_ext/date_time.rb +7 -0
- data/lib/active_support/core_ext/digest/uuid.rb +76 -0
- data/lib/active_support/core_ext/digest.rb +3 -0
- data/lib/active_support/core_ext/enumerable.rb +267 -0
- data/lib/active_support/core_ext/erb/util.rb +201 -0
- data/lib/active_support/core_ext/file/atomic.rb +72 -0
- data/lib/active_support/core_ext/file.rb +3 -0
- data/lib/active_support/core_ext/hash/conversions.rb +262 -0
- data/lib/active_support/core_ext/hash/deep_merge.rb +42 -0
- data/lib/active_support/core_ext/hash/deep_transform_values.rb +46 -0
- data/lib/active_support/core_ext/hash/except.rb +12 -0
- data/lib/active_support/core_ext/hash/indifferent_access.rb +24 -0
- data/lib/active_support/core_ext/hash/keys.rb +143 -0
- data/lib/active_support/core_ext/hash/reverse_merge.rb +25 -0
- data/lib/active_support/core_ext/hash/slice.rb +27 -0
- data/lib/active_support/core_ext/hash.rb +10 -0
- data/lib/active_support/core_ext/integer/inflections.rb +31 -0
- data/lib/active_support/core_ext/integer/multiple.rb +12 -0
- data/lib/active_support/core_ext/integer/time.rb +22 -0
- data/lib/active_support/core_ext/integer.rb +5 -0
- data/lib/active_support/core_ext/kernel/concern.rb +14 -0
- data/lib/active_support/core_ext/kernel/reporting.rb +45 -0
- data/lib/active_support/core_ext/kernel/singleton_class.rb +8 -0
- data/lib/active_support/core_ext/kernel.rb +5 -0
- data/lib/active_support/core_ext/load_error.rb +9 -0
- data/lib/active_support/core_ext/module/aliasing.rb +31 -0
- data/lib/active_support/core_ext/module/anonymous.rb +30 -0
- data/lib/active_support/core_ext/module/attr_internal.rb +49 -0
- data/lib/active_support/core_ext/module/attribute_accessors.rb +214 -0
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +175 -0
- data/lib/active_support/core_ext/module/concerning.rb +140 -0
- data/lib/active_support/core_ext/module/delegation.rb +225 -0
- data/lib/active_support/core_ext/module/deprecation.rb +25 -0
- data/lib/active_support/core_ext/module/introspection.rb +62 -0
- data/lib/active_support/core_ext/module/redefine_method.rb +40 -0
- data/lib/active_support/core_ext/module/remove_method.rb +17 -0
- data/lib/active_support/core_ext/module.rb +13 -0
- data/lib/active_support/core_ext/name_error.rb +59 -0
- data/lib/active_support/core_ext/numeric/bytes.rb +75 -0
- data/lib/active_support/core_ext/numeric/conversions.rb +145 -0
- data/lib/active_support/core_ext/numeric/time.rb +66 -0
- data/lib/active_support/core_ext/numeric.rb +5 -0
- data/lib/active_support/core_ext/object/acts_like.rb +45 -0
- data/lib/active_support/core_ext/object/blank.rb +199 -0
- data/lib/active_support/core_ext/object/conversions.rb +6 -0
- data/lib/active_support/core_ext/object/deep_dup.rb +71 -0
- data/lib/active_support/core_ext/object/duplicable.rb +69 -0
- data/lib/active_support/core_ext/object/inclusion.rb +37 -0
- data/lib/active_support/core_ext/object/instance_variables.rb +32 -0
- data/lib/active_support/core_ext/object/json.rb +260 -0
- data/lib/active_support/core_ext/object/to_param.rb +3 -0
- data/lib/active_support/core_ext/object/to_query.rb +87 -0
- data/lib/active_support/core_ext/object/try.rb +158 -0
- data/lib/active_support/core_ext/object/with.rb +46 -0
- data/lib/active_support/core_ext/object/with_options.rb +101 -0
- data/lib/active_support/core_ext/object.rb +17 -0
- data/lib/active_support/core_ext/pathname/blank.rb +20 -0
- data/lib/active_support/core_ext/pathname/existence.rb +23 -0
- data/lib/active_support/core_ext/pathname.rb +4 -0
- data/lib/active_support/core_ext/range/compare_range.rb +57 -0
- data/lib/active_support/core_ext/range/conversions.rb +62 -0
- data/lib/active_support/core_ext/range/each.rb +24 -0
- data/lib/active_support/core_ext/range/overlap.rb +40 -0
- data/lib/active_support/core_ext/range.rb +6 -0
- data/lib/active_support/core_ext/regexp.rb +14 -0
- data/lib/active_support/core_ext/securerandom.rb +41 -0
- data/lib/active_support/core_ext/string/access.rb +95 -0
- data/lib/active_support/core_ext/string/behavior.rb +8 -0
- data/lib/active_support/core_ext/string/conversions.rb +60 -0
- data/lib/active_support/core_ext/string/exclude.rb +13 -0
- data/lib/active_support/core_ext/string/filters.rb +151 -0
- data/lib/active_support/core_ext/string/indent.rb +45 -0
- data/lib/active_support/core_ext/string/inflections.rb +300 -0
- data/lib/active_support/core_ext/string/inquiry.rb +16 -0
- data/lib/active_support/core_ext/string/multibyte.rb +58 -0
- data/lib/active_support/core_ext/string/output_safety.rb +228 -0
- data/lib/active_support/core_ext/string/starts_ends_with.rb +6 -0
- data/lib/active_support/core_ext/string/strip.rb +27 -0
- data/lib/active_support/core_ext/string/zones.rb +16 -0
- data/lib/active_support/core_ext/string.rb +15 -0
- data/lib/active_support/core_ext/symbol/starts_ends_with.rb +6 -0
- data/lib/active_support/core_ext/symbol.rb +3 -0
- data/lib/active_support/core_ext/thread/backtrace/location.rb +12 -0
- data/lib/active_support/core_ext/time/acts_like.rb +10 -0
- data/lib/active_support/core_ext/time/calculations.rb +386 -0
- data/lib/active_support/core_ext/time/compatibility.rb +32 -0
- data/lib/active_support/core_ext/time/conversions.rb +75 -0
- data/lib/active_support/core_ext/time/zones.rb +97 -0
- data/lib/active_support/core_ext/time.rb +7 -0
- data/lib/active_support/core_ext.rb +5 -0
- data/lib/active_support/current_attributes/test_helper.rb +13 -0
- data/lib/active_support/current_attributes.rb +233 -0
- data/lib/active_support/deep_mergeable.rb +53 -0
- data/lib/active_support/delegation.rb +202 -0
- data/lib/active_support/dependencies/autoload.rb +72 -0
- data/lib/active_support/dependencies/interlock.rb +49 -0
- data/lib/active_support/dependencies/require_dependency.rb +28 -0
- data/lib/active_support/dependencies.rb +98 -0
- data/lib/active_support/deprecation/behaviors.rb +148 -0
- data/lib/active_support/deprecation/constant_accessor.rb +74 -0
- data/lib/active_support/deprecation/deprecators.rb +104 -0
- data/lib/active_support/deprecation/disallowed.rb +54 -0
- data/lib/active_support/deprecation/method_wrappers.rb +68 -0
- data/lib/active_support/deprecation/proxy_wrappers.rb +189 -0
- data/lib/active_support/deprecation/reporting.rb +179 -0
- data/lib/active_support/deprecation.rb +81 -0
- data/lib/active_support/deprecator.rb +7 -0
- data/lib/active_support/descendants_tracker.rb +112 -0
- data/lib/active_support/digest.rb +22 -0
- data/lib/active_support/duration/iso8601_parser.rb +123 -0
- data/lib/active_support/duration/iso8601_serializer.rb +64 -0
- data/lib/active_support/duration.rb +520 -0
- data/lib/active_support/encrypted_configuration.rb +126 -0
- data/lib/active_support/encrypted_file.rb +133 -0
- data/lib/active_support/environment_inquirer.rb +40 -0
- data/lib/active_support/error_reporter/test_helper.rb +15 -0
- data/lib/active_support/error_reporter.rb +265 -0
- data/lib/active_support/evented_file_update_checker.rb +182 -0
- data/lib/active_support/execution_context/test_helper.rb +13 -0
- data/lib/active_support/execution_context.rb +53 -0
- data/lib/active_support/execution_wrapper.rb +150 -0
- data/lib/active_support/executor/test_helper.rb +7 -0
- data/lib/active_support/executor.rb +8 -0
- data/lib/active_support/file_update_checker.rb +164 -0
- data/lib/active_support/fork_tracker.rb +43 -0
- data/lib/active_support/gem_version.rb +17 -0
- data/lib/active_support/gzip.rb +40 -0
- data/lib/active_support/hash_with_indifferent_access.rb +445 -0
- data/lib/active_support/html_safe_translation.rb +56 -0
- data/lib/active_support/i18n.rb +17 -0
- data/lib/active_support/i18n_railtie.rb +138 -0
- data/lib/active_support/inflections.rb +72 -0
- data/lib/active_support/inflector/inflections.rb +273 -0
- data/lib/active_support/inflector/methods.rb +387 -0
- data/lib/active_support/inflector/transliterate.rb +149 -0
- data/lib/active_support/inflector.rb +9 -0
- data/lib/active_support/isolated_execution_state.rb +75 -0
- data/lib/active_support/json/decoding.rb +76 -0
- data/lib/active_support/json/encoding.rb +120 -0
- data/lib/active_support/json.rb +4 -0
- data/lib/active_support/key_generator.rb +66 -0
- data/lib/active_support/lazy_load_hooks.rb +107 -0
- data/lib/active_support/locale/en.rb +33 -0
- data/lib/active_support/locale/en.yml +141 -0
- data/lib/active_support/log_subscriber/test_helper.rb +106 -0
- data/lib/active_support/log_subscriber.rb +192 -0
- data/lib/active_support/logger.rb +55 -0
- data/lib/active_support/logger_silence.rb +21 -0
- data/lib/active_support/logger_thread_safe_level.rb +47 -0
- data/lib/active_support/message_encryptor.rb +374 -0
- data/lib/active_support/message_encryptors.rb +141 -0
- data/lib/active_support/message_pack/cache_serializer.rb +23 -0
- data/lib/active_support/message_pack/extensions.rb +305 -0
- data/lib/active_support/message_pack/serializer.rb +63 -0
- data/lib/active_support/message_pack.rb +50 -0
- data/lib/active_support/message_verifier.rb +368 -0
- data/lib/active_support/message_verifiers.rb +135 -0
- data/lib/active_support/messages/codec.rb +65 -0
- data/lib/active_support/messages/metadata.rb +146 -0
- data/lib/active_support/messages/rotation_configuration.rb +23 -0
- data/lib/active_support/messages/rotation_coordinator.rb +93 -0
- data/lib/active_support/messages/rotator.rb +59 -0
- data/lib/active_support/messages/serializer_with_fallback.rb +158 -0
- data/lib/active_support/multibyte/chars.rb +178 -0
- data/lib/active_support/multibyte/unicode.rb +42 -0
- data/lib/active_support/multibyte.rb +23 -0
- data/lib/active_support/notifications/fanout.rb +446 -0
- data/lib/active_support/notifications/instrumenter.rb +240 -0
- data/lib/active_support/notifications.rb +281 -0
- data/lib/active_support/number_helper/number_converter.rb +190 -0
- data/lib/active_support/number_helper/number_to_currency_converter.rb +46 -0
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +30 -0
- data/lib/active_support/number_helper/number_to_human_converter.rb +69 -0
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +60 -0
- data/lib/active_support/number_helper/number_to_percentage_converter.rb +16 -0
- data/lib/active_support/number_helper/number_to_phone_converter.rb +60 -0
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +59 -0
- data/lib/active_support/number_helper/rounding_helper.rb +46 -0
- data/lib/active_support/number_helper.rb +479 -0
- data/lib/active_support/option_merger.rb +38 -0
- data/lib/active_support/ordered_hash.rb +50 -0
- data/lib/active_support/ordered_options.rb +147 -0
- data/lib/active_support/parameter_filter.rb +157 -0
- data/lib/active_support/proxy_object.rb +20 -0
- data/lib/active_support/rails.rb +26 -0
- data/lib/active_support/railtie.rb +161 -0
- data/lib/active_support/reloader.rb +138 -0
- data/lib/active_support/rescuable.rb +176 -0
- data/lib/active_support/secure_compare_rotator.rb +58 -0
- data/lib/active_support/security_utils.rb +38 -0
- data/lib/active_support/string_inquirer.rb +35 -0
- data/lib/active_support/subscriber.rb +146 -0
- data/lib/active_support/syntax_error_proxy.rb +60 -0
- data/lib/active_support/tagged_logging.rb +152 -0
- data/lib/active_support/test_case.rb +304 -0
- data/lib/active_support/testing/assertions.rb +332 -0
- data/lib/active_support/testing/autorun.rb +5 -0
- data/lib/active_support/testing/constant_lookup.rb +51 -0
- data/lib/active_support/testing/constant_stubbing.rb +54 -0
- data/lib/active_support/testing/declarative.rb +28 -0
- data/lib/active_support/testing/deprecation.rb +82 -0
- data/lib/active_support/testing/error_reporter_assertions.rb +107 -0
- data/lib/active_support/testing/file_fixtures.rb +38 -0
- data/lib/active_support/testing/isolation.rb +121 -0
- data/lib/active_support/testing/method_call_assertions.rb +69 -0
- data/lib/active_support/testing/parallelization/server.rb +85 -0
- data/lib/active_support/testing/parallelization/worker.rb +103 -0
- data/lib/active_support/testing/parallelization.rb +55 -0
- data/lib/active_support/testing/parallelize_executor.rb +81 -0
- data/lib/active_support/testing/setup_and_teardown.rb +57 -0
- data/lib/active_support/testing/stream.rb +41 -0
- data/lib/active_support/testing/strict_warnings.rb +43 -0
- data/lib/active_support/testing/tagged_logging.rb +27 -0
- data/lib/active_support/testing/tests_without_assertions.rb +19 -0
- data/lib/active_support/testing/time_helpers.rb +269 -0
- data/lib/active_support/time.rb +20 -0
- data/lib/active_support/time_with_zone.rb +609 -0
- data/lib/active_support/values/time_zone.rb +614 -0
- data/lib/active_support/version.rb +10 -0
- data/lib/active_support/xml_mini/jdom.rb +175 -0
- data/lib/active_support/xml_mini/libxml.rb +80 -0
- data/lib/active_support/xml_mini/libxmlsax.rb +83 -0
- data/lib/active_support/xml_mini/nokogiri.rb +83 -0
- data/lib/active_support/xml_mini/nokogirisax.rb +86 -0
- data/lib/active_support/xml_mini/rexml.rb +137 -0
- data/lib/active_support/xml_mini.rb +211 -0
- data/lib/active_support.rb +144 -0
- metadata +526 -0
@@ -0,0 +1,614 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "tzinfo"
|
4
|
+
require "concurrent/map"
|
5
|
+
|
6
|
+
module ActiveSupport
|
7
|
+
# = Active Support \Time Zone
|
8
|
+
#
|
9
|
+
# The TimeZone class serves as a wrapper around +TZInfo::Timezone+ instances.
|
10
|
+
# It allows us to do the following:
|
11
|
+
#
|
12
|
+
# * Limit the set of zones provided by TZInfo to a meaningful subset of 134
|
13
|
+
# zones.
|
14
|
+
# * Retrieve and display zones with a friendlier name
|
15
|
+
# (e.g., "Eastern Time (US & Canada)" instead of "America/New_York").
|
16
|
+
# * Lazily load +TZInfo::Timezone+ instances only when they're needed.
|
17
|
+
# * Create ActiveSupport::TimeWithZone instances via TimeZone's +local+,
|
18
|
+
# +parse+, +at+, and +now+ methods.
|
19
|
+
#
|
20
|
+
# If you set <tt>config.time_zone</tt> in the \Rails Application, you can
|
21
|
+
# access this TimeZone object via <tt>Time.zone</tt>:
|
22
|
+
#
|
23
|
+
# # application.rb:
|
24
|
+
# class Application < Rails::Application
|
25
|
+
# config.time_zone = 'Eastern Time (US & Canada)'
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# Time.zone # => #<ActiveSupport::TimeZone:0x514834...>
|
29
|
+
# Time.zone.name # => "Eastern Time (US & Canada)"
|
30
|
+
# Time.zone.now # => Sun, 18 May 2008 14:30:44 EDT -04:00
|
31
|
+
class TimeZone
|
32
|
+
# Keys are \Rails TimeZone names, values are TZInfo identifiers.
|
33
|
+
MAPPING = {
|
34
|
+
"International Date Line West" => "Etc/GMT+12",
|
35
|
+
"Midway Island" => "Pacific/Midway",
|
36
|
+
"American Samoa" => "Pacific/Pago_Pago",
|
37
|
+
"Hawaii" => "Pacific/Honolulu",
|
38
|
+
"Alaska" => "America/Juneau",
|
39
|
+
"Pacific Time (US & Canada)" => "America/Los_Angeles",
|
40
|
+
"Tijuana" => "America/Tijuana",
|
41
|
+
"Mountain Time (US & Canada)" => "America/Denver",
|
42
|
+
"Arizona" => "America/Phoenix",
|
43
|
+
"Chihuahua" => "America/Chihuahua",
|
44
|
+
"Mazatlan" => "America/Mazatlan",
|
45
|
+
"Central Time (US & Canada)" => "America/Chicago",
|
46
|
+
"Saskatchewan" => "America/Regina",
|
47
|
+
"Guadalajara" => "America/Mexico_City",
|
48
|
+
"Mexico City" => "America/Mexico_City",
|
49
|
+
"Monterrey" => "America/Monterrey",
|
50
|
+
"Central America" => "America/Guatemala",
|
51
|
+
"Eastern Time (US & Canada)" => "America/New_York",
|
52
|
+
"Indiana (East)" => "America/Indiana/Indianapolis",
|
53
|
+
"Bogota" => "America/Bogota",
|
54
|
+
"Lima" => "America/Lima",
|
55
|
+
"Quito" => "America/Lima",
|
56
|
+
"Atlantic Time (Canada)" => "America/Halifax",
|
57
|
+
"Caracas" => "America/Caracas",
|
58
|
+
"La Paz" => "America/La_Paz",
|
59
|
+
"Santiago" => "America/Santiago",
|
60
|
+
"Newfoundland" => "America/St_Johns",
|
61
|
+
"Brasilia" => "America/Sao_Paulo",
|
62
|
+
"Buenos Aires" => "America/Argentina/Buenos_Aires",
|
63
|
+
"Montevideo" => "America/Montevideo",
|
64
|
+
"Georgetown" => "America/Guyana",
|
65
|
+
"Puerto Rico" => "America/Puerto_Rico",
|
66
|
+
"Greenland" => "America/Godthab",
|
67
|
+
"Mid-Atlantic" => "Atlantic/South_Georgia",
|
68
|
+
"Azores" => "Atlantic/Azores",
|
69
|
+
"Cape Verde Is." => "Atlantic/Cape_Verde",
|
70
|
+
"Dublin" => "Europe/Dublin",
|
71
|
+
"Edinburgh" => "Europe/London",
|
72
|
+
"Lisbon" => "Europe/Lisbon",
|
73
|
+
"London" => "Europe/London",
|
74
|
+
"Casablanca" => "Africa/Casablanca",
|
75
|
+
"Monrovia" => "Africa/Monrovia",
|
76
|
+
"UTC" => "Etc/UTC",
|
77
|
+
"Belgrade" => "Europe/Belgrade",
|
78
|
+
"Bratislava" => "Europe/Bratislava",
|
79
|
+
"Budapest" => "Europe/Budapest",
|
80
|
+
"Ljubljana" => "Europe/Ljubljana",
|
81
|
+
"Prague" => "Europe/Prague",
|
82
|
+
"Sarajevo" => "Europe/Sarajevo",
|
83
|
+
"Skopje" => "Europe/Skopje",
|
84
|
+
"Warsaw" => "Europe/Warsaw",
|
85
|
+
"Zagreb" => "Europe/Zagreb",
|
86
|
+
"Brussels" => "Europe/Brussels",
|
87
|
+
"Copenhagen" => "Europe/Copenhagen",
|
88
|
+
"Madrid" => "Europe/Madrid",
|
89
|
+
"Paris" => "Europe/Paris",
|
90
|
+
"Amsterdam" => "Europe/Amsterdam",
|
91
|
+
"Berlin" => "Europe/Berlin",
|
92
|
+
"Bern" => "Europe/Zurich",
|
93
|
+
"Zurich" => "Europe/Zurich",
|
94
|
+
"Rome" => "Europe/Rome",
|
95
|
+
"Stockholm" => "Europe/Stockholm",
|
96
|
+
"Vienna" => "Europe/Vienna",
|
97
|
+
"West Central Africa" => "Africa/Algiers",
|
98
|
+
"Bucharest" => "Europe/Bucharest",
|
99
|
+
"Cairo" => "Africa/Cairo",
|
100
|
+
"Helsinki" => "Europe/Helsinki",
|
101
|
+
"Kyiv" => "Europe/Kiev",
|
102
|
+
"Riga" => "Europe/Riga",
|
103
|
+
"Sofia" => "Europe/Sofia",
|
104
|
+
"Tallinn" => "Europe/Tallinn",
|
105
|
+
"Vilnius" => "Europe/Vilnius",
|
106
|
+
"Athens" => "Europe/Athens",
|
107
|
+
"Istanbul" => "Europe/Istanbul",
|
108
|
+
"Minsk" => "Europe/Minsk",
|
109
|
+
"Jerusalem" => "Asia/Jerusalem",
|
110
|
+
"Harare" => "Africa/Harare",
|
111
|
+
"Pretoria" => "Africa/Johannesburg",
|
112
|
+
"Kaliningrad" => "Europe/Kaliningrad",
|
113
|
+
"Moscow" => "Europe/Moscow",
|
114
|
+
"St. Petersburg" => "Europe/Moscow",
|
115
|
+
"Volgograd" => "Europe/Volgograd",
|
116
|
+
"Samara" => "Europe/Samara",
|
117
|
+
"Kuwait" => "Asia/Kuwait",
|
118
|
+
"Riyadh" => "Asia/Riyadh",
|
119
|
+
"Nairobi" => "Africa/Nairobi",
|
120
|
+
"Baghdad" => "Asia/Baghdad",
|
121
|
+
"Tehran" => "Asia/Tehran",
|
122
|
+
"Abu Dhabi" => "Asia/Muscat",
|
123
|
+
"Muscat" => "Asia/Muscat",
|
124
|
+
"Baku" => "Asia/Baku",
|
125
|
+
"Tbilisi" => "Asia/Tbilisi",
|
126
|
+
"Yerevan" => "Asia/Yerevan",
|
127
|
+
"Kabul" => "Asia/Kabul",
|
128
|
+
"Ekaterinburg" => "Asia/Yekaterinburg",
|
129
|
+
"Islamabad" => "Asia/Karachi",
|
130
|
+
"Karachi" => "Asia/Karachi",
|
131
|
+
"Tashkent" => "Asia/Tashkent",
|
132
|
+
"Chennai" => "Asia/Kolkata",
|
133
|
+
"Kolkata" => "Asia/Kolkata",
|
134
|
+
"Mumbai" => "Asia/Kolkata",
|
135
|
+
"New Delhi" => "Asia/Kolkata",
|
136
|
+
"Kathmandu" => "Asia/Kathmandu",
|
137
|
+
"Dhaka" => "Asia/Dhaka",
|
138
|
+
"Sri Jayawardenepura" => "Asia/Colombo",
|
139
|
+
"Almaty" => "Asia/Almaty",
|
140
|
+
"Astana" => "Asia/Almaty",
|
141
|
+
"Novosibirsk" => "Asia/Novosibirsk",
|
142
|
+
"Rangoon" => "Asia/Rangoon",
|
143
|
+
"Bangkok" => "Asia/Bangkok",
|
144
|
+
"Hanoi" => "Asia/Bangkok",
|
145
|
+
"Jakarta" => "Asia/Jakarta",
|
146
|
+
"Krasnoyarsk" => "Asia/Krasnoyarsk",
|
147
|
+
"Beijing" => "Asia/Shanghai",
|
148
|
+
"Chongqing" => "Asia/Chongqing",
|
149
|
+
"Hong Kong" => "Asia/Hong_Kong",
|
150
|
+
"Urumqi" => "Asia/Urumqi",
|
151
|
+
"Kuala Lumpur" => "Asia/Kuala_Lumpur",
|
152
|
+
"Singapore" => "Asia/Singapore",
|
153
|
+
"Taipei" => "Asia/Taipei",
|
154
|
+
"Perth" => "Australia/Perth",
|
155
|
+
"Irkutsk" => "Asia/Irkutsk",
|
156
|
+
"Ulaanbaatar" => "Asia/Ulaanbaatar",
|
157
|
+
"Seoul" => "Asia/Seoul",
|
158
|
+
"Osaka" => "Asia/Tokyo",
|
159
|
+
"Sapporo" => "Asia/Tokyo",
|
160
|
+
"Tokyo" => "Asia/Tokyo",
|
161
|
+
"Yakutsk" => "Asia/Yakutsk",
|
162
|
+
"Darwin" => "Australia/Darwin",
|
163
|
+
"Adelaide" => "Australia/Adelaide",
|
164
|
+
"Canberra" => "Australia/Canberra",
|
165
|
+
"Melbourne" => "Australia/Melbourne",
|
166
|
+
"Sydney" => "Australia/Sydney",
|
167
|
+
"Brisbane" => "Australia/Brisbane",
|
168
|
+
"Hobart" => "Australia/Hobart",
|
169
|
+
"Vladivostok" => "Asia/Vladivostok",
|
170
|
+
"Guam" => "Pacific/Guam",
|
171
|
+
"Port Moresby" => "Pacific/Port_Moresby",
|
172
|
+
"Magadan" => "Asia/Magadan",
|
173
|
+
"Srednekolymsk" => "Asia/Srednekolymsk",
|
174
|
+
"Solomon Is." => "Pacific/Guadalcanal",
|
175
|
+
"New Caledonia" => "Pacific/Noumea",
|
176
|
+
"Fiji" => "Pacific/Fiji",
|
177
|
+
"Kamchatka" => "Asia/Kamchatka",
|
178
|
+
"Marshall Is." => "Pacific/Majuro",
|
179
|
+
"Auckland" => "Pacific/Auckland",
|
180
|
+
"Wellington" => "Pacific/Auckland",
|
181
|
+
"Nuku'alofa" => "Pacific/Tongatapu",
|
182
|
+
"Tokelau Is." => "Pacific/Fakaofo",
|
183
|
+
"Chatham Is." => "Pacific/Chatham",
|
184
|
+
"Samoa" => "Pacific/Apia"
|
185
|
+
}
|
186
|
+
|
187
|
+
UTC_OFFSET_WITH_COLON = "%s%02d:%02d" # :nodoc:
|
188
|
+
UTC_OFFSET_WITHOUT_COLON = UTC_OFFSET_WITH_COLON.tr(":", "") # :nodoc:
|
189
|
+
private_constant :UTC_OFFSET_WITH_COLON, :UTC_OFFSET_WITHOUT_COLON
|
190
|
+
|
191
|
+
@lazy_zones_map = Concurrent::Map.new
|
192
|
+
@country_zones = Concurrent::Map.new
|
193
|
+
|
194
|
+
class << self
|
195
|
+
# Assumes self represents an offset from UTC in seconds (as returned from
|
196
|
+
# Time#utc_offset) and turns this into an +HH:MM formatted string.
|
197
|
+
#
|
198
|
+
# ActiveSupport::TimeZone.seconds_to_utc_offset(-21_600) # => "-06:00"
|
199
|
+
def seconds_to_utc_offset(seconds, colon = true)
|
200
|
+
format = colon ? UTC_OFFSET_WITH_COLON : UTC_OFFSET_WITHOUT_COLON
|
201
|
+
sign = (seconds < 0 ? "-" : "+")
|
202
|
+
hours = seconds.abs / 3600
|
203
|
+
minutes = (seconds.abs % 3600) / 60
|
204
|
+
format % [sign, hours, minutes]
|
205
|
+
end
|
206
|
+
|
207
|
+
def find_tzinfo(name)
|
208
|
+
TZInfo::Timezone.get(MAPPING[name] || name)
|
209
|
+
end
|
210
|
+
|
211
|
+
alias_method :create, :new # :nodoc:
|
212
|
+
|
213
|
+
# Returns a TimeZone instance with the given name, or +nil+ if no
|
214
|
+
# such TimeZone instance exists. (This exists to support the use of
|
215
|
+
# this class with the +composed_of+ macro.)
|
216
|
+
def new(name)
|
217
|
+
self[name]
|
218
|
+
end
|
219
|
+
|
220
|
+
# Returns an array of all TimeZone objects. There are multiple
|
221
|
+
# TimeZone objects per time zone, in many cases, to make it easier
|
222
|
+
# for users to find their own time zone.
|
223
|
+
def all
|
224
|
+
@zones ||= zones_map.values.sort
|
225
|
+
end
|
226
|
+
|
227
|
+
# Locate a specific time zone object. If the argument is a string, it
|
228
|
+
# is interpreted to mean the name of the timezone to locate. If it is a
|
229
|
+
# numeric value it is either the hour offset, or the second offset, of the
|
230
|
+
# timezone to find. (The first one with that offset will be returned.)
|
231
|
+
# Returns +nil+ if no such time zone is known to the system.
|
232
|
+
def [](arg)
|
233
|
+
case arg
|
234
|
+
when self
|
235
|
+
arg
|
236
|
+
when String
|
237
|
+
begin
|
238
|
+
@lazy_zones_map[arg] ||= create(arg)
|
239
|
+
rescue TZInfo::InvalidTimezoneIdentifier
|
240
|
+
nil
|
241
|
+
end
|
242
|
+
when TZInfo::Timezone
|
243
|
+
@lazy_zones_map[arg.name] ||= create(arg.name, nil, arg)
|
244
|
+
when Numeric, ActiveSupport::Duration
|
245
|
+
arg *= 3600 if arg.abs <= 13
|
246
|
+
all.find { |z| z.utc_offset == arg.to_i }
|
247
|
+
else
|
248
|
+
raise ArgumentError, "invalid argument to TimeZone[]: #{arg.inspect}"
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
# A convenience method for returning a collection of TimeZone objects
|
253
|
+
# for time zones in the USA.
|
254
|
+
def us_zones
|
255
|
+
country_zones(:us)
|
256
|
+
end
|
257
|
+
|
258
|
+
# A convenience method for returning a collection of TimeZone objects
|
259
|
+
# for time zones in the country specified by its ISO 3166-1 Alpha2 code.
|
260
|
+
def country_zones(country_code)
|
261
|
+
code = country_code.to_s.upcase
|
262
|
+
@country_zones[code] ||= load_country_zones(code)
|
263
|
+
end
|
264
|
+
|
265
|
+
def clear # :nodoc:
|
266
|
+
@lazy_zones_map = Concurrent::Map.new
|
267
|
+
@country_zones = Concurrent::Map.new
|
268
|
+
@zones = nil
|
269
|
+
@zones_map = nil
|
270
|
+
end
|
271
|
+
|
272
|
+
private
|
273
|
+
def load_country_zones(code)
|
274
|
+
country = TZInfo::Country.get(code)
|
275
|
+
country.zone_identifiers.flat_map do |tz_id|
|
276
|
+
if MAPPING.value?(tz_id)
|
277
|
+
MAPPING.inject([]) do |memo, (key, value)|
|
278
|
+
memo << self[key] if value == tz_id
|
279
|
+
memo
|
280
|
+
end
|
281
|
+
else
|
282
|
+
create(tz_id, nil, TZInfo::Timezone.get(tz_id))
|
283
|
+
end
|
284
|
+
end.sort!
|
285
|
+
end
|
286
|
+
|
287
|
+
def zones_map
|
288
|
+
@zones_map ||= MAPPING.each_with_object({}) do |(name, _), zones|
|
289
|
+
timezone = self[name]
|
290
|
+
zones[name] = timezone if timezone
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
include Comparable
|
296
|
+
attr_reader :name
|
297
|
+
attr_reader :tzinfo
|
298
|
+
|
299
|
+
##
|
300
|
+
# :singleton-method: create
|
301
|
+
# :call-seq: create(name, utc_offset = nil, tzinfo = nil)
|
302
|
+
#
|
303
|
+
# Create a new TimeZone object with the given name and offset. The
|
304
|
+
# offset is the number of seconds that this time zone is offset from UTC
|
305
|
+
# (GMT). Seconds were chosen as the offset unit because that is the unit
|
306
|
+
# that Ruby uses to represent time zone offsets (see Time#utc_offset).
|
307
|
+
|
308
|
+
# :stopdoc:
|
309
|
+
def initialize(name, utc_offset = nil, tzinfo = nil)
|
310
|
+
@name = name
|
311
|
+
@utc_offset = utc_offset
|
312
|
+
@tzinfo = tzinfo || TimeZone.find_tzinfo(name)
|
313
|
+
end
|
314
|
+
# :startdoc:
|
315
|
+
|
316
|
+
# Returns the offset of this time zone from UTC in seconds.
|
317
|
+
def utc_offset
|
318
|
+
@utc_offset || tzinfo&.current_period&.base_utc_offset
|
319
|
+
end
|
320
|
+
|
321
|
+
# Returns a formatted string of the offset from UTC, or an alternative
|
322
|
+
# string if the time zone is already UTC.
|
323
|
+
#
|
324
|
+
# zone = ActiveSupport::TimeZone['Central Time (US & Canada)']
|
325
|
+
# zone.formatted_offset # => "-06:00"
|
326
|
+
# zone.formatted_offset(false) # => "-0600"
|
327
|
+
def formatted_offset(colon = true, alternate_utc_string = nil)
|
328
|
+
utc_offset == 0 && alternate_utc_string || self.class.seconds_to_utc_offset(utc_offset, colon)
|
329
|
+
end
|
330
|
+
|
331
|
+
# Compare this time zone to the parameter. The two are compared first on
|
332
|
+
# their offsets, and then by name.
|
333
|
+
def <=>(zone)
|
334
|
+
return unless zone.respond_to? :utc_offset
|
335
|
+
result = (utc_offset <=> zone.utc_offset)
|
336
|
+
result = (name <=> zone.name) if result == 0
|
337
|
+
result
|
338
|
+
end
|
339
|
+
|
340
|
+
# Compare #name and TZInfo identifier to a supplied regexp, returning +true+
|
341
|
+
# if a match is found.
|
342
|
+
def =~(re)
|
343
|
+
re === name || re === MAPPING[name]
|
344
|
+
end
|
345
|
+
|
346
|
+
# Compare #name and TZInfo identifier to a supplied regexp, returning +true+
|
347
|
+
# if a match is found.
|
348
|
+
def match?(re)
|
349
|
+
(re == name) || (re == MAPPING[name]) ||
|
350
|
+
((Regexp === re) && (re.match?(name) || re.match?(MAPPING[name])))
|
351
|
+
end
|
352
|
+
|
353
|
+
# Returns a textual representation of this time zone.
|
354
|
+
def to_s
|
355
|
+
"(GMT#{formatted_offset}) #{name}"
|
356
|
+
end
|
357
|
+
|
358
|
+
# Method for creating new ActiveSupport::TimeWithZone instance in time zone
|
359
|
+
# of +self+ from given values.
|
360
|
+
#
|
361
|
+
# Time.zone = 'Hawaii' # => "Hawaii"
|
362
|
+
# Time.zone.local(2007, 2, 1, 15, 30, 45) # => Thu, 01 Feb 2007 15:30:45 HST -10:00
|
363
|
+
def local(*args)
|
364
|
+
time = Time.utc(*args)
|
365
|
+
ActiveSupport::TimeWithZone.new(nil, self, time)
|
366
|
+
end
|
367
|
+
|
368
|
+
# Method for creating new ActiveSupport::TimeWithZone instance in time zone
|
369
|
+
# of +self+ from number of seconds since the Unix epoch.
|
370
|
+
#
|
371
|
+
# Time.zone = 'Hawaii' # => "Hawaii"
|
372
|
+
# Time.utc(2000).to_f # => 946684800.0
|
373
|
+
# Time.zone.at(946684800.0) # => Fri, 31 Dec 1999 14:00:00 HST -10:00
|
374
|
+
#
|
375
|
+
# A second argument can be supplied to specify sub-second precision.
|
376
|
+
#
|
377
|
+
# Time.zone = 'Hawaii' # => "Hawaii"
|
378
|
+
# Time.at(946684800, 123456.789).nsec # => 123456789
|
379
|
+
def at(*args)
|
380
|
+
Time.at(*args).utc.in_time_zone(self)
|
381
|
+
end
|
382
|
+
|
383
|
+
# Method for creating new ActiveSupport::TimeWithZone instance in time zone
|
384
|
+
# of +self+ from an ISO 8601 string.
|
385
|
+
#
|
386
|
+
# Time.zone = 'Hawaii' # => "Hawaii"
|
387
|
+
# Time.zone.iso8601('1999-12-31T14:00:00') # => Fri, 31 Dec 1999 14:00:00 HST -10:00
|
388
|
+
#
|
389
|
+
# If the time components are missing then they will be set to zero.
|
390
|
+
#
|
391
|
+
# Time.zone = 'Hawaii' # => "Hawaii"
|
392
|
+
# Time.zone.iso8601('1999-12-31') # => Fri, 31 Dec 1999 00:00:00 HST -10:00
|
393
|
+
#
|
394
|
+
# If the string is invalid then an +ArgumentError+ will be raised unlike +parse+
|
395
|
+
# which usually returns +nil+ when given an invalid date string.
|
396
|
+
def iso8601(str)
|
397
|
+
# Historically `Date._iso8601(nil)` returns `{}`, but in the `date` gem versions `3.2.1`, `3.1.2`, `3.0.2`,
|
398
|
+
# and `2.0.1`, `Date._iso8601(nil)` raises `TypeError` https://github.com/ruby/date/issues/39
|
399
|
+
# Future `date` releases are expected to revert back to the original behavior.
|
400
|
+
raise ArgumentError, "invalid date" if str.nil?
|
401
|
+
|
402
|
+
parts = Date._iso8601(str)
|
403
|
+
|
404
|
+
year = parts.fetch(:year)
|
405
|
+
|
406
|
+
if parts.key?(:yday)
|
407
|
+
ordinal_date = Date.ordinal(year, parts.fetch(:yday))
|
408
|
+
month = ordinal_date.month
|
409
|
+
day = ordinal_date.day
|
410
|
+
else
|
411
|
+
month = parts.fetch(:mon)
|
412
|
+
day = parts.fetch(:mday)
|
413
|
+
end
|
414
|
+
|
415
|
+
time = Time.new(
|
416
|
+
year,
|
417
|
+
month,
|
418
|
+
day,
|
419
|
+
parts.fetch(:hour, 0),
|
420
|
+
parts.fetch(:min, 0),
|
421
|
+
parts.fetch(:sec, 0) + parts.fetch(:sec_fraction, 0),
|
422
|
+
parts.fetch(:offset, 0)
|
423
|
+
)
|
424
|
+
|
425
|
+
if parts[:offset]
|
426
|
+
TimeWithZone.new(time.utc, self)
|
427
|
+
else
|
428
|
+
TimeWithZone.new(nil, self, time)
|
429
|
+
end
|
430
|
+
|
431
|
+
rescue Date::Error, KeyError
|
432
|
+
raise ArgumentError, "invalid date"
|
433
|
+
end
|
434
|
+
|
435
|
+
# Method for creating new ActiveSupport::TimeWithZone instance in time zone
|
436
|
+
# of +self+ from parsed string.
|
437
|
+
#
|
438
|
+
# Time.zone = 'Hawaii' # => "Hawaii"
|
439
|
+
# Time.zone.parse('1999-12-31 14:00:00') # => Fri, 31 Dec 1999 14:00:00 HST -10:00
|
440
|
+
#
|
441
|
+
# If upper components are missing from the string, they are supplied from
|
442
|
+
# TimeZone#now:
|
443
|
+
#
|
444
|
+
# Time.zone.now # => Fri, 31 Dec 1999 14:00:00 HST -10:00
|
445
|
+
# Time.zone.parse('22:30:00') # => Fri, 31 Dec 1999 22:30:00 HST -10:00
|
446
|
+
#
|
447
|
+
# However, if the date component is not provided, but any other upper
|
448
|
+
# components are supplied, then the day of the month defaults to 1:
|
449
|
+
#
|
450
|
+
# Time.zone.parse('Mar 2000') # => Wed, 01 Mar 2000 00:00:00 HST -10:00
|
451
|
+
#
|
452
|
+
# If the string is invalid then an +ArgumentError+ could be raised.
|
453
|
+
def parse(str, now = now())
|
454
|
+
parts_to_time(Date._parse(str, false), now)
|
455
|
+
end
|
456
|
+
|
457
|
+
# Method for creating new ActiveSupport::TimeWithZone instance in time zone
|
458
|
+
# of +self+ from an RFC 3339 string.
|
459
|
+
#
|
460
|
+
# Time.zone = 'Hawaii' # => "Hawaii"
|
461
|
+
# Time.zone.rfc3339('2000-01-01T00:00:00Z') # => Fri, 31 Dec 1999 14:00:00 HST -10:00
|
462
|
+
#
|
463
|
+
# If the time or zone components are missing then an +ArgumentError+ will
|
464
|
+
# be raised. This is much stricter than either +parse+ or +iso8601+ which
|
465
|
+
# allow for missing components.
|
466
|
+
#
|
467
|
+
# Time.zone = 'Hawaii' # => "Hawaii"
|
468
|
+
# Time.zone.rfc3339('1999-12-31') # => ArgumentError: invalid date
|
469
|
+
def rfc3339(str)
|
470
|
+
parts = Date._rfc3339(str)
|
471
|
+
|
472
|
+
raise ArgumentError, "invalid date" if parts.empty?
|
473
|
+
|
474
|
+
time = Time.new(
|
475
|
+
parts.fetch(:year),
|
476
|
+
parts.fetch(:mon),
|
477
|
+
parts.fetch(:mday),
|
478
|
+
parts.fetch(:hour),
|
479
|
+
parts.fetch(:min),
|
480
|
+
parts.fetch(:sec) + parts.fetch(:sec_fraction, 0),
|
481
|
+
parts.fetch(:offset)
|
482
|
+
)
|
483
|
+
|
484
|
+
TimeWithZone.new(time.utc, self)
|
485
|
+
end
|
486
|
+
|
487
|
+
# Parses +str+ according to +format+ and returns an ActiveSupport::TimeWithZone.
|
488
|
+
#
|
489
|
+
# Assumes that +str+ is a time in the time zone +self+,
|
490
|
+
# unless +format+ includes an explicit time zone.
|
491
|
+
# (This is the same behavior as +parse+.)
|
492
|
+
# In either case, the returned TimeWithZone has the timezone of +self+.
|
493
|
+
#
|
494
|
+
# Time.zone = 'Hawaii' # => "Hawaii"
|
495
|
+
# Time.zone.strptime('1999-12-31 14:00:00', '%Y-%m-%d %H:%M:%S') # => Fri, 31 Dec 1999 14:00:00 HST -10:00
|
496
|
+
#
|
497
|
+
# If upper components are missing from the string, they are supplied from
|
498
|
+
# TimeZone#now:
|
499
|
+
#
|
500
|
+
# Time.zone.now # => Fri, 31 Dec 1999 14:00:00 HST -10:00
|
501
|
+
# Time.zone.strptime('22:30:00', '%H:%M:%S') # => Fri, 31 Dec 1999 22:30:00 HST -10:00
|
502
|
+
#
|
503
|
+
# However, if the date component is not provided, but any other upper
|
504
|
+
# components are supplied, then the day of the month defaults to 1:
|
505
|
+
#
|
506
|
+
# Time.zone.strptime('Mar 2000', '%b %Y') # => Wed, 01 Mar 2000 00:00:00 HST -10:00
|
507
|
+
def strptime(str, format, now = now())
|
508
|
+
parts_to_time(DateTime._strptime(str, format), now)
|
509
|
+
end
|
510
|
+
|
511
|
+
# Returns an ActiveSupport::TimeWithZone instance representing the current
|
512
|
+
# time in the time zone represented by +self+.
|
513
|
+
#
|
514
|
+
# Time.zone = 'Hawaii' # => "Hawaii"
|
515
|
+
# Time.zone.now # => Wed, 23 Jan 2008 20:24:27 HST -10:00
|
516
|
+
def now
|
517
|
+
time_now.utc.in_time_zone(self)
|
518
|
+
end
|
519
|
+
|
520
|
+
# Returns the current date in this time zone.
|
521
|
+
def today
|
522
|
+
tzinfo.now.to_date
|
523
|
+
end
|
524
|
+
|
525
|
+
# Returns the next date in this time zone.
|
526
|
+
def tomorrow
|
527
|
+
today + 1
|
528
|
+
end
|
529
|
+
|
530
|
+
# Returns the previous date in this time zone.
|
531
|
+
def yesterday
|
532
|
+
today - 1
|
533
|
+
end
|
534
|
+
|
535
|
+
# Adjust the given time to the simultaneous time in the time zone
|
536
|
+
# represented by +self+. Returns a local time with the appropriate offset
|
537
|
+
# -- if you want an ActiveSupport::TimeWithZone instance, use
|
538
|
+
# Time#in_time_zone() instead.
|
539
|
+
#
|
540
|
+
# As of tzinfo 2, utc_to_local returns a Time with a non-zero utc_offset.
|
541
|
+
# See the +utc_to_local_returns_utc_offset_times+ config for more info.
|
542
|
+
def utc_to_local(time)
|
543
|
+
tzinfo.utc_to_local(time).yield_self do |t|
|
544
|
+
ActiveSupport.utc_to_local_returns_utc_offset_times ?
|
545
|
+
t : Time.utc(t.year, t.month, t.day, t.hour, t.min, t.sec, t.sec_fraction * 1_000_000)
|
546
|
+
end
|
547
|
+
end
|
548
|
+
|
549
|
+
# Adjust the given time to the simultaneous time in UTC. Returns a
|
550
|
+
# Time.utc() instance.
|
551
|
+
def local_to_utc(time, dst = true)
|
552
|
+
tzinfo.local_to_utc(time, dst)
|
553
|
+
end
|
554
|
+
|
555
|
+
def period_for_utc(time) # :nodoc:
|
556
|
+
tzinfo.period_for_utc(time)
|
557
|
+
end
|
558
|
+
|
559
|
+
def period_for_local(time, dst = true) # :nodoc:
|
560
|
+
tzinfo.period_for_local(time, dst) { |periods| periods.last }
|
561
|
+
end
|
562
|
+
|
563
|
+
def periods_for_local(time) # :nodoc:
|
564
|
+
tzinfo.periods_for_local(time)
|
565
|
+
end
|
566
|
+
|
567
|
+
def abbr(time) # :nodoc:
|
568
|
+
tzinfo.abbr(time)
|
569
|
+
end
|
570
|
+
|
571
|
+
def dst?(time) # :nodoc:
|
572
|
+
tzinfo.dst?(time)
|
573
|
+
end
|
574
|
+
|
575
|
+
def init_with(coder) # :nodoc:
|
576
|
+
initialize(coder["name"])
|
577
|
+
end
|
578
|
+
|
579
|
+
def encode_with(coder) # :nodoc:
|
580
|
+
coder.tag = "!ruby/object:#{self.class}"
|
581
|
+
coder.map = { "name" => tzinfo.name }
|
582
|
+
end
|
583
|
+
|
584
|
+
private
|
585
|
+
def parts_to_time(parts, now)
|
586
|
+
raise ArgumentError, "invalid date" if parts.nil?
|
587
|
+
return if parts.empty?
|
588
|
+
|
589
|
+
if parts[:seconds]
|
590
|
+
time = Time.at(parts[:seconds])
|
591
|
+
else
|
592
|
+
time = Time.new(
|
593
|
+
parts.fetch(:year, now.year),
|
594
|
+
parts.fetch(:mon, now.month),
|
595
|
+
parts.fetch(:mday, parts[:year] || parts[:mon] ? 1 : now.day),
|
596
|
+
parts.fetch(:hour, 0),
|
597
|
+
parts.fetch(:min, 0),
|
598
|
+
parts.fetch(:sec, 0) + parts.fetch(:sec_fraction, 0),
|
599
|
+
parts.fetch(:offset, 0)
|
600
|
+
)
|
601
|
+
end
|
602
|
+
|
603
|
+
if parts[:offset] || parts[:seconds]
|
604
|
+
TimeWithZone.new(time.utc, self)
|
605
|
+
else
|
606
|
+
TimeWithZone.new(nil, self, time)
|
607
|
+
end
|
608
|
+
end
|
609
|
+
|
610
|
+
def time_now
|
611
|
+
Time.now
|
612
|
+
end
|
613
|
+
end
|
614
|
+
end
|