activesupport 2.3.5 → 3.0.0.beta3
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.
- data/CHANGELOG +66 -9
- data/lib/active_support/all.rb +2 -7
- data/lib/active_support/backtrace_cleaner.rb +31 -9
- data/lib/active_support/base64.rb +9 -0
- data/lib/active_support/basic_object.rb +7 -10
- data/lib/active_support/benchmarkable.rb +60 -0
- data/lib/active_support/buffered_logger.rb +14 -9
- data/lib/active_support/cache/compressed_mem_cache_store.rb +2 -0
- data/lib/active_support/cache/file_store.rb +35 -17
- data/lib/active_support/cache/mem_cache_store.rb +32 -23
- data/lib/active_support/cache/memory_store.rb +17 -10
- data/lib/active_support/cache/strategy/local_cache.rb +9 -1
- data/lib/active_support/cache.rb +75 -55
- data/lib/active_support/callbacks.rb +490 -169
- data/lib/active_support/concern.rb +29 -0
- data/lib/active_support/configurable.rb +35 -0
- data/lib/active_support/core_ext/array/access.rb +39 -46
- data/lib/active_support/core_ext/array/conversions.rb +145 -182
- data/lib/active_support/core_ext/array/extract_options.rb +26 -17
- data/lib/active_support/core_ext/array/grouping.rb +87 -93
- data/lib/active_support/core_ext/array/random_access.rb +4 -10
- data/lib/active_support/core_ext/array/uniq_by.rb +17 -0
- data/lib/active_support/core_ext/array/wrap.rb +22 -0
- data/lib/active_support/core_ext/array.rb +2 -10
- data/lib/active_support/core_ext/big_decimal/conversions.rb +27 -0
- data/lib/active_support/core_ext/big_decimal.rb +1 -0
- data/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +16 -20
- data/lib/active_support/core_ext/cgi.rb +0 -4
- data/lib/active_support/core_ext/class/attribute.rb +70 -0
- data/lib/active_support/core_ext/class/attribute_accessors.rb +40 -31
- data/lib/active_support/core_ext/class/delegating_attributes.rb +37 -40
- data/lib/active_support/core_ext/class/inheritable_attributes.rb +100 -11
- data/lib/active_support/core_ext/class/subclasses.rb +55 -0
- data/lib/active_support/core_ext/class.rb +1 -1
- data/lib/active_support/core_ext/date/acts_like.rb +8 -0
- data/lib/active_support/core_ext/date/calculations.rb +218 -228
- data/lib/active_support/core_ext/date/conversions.rb +87 -96
- data/lib/active_support/core_ext/date/freeze.rb +31 -0
- data/lib/active_support/core_ext/date_time/acts_like.rb +13 -0
- data/lib/active_support/core_ext/date_time/calculations.rb +97 -110
- data/lib/active_support/core_ext/date_time/conversions.rb +85 -85
- data/lib/active_support/core_ext/date_time/zones.rb +17 -0
- data/lib/active_support/core_ext/enumerable.rb +18 -13
- data/lib/active_support/core_ext/exception.rb +1 -43
- data/lib/active_support/core_ext/file/atomic.rb +35 -40
- data/lib/active_support/core_ext/file/path.rb +5 -0
- data/lib/active_support/core_ext/file.rb +0 -4
- data/lib/active_support/core_ext/float/rounding.rb +15 -20
- data/lib/active_support/core_ext/float.rb +0 -6
- data/lib/active_support/core_ext/hash/conversions.rb +255 -229
- data/lib/active_support/core_ext/hash/deep_merge.rb +12 -19
- data/lib/active_support/core_ext/hash/diff.rb +11 -17
- data/lib/active_support/core_ext/hash/except.rb +21 -22
- data/lib/active_support/core_ext/hash/indifferent_access.rb +8 -137
- data/lib/active_support/core_ext/hash/keys.rb +38 -45
- data/lib/active_support/core_ext/hash/reverse_merge.rb +25 -32
- data/lib/active_support/core_ext/hash/slice.rb +35 -37
- data/lib/active_support/core_ext/hash.rb +8 -14
- data/lib/active_support/core_ext/integer/inflections.rb +10 -16
- data/lib/active_support/core_ext/integer/multiple.rb +6 -0
- data/lib/active_support/core_ext/integer/time.rb +36 -42
- data/lib/active_support/core_ext/integer.rb +1 -7
- data/lib/active_support/core_ext/kernel/debugger.rb +1 -1
- data/lib/active_support/core_ext/kernel/reporting.rb +9 -7
- data/lib/active_support/core_ext/kernel/requires.rb +3 -1
- data/lib/active_support/core_ext/kernel/singleton_class.rb +13 -0
- data/lib/active_support/core_ext/kernel.rb +1 -1
- data/lib/active_support/core_ext/load_error.rb +16 -32
- data/lib/active_support/core_ext/logger.rb +3 -2
- data/lib/active_support/core_ext/module/aliasing.rb +64 -68
- data/lib/active_support/core_ext/module/anonymous.rb +24 -0
- data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +1 -1
- data/lib/active_support/core_ext/module/attr_internal.rb +4 -4
- data/lib/active_support/core_ext/module/attribute_accessors.rb +48 -42
- data/lib/active_support/core_ext/module/delegation.rb +22 -11
- data/lib/active_support/core_ext/module/deprecation.rb +9 -0
- data/lib/active_support/core_ext/module/introspection.rb +77 -79
- data/lib/active_support/core_ext/module/method_names.rb +14 -0
- data/lib/active_support/core_ext/module/reachable.rb +10 -0
- data/lib/active_support/core_ext/module/remove_method.rb +6 -0
- data/lib/active_support/core_ext/module/synchronization.rb +4 -1
- data/lib/active_support/core_ext/module.rb +7 -18
- data/lib/active_support/core_ext/name_error.rb +3 -4
- data/lib/active_support/core_ext/numeric/bytes.rb +35 -41
- data/lib/active_support/core_ext/numeric/time.rb +70 -74
- data/lib/active_support/core_ext/numeric.rb +1 -8
- data/lib/active_support/core_ext/object/acts_like.rb +10 -0
- data/lib/active_support/core_ext/object/blank.rb +20 -2
- data/lib/active_support/core_ext/object/conversions.rb +4 -15
- data/lib/active_support/core_ext/object/duplicable.rb +65 -0
- data/lib/active_support/core_ext/object/extending.rb +8 -77
- data/lib/active_support/core_ext/object/instance_variables.rb +0 -7
- data/lib/active_support/core_ext/object/misc.rb +2 -90
- data/lib/active_support/core_ext/object/returning.rb +42 -0
- data/lib/active_support/core_ext/object/to_param.rb +49 -0
- data/lib/active_support/core_ext/object/to_query.rb +27 -0
- data/lib/active_support/core_ext/{try.rb → object/try.rb} +4 -4
- data/lib/active_support/core_ext/object/with_options.rb +24 -0
- data/lib/active_support/core_ext/object.rb +10 -2
- data/lib/active_support/core_ext/proc.rb +3 -1
- data/lib/active_support/core_ext/process/daemon.rb +17 -19
- data/lib/active_support/core_ext/range/blockless_step.rb +24 -27
- data/lib/active_support/core_ext/range/conversions.rb +17 -23
- data/lib/active_support/core_ext/range/include_range.rb +18 -27
- data/lib/active_support/core_ext/range/overlaps.rb +6 -13
- data/lib/active_support/core_ext/range.rb +2 -9
- data/lib/active_support/core_ext/regexp.rb +5 -0
- data/lib/active_support/core_ext/rexml.rb +12 -7
- data/lib/active_support/core_ext/string/access.rb +88 -95
- data/lib/active_support/core_ext/string/behavior.rb +6 -12
- data/lib/active_support/core_ext/string/conversions.rb +20 -21
- data/lib/active_support/core_ext/string/exclude.rb +6 -0
- data/lib/active_support/core_ext/string/filters.rb +17 -23
- data/lib/active_support/core_ext/string/inflections.rb +147 -154
- data/lib/active_support/core_ext/string/interpolation.rb +1 -0
- data/lib/active_support/core_ext/string/multibyte.rb +68 -74
- data/lib/active_support/core_ext/string/output_safety.rb +105 -44
- data/lib/active_support/core_ext/string/starts_ends_with.rb +3 -34
- data/lib/active_support/core_ext/string/xchar.rb +10 -3
- data/lib/active_support/core_ext/string.rb +6 -20
- data/lib/active_support/core_ext/time/acts_like.rb +8 -0
- data/lib/active_support/core_ext/time/calculations.rb +276 -299
- data/lib/active_support/core_ext/time/conversions.rb +79 -84
- data/lib/active_support/core_ext/time/marshal.rb +56 -0
- data/lib/active_support/core_ext/time/publicize_conversion_methods.rb +10 -0
- data/lib/active_support/core_ext/time/zones.rb +73 -81
- data/lib/active_support/core_ext/uri.rb +2 -1
- data/lib/active_support/core_ext.rb +2 -7
- data/lib/active_support/dependencies/autoload.rb +50 -0
- data/lib/active_support/dependencies.rb +168 -197
- data/lib/active_support/deprecation/behaviors.rb +38 -0
- data/lib/active_support/deprecation/method_wrappers.rb +29 -0
- data/lib/active_support/deprecation/proxy_wrappers.rb +74 -0
- data/lib/active_support/deprecation/reporting.rb +56 -0
- data/lib/active_support/deprecation.rb +9 -187
- data/lib/active_support/duration.rb +6 -2
- data/lib/active_support/hash_with_indifferent_access.rb +141 -0
- data/lib/active_support/i18n.rb +3 -0
- data/lib/active_support/inflections.rb +1 -1
- data/lib/active_support/inflector/inflections.rb +211 -0
- data/lib/active_support/inflector/methods.rb +141 -0
- data/lib/active_support/inflector/transliterate.rb +77 -0
- data/lib/active_support/inflector.rb +4 -403
- data/lib/active_support/json/backends/jsongem.rb +16 -10
- data/lib/active_support/json/backends/yajl.rb +40 -0
- data/lib/active_support/json/backends/yaml.rb +14 -8
- data/lib/active_support/json/decoding.rb +17 -1
- data/lib/active_support/json/encoding.rb +164 -35
- data/lib/active_support/json/variable.rb +4 -3
- data/lib/active_support/lazy_load_hooks.rb +17 -0
- data/lib/active_support/memoizable.rb +8 -5
- data/lib/active_support/message_encryptor.rb +1 -0
- data/lib/active_support/message_verifier.rb +12 -29
- data/lib/active_support/multibyte/chars.rb +88 -31
- data/lib/active_support/multibyte/unicode_database.rb +5 -5
- data/lib/active_support/multibyte/utils.rb +6 -7
- data/lib/active_support/multibyte.rb +11 -6
- data/lib/active_support/notifications/fanout.rb +83 -0
- data/lib/active_support/notifications/instrumenter.rb +50 -0
- data/lib/active_support/notifications.rb +81 -0
- data/lib/active_support/option_merger.rb +2 -0
- data/lib/active_support/ordered_hash.rb +28 -11
- data/lib/active_support/ordered_options.rb +9 -1
- data/lib/active_support/railtie.rb +64 -0
- data/lib/active_support/rescuable.rb +11 -6
- data/lib/active_support/ruby/shim.rb +21 -0
- data/lib/active_support/test_case.rb +10 -8
- data/lib/active_support/testing/assertions.rb +17 -0
- data/lib/active_support/testing/declarative.rb +31 -12
- data/lib/active_support/testing/deprecation.rb +8 -10
- data/lib/active_support/testing/isolation.rb +153 -0
- data/lib/active_support/testing/pending.rb +48 -0
- data/lib/active_support/testing/performance.rb +342 -339
- data/lib/active_support/testing/setup_and_teardown.rb +48 -31
- data/lib/active_support/time/autoload.rb +5 -0
- data/lib/active_support/time.rb +34 -0
- data/lib/active_support/time_with_zone.rb +18 -12
- data/lib/active_support/values/time_zone.rb +51 -68
- data/lib/active_support/version.rb +5 -4
- data/lib/active_support/whiny_nil.rb +5 -9
- data/lib/active_support/xml_mini/jdom.rb +13 -7
- data/lib/active_support/xml_mini/libxml.rb +38 -91
- data/lib/active_support/xml_mini/libxmlsax.rb +85 -0
- data/lib/active_support/xml_mini/nokogiri.rb +40 -31
- data/lib/active_support/xml_mini/nokogirisax.rb +83 -0
- data/lib/active_support/xml_mini/rexml.rb +30 -9
- data/lib/active_support/xml_mini.rb +2 -0
- data/lib/active_support.rb +46 -30
- metadata +136 -215
- data/lib/active_support/cache/drb_store.rb +0 -14
- data/lib/active_support/core_ext/array/wrapper.rb +0 -24
- data/lib/active_support/core_ext/base64/encoding.rb +0 -16
- data/lib/active_support/core_ext/base64.rb +0 -4
- data/lib/active_support/core_ext/bigdecimal/conversions.rb +0 -37
- data/lib/active_support/core_ext/bigdecimal.rb +0 -6
- data/lib/active_support/core_ext/blank.rb +0 -2
- data/lib/active_support/core_ext/class/removal.rb +0 -50
- data/lib/active_support/core_ext/date/behavior.rb +0 -42
- data/lib/active_support/core_ext/date.rb +0 -10
- data/lib/active_support/core_ext/date_time.rb +0 -12
- data/lib/active_support/core_ext/duplicable.rb +0 -43
- data/lib/active_support/core_ext/float/time.rb +0 -27
- data/lib/active_support/core_ext/integer/even_odd.rb +0 -29
- data/lib/active_support/core_ext/kernel/daemonizing.rb +0 -7
- data/lib/active_support/core_ext/module/inclusion.rb +0 -30
- data/lib/active_support/core_ext/module/loading.rb +0 -23
- data/lib/active_support/core_ext/module/model_naming.rb +0 -25
- data/lib/active_support/core_ext/numeric/conversions.rb +0 -19
- data/lib/active_support/core_ext/object/metaclass.rb +0 -13
- data/lib/active_support/core_ext/pathname/clean_within.rb +0 -14
- data/lib/active_support/core_ext/pathname.rb +0 -7
- data/lib/active_support/core_ext/string/bytesize.rb +0 -5
- data/lib/active_support/core_ext/string/iterators.rb +0 -23
- data/lib/active_support/core_ext/symbol.rb +0 -14
- data/lib/active_support/core_ext/time/behavior.rb +0 -13
- data/lib/active_support/core_ext/time.rb +0 -42
- data/lib/active_support/json/encoders/date.rb +0 -22
- data/lib/active_support/json/encoders/date_time.rb +0 -22
- data/lib/active_support/json/encoders/enumerable.rb +0 -17
- data/lib/active_support/json/encoders/false_class.rb +0 -7
- data/lib/active_support/json/encoders/hash.rb +0 -56
- data/lib/active_support/json/encoders/nil_class.rb +0 -7
- data/lib/active_support/json/encoders/numeric.rb +0 -21
- data/lib/active_support/json/encoders/object.rb +0 -10
- data/lib/active_support/json/encoders/regexp.rb +0 -9
- data/lib/active_support/json/encoders/string.rb +0 -9
- data/lib/active_support/json/encoders/symbol.rb +0 -5
- data/lib/active_support/json/encoders/time.rb +0 -22
- data/lib/active_support/json/encoders/true_class.rb +0 -7
- data/lib/active_support/vendor/builder-2.1.2/blankslate.rb +0 -113
- data/lib/active_support/vendor/builder-2.1.2/builder/blankslate.rb +0 -20
- data/lib/active_support/vendor/builder-2.1.2/builder/css.rb +0 -250
- data/lib/active_support/vendor/builder-2.1.2/builder/xchar.rb +0 -115
- data/lib/active_support/vendor/builder-2.1.2/builder/xmlbase.rb +0 -139
- data/lib/active_support/vendor/builder-2.1.2/builder/xmlevents.rb +0 -63
- data/lib/active_support/vendor/builder-2.1.2/builder/xmlmarkup.rb +0 -328
- data/lib/active_support/vendor/builder-2.1.2/builder.rb +0 -13
- data/lib/active_support/vendor/i18n-0.1.3/MIT-LICENSE +0 -20
- data/lib/active_support/vendor/i18n-0.1.3/README.textile +0 -20
- data/lib/active_support/vendor/i18n-0.1.3/Rakefile +0 -5
- data/lib/active_support/vendor/i18n-0.1.3/i18n.gemspec +0 -27
- data/lib/active_support/vendor/i18n-0.1.3/lib/i18n/backend/simple.rb +0 -214
- data/lib/active_support/vendor/i18n-0.1.3/lib/i18n/exceptions.rb +0 -53
- data/lib/active_support/vendor/i18n-0.1.3/lib/i18n.rb +0 -199
- data/lib/active_support/vendor/i18n-0.1.3/test/all.rb +0 -5
- data/lib/active_support/vendor/i18n-0.1.3/test/i18n_exceptions_test.rb +0 -99
- data/lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb +0 -124
- data/lib/active_support/vendor/i18n-0.1.3/test/locale/en.rb +0 -1
- data/lib/active_support/vendor/i18n-0.1.3/test/locale/en.yml +0 -3
- data/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb +0 -567
- data/lib/active_support/vendor/memcache-client-1.7.4/memcache.rb +0 -1107
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone.rb +0 -47
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone_info.rb +0 -228
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Algiers.rb +0 -55
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Cairo.rb +0 -219
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Casablanca.rb +0 -40
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Harare.rb +0 -18
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Johannesburg.rb +0 -25
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Monrovia.rb +0 -22
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Nairobi.rb +0 -23
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Argentina/Buenos_Aires.rb +0 -166
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Argentina/San_Juan.rb +0 -86
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Bogota.rb +0 -23
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Caracas.rb +0 -23
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Chicago.rb +0 -283
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Chihuahua.rb +0 -136
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Denver.rb +0 -204
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Godthab.rb +0 -161
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Guatemala.rb +0 -27
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Halifax.rb +0 -274
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Indiana/Indianapolis.rb +0 -149
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Juneau.rb +0 -194
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/La_Paz.rb +0 -22
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Lima.rb +0 -35
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Los_Angeles.rb +0 -232
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Mazatlan.rb +0 -139
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Mexico_City.rb +0 -144
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Monterrey.rb +0 -131
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/New_York.rb +0 -282
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Phoenix.rb +0 -30
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Regina.rb +0 -74
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Santiago.rb +0 -205
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Sao_Paulo.rb +0 -171
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/St_Johns.rb +0 -288
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Tijuana.rb +0 -196
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Almaty.rb +0 -67
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Baghdad.rb +0 -73
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Baku.rb +0 -161
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Bangkok.rb +0 -20
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Chongqing.rb +0 -33
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Colombo.rb +0 -30
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Dhaka.rb +0 -27
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Hong_Kong.rb +0 -87
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Irkutsk.rb +0 -165
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Jakarta.rb +0 -30
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Jerusalem.rb +0 -163
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kabul.rb +0 -20
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kamchatka.rb +0 -163
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Karachi.rb +0 -30
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Katmandu.rb +0 -20
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kolkata.rb +0 -25
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Krasnoyarsk.rb +0 -163
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kuala_Lumpur.rb +0 -31
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kuwait.rb +0 -18
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Magadan.rb +0 -163
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Muscat.rb +0 -18
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Novosibirsk.rb +0 -164
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Rangoon.rb +0 -24
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Riyadh.rb +0 -18
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Seoul.rb +0 -34
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Shanghai.rb +0 -35
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Singapore.rb +0 -33
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Taipei.rb +0 -59
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tashkent.rb +0 -47
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tbilisi.rb +0 -78
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tehran.rb +0 -121
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tokyo.rb +0 -30
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Ulaanbaatar.rb +0 -65
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Urumqi.rb +0 -33
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Vladivostok.rb +0 -164
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yakutsk.rb +0 -163
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yekaterinburg.rb +0 -165
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yerevan.rb +0 -165
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/Azores.rb +0 -270
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/Cape_Verde.rb +0 -23
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/South_Georgia.rb +0 -18
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Adelaide.rb +0 -187
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Brisbane.rb +0 -35
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Darwin.rb +0 -29
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Hobart.rb +0 -193
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Melbourne.rb +0 -185
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Perth.rb +0 -37
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Sydney.rb +0 -185
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Etc/UTC.rb +0 -16
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Amsterdam.rb +0 -228
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Athens.rb +0 -185
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Belgrade.rb +0 -163
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Berlin.rb +0 -188
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Bratislava.rb +0 -13
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Brussels.rb +0 -232
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Bucharest.rb +0 -181
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Budapest.rb +0 -197
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Copenhagen.rb +0 -179
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Dublin.rb +0 -276
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Helsinki.rb +0 -163
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Istanbul.rb +0 -218
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Kiev.rb +0 -168
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Lisbon.rb +0 -268
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Ljubljana.rb +0 -13
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/London.rb +0 -288
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Madrid.rb +0 -211
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Minsk.rb +0 -170
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Moscow.rb +0 -181
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Paris.rb +0 -232
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Prague.rb +0 -187
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Riga.rb +0 -176
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Rome.rb +0 -215
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Sarajevo.rb +0 -13
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Skopje.rb +0 -13
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Sofia.rb +0 -173
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Stockholm.rb +0 -165
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Tallinn.rb +0 -172
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Vienna.rb +0 -183
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Vilnius.rb +0 -170
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Warsaw.rb +0 -212
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Zagreb.rb +0 -13
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Auckland.rb +0 -202
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Fiji.rb +0 -23
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Guam.rb +0 -22
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Honolulu.rb +0 -28
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Majuro.rb +0 -20
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Midway.rb +0 -25
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Noumea.rb +0 -25
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Pago_Pago.rb +0 -26
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Port_Moresby.rb +0 -20
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Tongatapu.rb +0 -27
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/info_timezone.rb +0 -52
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/linked_timezone.rb +0 -51
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/linked_timezone_info.rb +0 -44
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/offset_rationals.rb +0 -98
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/ruby_core_support.rb +0 -56
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/time_or_datetime.rb +0 -292
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone.rb +0 -508
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_definition.rb +0 -56
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_info.rb +0 -40
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_offset_info.rb +0 -94
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_period.rb +0 -198
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_transition_info.rb +0 -129
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo.rb +0 -33
- data/lib/active_support/vendor.rb +0 -28
- data/lib/activesupport.rb +0 -2
|
@@ -1,304 +1,281 @@
|
|
|
1
1
|
require 'active_support/duration'
|
|
2
|
+
require 'active_support/core_ext/date/acts_like'
|
|
3
|
+
require 'active_support/core_ext/date/calculations'
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
other.until(self)
|
|
276
|
-
else
|
|
277
|
-
minus_without_duration(other)
|
|
278
|
-
end
|
|
279
|
-
end
|
|
280
|
-
|
|
281
|
-
# Time#- can also be used to determine the number of seconds between two Time instances.
|
|
282
|
-
# We're layering on additional behavior so that ActiveSupport::TimeWithZone instances
|
|
283
|
-
# are coerced into values that Time#- will recognize
|
|
284
|
-
def minus_with_coercion(other)
|
|
285
|
-
other = other.comparable_time if other.respond_to?(:comparable_time)
|
|
286
|
-
minus_without_coercion(other)
|
|
287
|
-
end
|
|
288
|
-
|
|
289
|
-
# Layers additional behavior on Time#<=> so that DateTime and ActiveSupport::TimeWithZone instances
|
|
290
|
-
# can be chronologically compared with a Time
|
|
291
|
-
def compare_with_coercion(other)
|
|
292
|
-
# if other is an ActiveSupport::TimeWithZone, coerce a Time instance from it so we can do <=> comparison
|
|
293
|
-
other = other.comparable_time if other.respond_to?(:comparable_time)
|
|
294
|
-
if other.acts_like?(:date)
|
|
295
|
-
# other is a Date/DateTime, so coerce self #to_datetime and hand off to DateTime#<=>
|
|
296
|
-
to_datetime.compare_without_coercion(other)
|
|
297
|
-
else
|
|
298
|
-
compare_without_coercion(other)
|
|
299
|
-
end
|
|
300
|
-
end
|
|
301
|
-
end
|
|
5
|
+
class Time
|
|
6
|
+
COMMON_YEAR_DAYS_IN_MONTH = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
|
7
|
+
DAYS_INTO_WEEK = { :monday => 0, :tuesday => 1, :wednesday => 2, :thursday => 3, :friday => 4, :saturday => 5, :sunday => 6 }
|
|
8
|
+
|
|
9
|
+
class << self
|
|
10
|
+
# Overriding case equality method so that it returns true for ActiveSupport::TimeWithZone instances
|
|
11
|
+
def ===(other)
|
|
12
|
+
other.is_a?(::Time)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Return the number of days in the given month.
|
|
16
|
+
# If no year is specified, it will use the current year.
|
|
17
|
+
def days_in_month(month, year = now.year)
|
|
18
|
+
return 29 if month == 2 && ::Date.gregorian_leap?(year)
|
|
19
|
+
COMMON_YEAR_DAYS_IN_MONTH[month]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Returns a new Time if requested year can be accommodated by Ruby's Time class
|
|
23
|
+
# (i.e., if year is within either 1970..2038 or 1902..2038, depending on system architecture);
|
|
24
|
+
# otherwise returns a DateTime
|
|
25
|
+
def time_with_datetime_fallback(utc_or_local, year, month=1, day=1, hour=0, min=0, sec=0, usec=0)
|
|
26
|
+
::Time.send(utc_or_local, year, month, day, hour, min, sec, usec)
|
|
27
|
+
rescue
|
|
28
|
+
offset = utc_or_local.to_sym == :local ? ::DateTime.local_offset : 0
|
|
29
|
+
::DateTime.civil(year, month, day, hour, min, sec, offset)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Wraps class method +time_with_datetime_fallback+ with +utc_or_local+ set to <tt>:utc</tt>.
|
|
33
|
+
def utc_time(*args)
|
|
34
|
+
time_with_datetime_fallback(:utc, *args)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Wraps class method +time_with_datetime_fallback+ with +utc_or_local+ set to <tt>:local</tt>.
|
|
38
|
+
def local_time(*args)
|
|
39
|
+
time_with_datetime_fallback(:local, *args)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Tells whether the Time object's time lies in the past
|
|
44
|
+
def past?
|
|
45
|
+
self < ::Time.current
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Tells whether the Time object's time is today
|
|
49
|
+
def today?
|
|
50
|
+
to_date == ::Date.current
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Tells whether the Time object's time lies in the future
|
|
54
|
+
def future?
|
|
55
|
+
self > ::Time.current
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Seconds since midnight: Time.now.seconds_since_midnight
|
|
59
|
+
def seconds_since_midnight
|
|
60
|
+
to_i - change(:hour => 0).to_i + (usec / 1.0e+6)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Returns a new Time where one or more of the elements have been changed according to the +options+ parameter. The time options
|
|
64
|
+
# (hour, minute, sec, usec) reset cascadingly, so if only the hour is passed, then minute, sec, and usec is set to 0. If the hour and
|
|
65
|
+
# minute is passed, then sec and usec is set to 0.
|
|
66
|
+
def change(options)
|
|
67
|
+
::Time.send(
|
|
68
|
+
utc? ? :utc_time : :local_time,
|
|
69
|
+
options[:year] || year,
|
|
70
|
+
options[:month] || month,
|
|
71
|
+
options[:day] || day,
|
|
72
|
+
options[:hour] || hour,
|
|
73
|
+
options[:min] || (options[:hour] ? 0 : min),
|
|
74
|
+
options[:sec] || ((options[:hour] || options[:min]) ? 0 : sec),
|
|
75
|
+
options[:usec] || ((options[:hour] || options[:min] || options[:sec]) ? 0 : usec)
|
|
76
|
+
)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Uses Date to provide precise Time calculations for years, months, and days.
|
|
80
|
+
# The +options+ parameter takes a hash with any of these keys: <tt>:years</tt>,
|
|
81
|
+
# <tt>:months</tt>, <tt>:weeks</tt>, <tt>:days</tt>, <tt>:hours</tt>,
|
|
82
|
+
# <tt>:minutes</tt>, <tt>:seconds</tt>.
|
|
83
|
+
def advance(options)
|
|
84
|
+
unless options[:weeks].nil?
|
|
85
|
+
options[:weeks], partial_weeks = options[:weeks].divmod(1)
|
|
86
|
+
options[:days] = (options[:days] || 0) + 7 * partial_weeks
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
unless options[:days].nil?
|
|
90
|
+
options[:days], partial_days = options[:days].divmod(1)
|
|
91
|
+
options[:hours] = (options[:hours] || 0) + 24 * partial_days
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
d = to_date.advance(options)
|
|
95
|
+
time_advanced_by_date = change(:year => d.year, :month => d.month, :day => d.day)
|
|
96
|
+
seconds_to_advance = (options[:seconds] || 0) + (options[:minutes] || 0) * 60 + (options[:hours] || 0) * 3600
|
|
97
|
+
seconds_to_advance == 0 ? time_advanced_by_date : time_advanced_by_date.since(seconds_to_advance)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Returns a new Time representing the time a number of seconds ago, this is basically a wrapper around the Numeric extension
|
|
101
|
+
def ago(seconds)
|
|
102
|
+
since(-seconds)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Returns a new Time representing the time a number of seconds since the instance time
|
|
106
|
+
def since(seconds)
|
|
107
|
+
self + seconds
|
|
108
|
+
rescue
|
|
109
|
+
to_datetime.since(seconds)
|
|
110
|
+
end
|
|
111
|
+
alias :in :since
|
|
112
|
+
|
|
113
|
+
# Returns a new Time representing the time a number of specified months ago
|
|
114
|
+
def months_ago(months)
|
|
115
|
+
advance(:months => -months)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Returns a new Time representing the time a number of specified months in the future
|
|
119
|
+
def months_since(months)
|
|
120
|
+
advance(:months => months)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# Returns a new Time representing the time a number of specified years ago
|
|
124
|
+
def years_ago(years)
|
|
125
|
+
advance(:years => -years)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# Returns a new Time representing the time a number of specified years in the future
|
|
129
|
+
def years_since(years)
|
|
130
|
+
advance(:years => years)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# Short-hand for years_ago(1)
|
|
134
|
+
def last_year
|
|
135
|
+
years_ago(1)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# Short-hand for years_since(1)
|
|
139
|
+
def next_year
|
|
140
|
+
years_since(1)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
# Short-hand for months_ago(1)
|
|
145
|
+
def last_month
|
|
146
|
+
months_ago(1)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
# Short-hand for months_since(1)
|
|
150
|
+
def next_month
|
|
151
|
+
months_since(1)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
# Returns a new Time representing the "start" of this week (Monday, 0:00)
|
|
155
|
+
def beginning_of_week
|
|
156
|
+
days_to_monday = wday!=0 ? wday-1 : 6
|
|
157
|
+
(self - days_to_monday.days).midnight
|
|
158
|
+
end
|
|
159
|
+
alias :monday :beginning_of_week
|
|
160
|
+
alias :at_beginning_of_week :beginning_of_week
|
|
161
|
+
|
|
162
|
+
# Returns a new Time representing the end of this week, (end of Sunday)
|
|
163
|
+
def end_of_week
|
|
164
|
+
days_to_sunday = wday!=0 ? 7-wday : 0
|
|
165
|
+
(self + days_to_sunday.days).end_of_day
|
|
166
|
+
end
|
|
167
|
+
alias :at_end_of_week :end_of_week
|
|
168
|
+
|
|
169
|
+
# Returns a new Time representing the start of the given day in next week (default is Monday).
|
|
170
|
+
def next_week(day = :monday)
|
|
171
|
+
since(1.week).beginning_of_week.since(DAYS_INTO_WEEK[day].day).change(:hour => 0)
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
# Returns a new Time representing the start of the day (0:00)
|
|
175
|
+
def beginning_of_day
|
|
176
|
+
#(self - seconds_since_midnight).change(:usec => 0)
|
|
177
|
+
change(:hour => 0, :min => 0, :sec => 0, :usec => 0)
|
|
178
|
+
end
|
|
179
|
+
alias :midnight :beginning_of_day
|
|
180
|
+
alias :at_midnight :beginning_of_day
|
|
181
|
+
alias :at_beginning_of_day :beginning_of_day
|
|
182
|
+
|
|
183
|
+
# Returns a new Time representing the end of the day, 23:59:59.999999 (.999999999 in ruby1.9)
|
|
184
|
+
def end_of_day
|
|
185
|
+
change(:hour => 23, :min => 59, :sec => 59, :usec => 999999.999)
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# Returns a new Time representing the start of the month (1st of the month, 0:00)
|
|
189
|
+
def beginning_of_month
|
|
190
|
+
#self - ((self.mday-1).days + self.seconds_since_midnight)
|
|
191
|
+
change(:day => 1,:hour => 0, :min => 0, :sec => 0, :usec => 0)
|
|
192
|
+
end
|
|
193
|
+
alias :at_beginning_of_month :beginning_of_month
|
|
194
|
+
|
|
195
|
+
# Returns a new Time representing the end of the month (end of the last day of the month)
|
|
196
|
+
def end_of_month
|
|
197
|
+
#self - ((self.mday-1).days + self.seconds_since_midnight)
|
|
198
|
+
last_day = ::Time.days_in_month(month, year)
|
|
199
|
+
change(:day => last_day, :hour => 23, :min => 59, :sec => 59, :usec => 999999.999)
|
|
200
|
+
end
|
|
201
|
+
alias :at_end_of_month :end_of_month
|
|
202
|
+
|
|
203
|
+
# Returns a new Time representing the start of the quarter (1st of january, april, july, october, 0:00)
|
|
204
|
+
def beginning_of_quarter
|
|
205
|
+
beginning_of_month.change(:month => [10, 7, 4, 1].detect { |m| m <= month })
|
|
206
|
+
end
|
|
207
|
+
alias :at_beginning_of_quarter :beginning_of_quarter
|
|
208
|
+
|
|
209
|
+
# Returns a new Time representing the end of the quarter (end of the last day of march, june, september, december)
|
|
210
|
+
def end_of_quarter
|
|
211
|
+
beginning_of_month.change(:month => [3, 6, 9, 12].detect { |m| m >= month }).end_of_month
|
|
212
|
+
end
|
|
213
|
+
alias :at_end_of_quarter :end_of_quarter
|
|
214
|
+
|
|
215
|
+
# Returns a new Time representing the start of the year (1st of january, 0:00)
|
|
216
|
+
def beginning_of_year
|
|
217
|
+
change(:month => 1, :day => 1, :hour => 0, :min => 0, :sec => 0, :usec => 0)
|
|
218
|
+
end
|
|
219
|
+
alias :at_beginning_of_year :beginning_of_year
|
|
220
|
+
|
|
221
|
+
# Returns a new Time representing the end of the year (end of the 31st of december)
|
|
222
|
+
def end_of_year
|
|
223
|
+
change(:month => 12, :day => 31, :hour => 23, :min => 59, :sec => 59, :usec => 999999.999)
|
|
224
|
+
end
|
|
225
|
+
alias :at_end_of_year :end_of_year
|
|
226
|
+
|
|
227
|
+
# Convenience method which returns a new Time representing the time 1 day ago
|
|
228
|
+
def yesterday
|
|
229
|
+
advance(:days => -1)
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
# Convenience method which returns a new Time representing the time 1 day since the instance time
|
|
233
|
+
def tomorrow
|
|
234
|
+
advance(:days => 1)
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
def plus_with_duration(other) #:nodoc:
|
|
238
|
+
if ActiveSupport::Duration === other
|
|
239
|
+
other.since(self)
|
|
240
|
+
else
|
|
241
|
+
plus_without_duration(other)
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
alias_method :plus_without_duration, :+
|
|
245
|
+
alias_method :+, :plus_with_duration
|
|
246
|
+
|
|
247
|
+
def minus_with_duration(other) #:nodoc:
|
|
248
|
+
if ActiveSupport::Duration === other
|
|
249
|
+
other.until(self)
|
|
250
|
+
else
|
|
251
|
+
minus_without_duration(other)
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
alias_method :minus_without_duration, :-
|
|
255
|
+
alias_method :-, :minus_with_duration
|
|
256
|
+
|
|
257
|
+
# Time#- can also be used to determine the number of seconds between two Time instances.
|
|
258
|
+
# We're layering on additional behavior so that ActiveSupport::TimeWithZone instances
|
|
259
|
+
# are coerced into values that Time#- will recognize
|
|
260
|
+
def minus_with_coercion(other)
|
|
261
|
+
other = other.comparable_time if other.respond_to?(:comparable_time)
|
|
262
|
+
other.is_a?(DateTime) ? to_f - other.to_f : minus_without_coercion(other)
|
|
263
|
+
end
|
|
264
|
+
alias_method :minus_without_coercion, :-
|
|
265
|
+
alias_method :-, :minus_with_coercion
|
|
266
|
+
|
|
267
|
+
# Layers additional behavior on Time#<=> so that DateTime and ActiveSupport::TimeWithZone instances
|
|
268
|
+
# can be chronologically compared with a Time
|
|
269
|
+
def compare_with_coercion(other)
|
|
270
|
+
# if other is an ActiveSupport::TimeWithZone, coerce a Time instance from it so we can do <=> comparison
|
|
271
|
+
other = other.comparable_time if other.respond_to?(:comparable_time)
|
|
272
|
+
if other.acts_like?(:date)
|
|
273
|
+
# other is a Date/DateTime, so coerce self #to_datetime and hand off to DateTime#<=>
|
|
274
|
+
to_datetime.compare_without_coercion(other)
|
|
275
|
+
else
|
|
276
|
+
compare_without_coercion(other)
|
|
302
277
|
end
|
|
303
278
|
end
|
|
279
|
+
alias_method :compare_without_coercion, :<=>
|
|
280
|
+
alias_method :<=>, :compare_with_coercion
|
|
304
281
|
end
|