aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/values
Commit message (Collapse)AuthorAgeFilesLines
* Privatize and add # :nodoc: to constantsAlberto Almagro2018-10-281-2/+3
| | | | | | Both `UTC_OFFSET_WITH_COLON` and `UTC_OFFSET_WITHOUT_COLON` are only used within `ActiveSupport::TimeZone` and in my opinion they do not provide relevant information that should appear in the docs.
* Turn on performance based copsDillon Welch2018-07-231-2/+2
| | | | | | | | | | | | | | | | Use attr_reader/attr_writer instead of methods method is 12% slower Use flat_map over map.flatten(1) flatten is 66% slower Use hash[]= instead of hash.merge! with single arguments merge! is 166% slower See https://github.com/rails/rails/pull/32337 for more conversation
* Allow Time.zone.at to receive a second argumentJosh Pencheon2018-05-301-2/+7
| | | | For parity with Ruby's Time::at
* Fix exception in AS::Timezone.all when any tzinfo data is missingDominik Sander2018-04-181-1/+2
| | | | | | | | | | | | | | | | | | | | Before this change missing timezone data for any of the time zones defined in `ActiveSupport::Timezone::MAPPING` caused a `comparison of NilClass with ActiveSupport::TimeZone failed` exception. Attempting to get a timezone by passing a number/duration to `[]` or calling `all` directly will try to sort sort the values of `zones_map`. Those values are initialized by the return value of `create(zonename)` which returns `nil` if `TZInfo` is unable to find the timezone information. In our case the exception was triggered by an outdated tzdata package which did not include information for the "recently" added time zones. Before 078421bacba178eac6a8e607b16f3f4511c5d72f `zones_map` only returned the information that have been loaded into `@lazy_zone_map` which ignored time zones for which the data could not be loaded, this change restores the previous behaviour.
* Remove `AS::Multibyte`'s unicode tableFumiaki MATSUSHIMA2018-02-201-0/+0
|
* Return all mappings for a timezone id in `country_zones`Andrew White2018-02-191-2/+5
| | | | | | | | | | | | | | Some timezones like `Europe/London` have multiple mappings in `ActiveSupport::TimeZone::MAPPING` so return all of them instead of the first one found by using `Hash#value`. e.g: # Before ActiveSupport::TimeZone.country_zones("GB") # => ["Edinburgh"] # After ActiveSupport::TimeZone.country_zones("GB") # => ["Edinburgh", "London"] Fixes #31668.
* Remove require Object#blank? monkey patchSean Collins2018-02-171-1/+0
| | | | | | | Object#blank? used to be used in this file, but it's not anymore. This avoids a monkey-patch, for those who want to use just this isolated feature of ActiveSupport.
* Enable autocorrect for `Lint/EndAlignment` copKoichi ITO2018-01-181-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ### Summary This PR changes .rubocop.yml. Regarding the code using `if ... else ... end`, I think the coding style that Rails expects is as follows. ```ruby var = if cond a else b end ``` However, the current .rubocop.yml setting does not offense for the following code. ```ruby var = if cond a else b end ``` I think that the above code expects offense to be warned. Moreover, the layout by autocorrect is unnatural. ```ruby var = if cond a else b end ``` This PR adds a setting to .rubocop.yml to make an offense warning and autocorrect as expected by the coding style. And this change also fixes `case ... when ... end` together. Also this PR itself is an example that arranges the layout using `rubocop -a`. ### Other Information Autocorrect of `Lint/EndAlignment` cop is `false` by default. https://github.com/bbatsov/rubocop/blob/v0.51.0/config/default.yml#L1443 This PR changes this value to `true`. Also this PR has changed it together as it is necessary to enable `Layout/ElseAlignment` cop to make this behavior.
* Enable `Style/DefWithParentheses` rubocop ruleRyuta Kamizono2017-11-271-1/+1
| | | | | | | The def with blank `()` was newly added in #31176, but we have not used the blank `()` style in most part of our code base. So I've enabled `Style/DefWithParentheses` to prevent to newly added the code.
* Make ActiveSupport::TimeZone.all independent of previous lookups (#31176)Chris LaRose2017-11-221-3/+9
|
* Merge pull request #31128 from rails/handle-ambigious-timesAndrew White2017-11-151-1/+1
|\ | | | | Handle `TZInfo::AmbiguousTime` errors
| * Handle `TZInfo::AmbiguousTime` errorsAndrew White2017-11-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Make `ActiveSupport::TimeWithZone` match Ruby's handling of ambiguous times by choosing the later period, e.g. Ruby: ``` ENV["TZ"] = "Europe/Moscow" Time.local(2014, 10, 26, 1, 0, 0) # => 2014-10-26 01:00:00 +0300 ``` Before: ``` >> "2014-10-26 01:00:00".in_time_zone("Moscow") TZInfo::AmbiguousTime: 26/10/2014 01:00 is an ambiguous local time. ``` After: ``` >> "2014-10-26 01:00:00".in_time_zone("Moscow") => Sun, 26 Oct 2014 01:00:00 MSK +03:00 ``` Fixes #17395.
* | Merge pull request #29776 from mrj/fix-idlw-timezoneMatthew Draper2017-11-151-1/+1
|\ \ | |/ |/| Fix the "International Date Line West" timezone
| * Change the "International Date Line West" TZInfo timezone from ↵Mark James2017-07-131-1/+1
| | | | | | | | "Pacific/Midway" (-11) to "Etc/GMT+12" (-12).
* | [Active Support] require_relative => requireAkira Matsuda2017-10-211-1/+1
|/ | | | This basically reverts 8da30ad6be34339124ba4cb4e36aea260dda12bc
* [Active Support] `rubocop -a --only Layout/EmptyLineAfterMagicComment`Koichi ITO2017-07-111-0/+1
|
* Merge pull request #29728 from kirs/frozen-activesupportMatthew Draper2017-07-091-0/+1
|\ | | | | Use frozen-string-literal in ActiveSupport
| * Use frozen-string-literal in ActiveSupportKir Shatrov2017-07-091-0/+1
| |
* | Merge pull request #28668 from Dorian/mention-time-parse-argument-errorAaron Patterson2017-07-051-1/+3
|\ \ | |/ |/| Mention Time.zone.parse possibly throwing ArgumentError
| * Mention and test for possible ArgumentError when parsing timesDorian Marié2017-04-081-1/+3
| |
* | [Active Support] require => require_relativeAkira Matsuda2017-07-011-1/+1
| |
* | There are actually only 134 unique timezones.Chris Dosé2017-04-161-1/+1
| |
* | Add Puerto Rico support to ActiveSupport::TimeZoneChris Dosé2017-04-161-0/+1
|/
* Return unmapped timezones from `country_zones`Andrew White2017-03-281-5/+12
| | | | | | | If a country doesn't exist in the MAPPINGS hash then create a new `ActiveSupport::Timezone` instance using the supplied timezone id. Fixes #28431.
* Add `ActiveSupport::TimeZone.rfc3339` parsing methodAndrew White2017-03-031-0/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously there was no way to get a RFC 3339 timestamp into a specific timezone without either using `parse` or chaining methods. The new method allows parsing directly into the timezone, e.g: >> Time.zone = "Hawaii" => "Hawaii" >> Time.zone.rfc3339("1999-12-31T14:00:00Z") => Fri, 31 Dec 1999 14:00:00 HST -10:00 This new method has stricter semantics than the current `parse` method and will raise an `ArgumentError` instead of returning nil, e.g: >> Time.zone = "Hawaii" => "Hawaii" >> Time.zone.rfc3339("foobar") ArgumentError: invalid date >> Time.zone.parse("foobar") => nil It will also raise an `ArgumentError` when either the time or offset components are missing, e.g: >> Time.zone = "Hawaii" => "Hawaii" >> Time.zone.rfc3339("1999-12-31") ArgumentError: invalid date >> Time.zone.rfc3339("1999-12-31T14:00:00") ArgumentError: invalid date
* Add `ActiveSupport::TimeZone.iso8601` parsing methodAndrew White2017-03-031-0/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously there was no way to get a ISO 8601 timestamp into a specific timezone without either using `parse` or chaining methods. The new method allows parsing directly into the timezone, e.g: >> Time.zone = "Hawaii" => "Hawaii" >> Time.zone.iso8601("1999-12-31T14:00:00Z") => Fri, 31 Dec 1999 14:00:00 HST -10:00 If the timestamp is a ISO 8601 date (YYYY-MM-DD) then the time is set to midnight, e.g: >> Time.zone = "Hawaii" => "Hawaii" >> Time.zone.iso8601("1999-12-31") => Fri, 31 Dec 1999 00:00:00 HST -10:00 This new method has stricter semantics than the current `parse` method and will raise an `ArgumentError` instead of returning nil, e.g: >> Time.zone = "Hawaii" => "Hawaii" >> Time.zone.iso8601("foobar") ArgumentError: invalid date >> Time.zone.parse("foobar") => nil
* Update Unicode Version to 9.0.0Fumiaki MATSUSHIMA2017-01-281-0/+0
| | | | | | | | | | | | | | | | | | | | | | | | | 9.0.0 was released on June 21, 2016 http://blog.unicode.org/2016/06/announcing-unicode-standard-version-90.html http://www.unicode.org/versions/Unicode9.0.0/ There are some changes about grapheme cluster in Unicode 9.0.0: http://unicode.org/reports/tr29/#Grapheme_Cluster_Boundary_Rules ------------ I noticed that `unpack_graphemes` returns [Other] when the argument is Other ÷ Prepend (it must be [Other, Prepend]). But in [Unicode 8.0.0's Prepend has no characters](http://www.unicode.org/reports/tr29/tr29-27.html#Prepend) so we don't have to backport following patch: ```diff should_break = + if pos == eoc + true ```
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-6/+6
|
* Fix `ActiveSupport::TimeZone#strptime` cannot parse timestamps (%Q, %s)denisovlev2016-10-211-11/+15
|
* Add three new rubocop rulesRafael Mendonça França2016-08-161-1/+1
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* applies remaining conventions across the projectXavier Noria2016-08-061-10/+10
|
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-5/+5
|
* applies new string literal convention in activesupport/libXavier Noria2016-08-061-8/+8
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Raise ArgumentError for bad strptime argumentsJohn Gesimondo2016-07-111-0/+1
|
* Do not cache ActiveSupport::TimeZone#utc_offsetAlexey Shein2016-04-251-3/+1
| | | | | | | | | | | | | | | This can be an issue when TZInfo::TimeZone#current_period is refreshed due to timezone period transition, but it's not reflected in ActiveSupport::TimeZone object. For example, on Sun, 26 Oct 2014 22:00 UTC, Moscow changed its TZ from MSK +04:00 to MSK +03:00 (-1 hour). If ActiveSupport::TimeZone['Moscow'] happens to be initialized just before the timezone transition, it will cache its stale utc_offset even after the timezone transition. This commit removes cache and fixes this issue. Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
* Add ActiveSupport::TimeZone.country_zones helperAndrey Novikov2016-04-191-1/+13
| | | | | | That helper will return time zones for any country that tzdata knows about. So it will be much simpler for non-US people to list own country time zones in HTML selects or anywhere.
* Remove unused try requireBart de Water2016-03-101-1/+0
|
* Fix wrong timezone mapping for Switzerland [22233]Kacper Walanus2015-11-151-1/+2
|
* Require only necessary concurrent-ruby classes.Jerry D'Antonio2015-11-041-1/+1
|
* Remove outdated statement about bundled TZInfo.Phil Ross2015-10-181-6/+0
| | | | | The bundled version of TZInfo referred to was removed from Active Support in version 3.0.
* Merge branch 'master' of github.com:rails/docrailsVijay Dev2015-10-041-1/+1
|\
| * Renamed ‘Return’ to ‘Returns’ [ci skip]Ronak Jangir2015-09-281-1/+1
| |
* | Update docs for `formatted_offset` Ronak Jangir2015-09-291-2/+6
| | | | | | Output of `formatted_offset` is depends on input so it’s not always in +HH:MM format. Possible outputs are “+5:30”, “+530” or provided alternate UTC string [ci skip]
* | Replaced `ThreadSafe::Map` with successor `Concurrent::Map`.Jerry D'Antonio2015-09-191-2/+2
|/ | | | | | | The thread_safe gem is being deprecated and all its code has been merged into the concurrent-ruby gem. The new class, Concurrent::Map, is exactly the same as its predecessor except for fixes to two bugs discovered during the merge.
* Improve Docs of ActiveSupport::TimeZone [ci skip]amitkumarsuroliya2015-09-151-2/+2
| | | | | `TimeZone` class is a part of `ActiveSupport` module. For Accessing `TimeZone` class, we need to call `ActiveSupport::TimeZone` instead of `TimeZone`. individual `TimeZone` gives `NameError: uninitialized constant ‘TimeZone’ error
* Update Unicode Version to 8.0.0Anshul Sharma2015-09-041-0/+0
|
* Improve ActiveSupport::TimeWithZone conversion to YAMLAndrew White2015-04-221-0/+9
| | | | | | | | | | | Previously when converting AS::TimeWithZone to YAML it would be output as a UTC timestamp. Whilst this preserves the time information accurately it loses the timezone information. This commit changes that so that it is saved along with the time information. It also provides nicer encoding of AS::TimeZone instances themselves which previously embedded all of the data from the TZInfo records. Fixes #9183.
* Refactor ActiveSupport::Timezone#strptimeAndrew White2015-04-221-28/+35
| | | | | Make strptime behave more like parse when components are missing and share behavior between the two methods.
* Add ActiveSupport::TimeZone#strptime.Paul A Jungwirth2015-04-221-0/+20
| | | | This makes it easier to parse user-inputted times as from a given time zone.
* Revert "Take DST into account when locating TimeZone from Numeric."Andrew White2015-03-091-7/+1
| | | | | | | | | | | | | | | | Reverting this as it's not the implementation that we would like it to be. This is being used inside of ActiveSUpport::TimeZone[] and it's unaware of the context in which to find the timezone period so the timezone found changes depending on whether DST is in effect for the current period. This means that `'2001-01-01'.in_time_zone(-9)` changes from winter/summer even though it's the same date that we're trying to convert. Since finding timezones by numeric offsets is a bit hit and miss we should introduce a new API for finding them which supplies the date context in which we want to search and we should probably also deprecate the finding of timezones via the [] method, though this needs further discussion. This reverts commit 2cc2fa3633edd96773023c6b09d07c7b9d9b841d.