aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/time_zone_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Revert "Use assert_match / assert_no_match for asserting match"Akira Matsuda2019-07-291-3/+3
| | | | | | This reverts commit e9651deea4145f62224af56af027bfbb3e45e4cd. Now we're having both `=~` and `match?` for these objects, and it's nicer to have explicit tests for both of them
* Add AS::TimeZone#match?Akira Matsuda2019-07-291-0/+7
|
* Use assert_match / assert_no_match for asserting matchAkira Matsuda2019-07-271-3/+3
|
* ActiveSupport typo fixes.alkesh262019-02-011-1/+1
|
* Allow Time.zone.at to receive a second argumentJosh Pencheon2018-05-301-0/+10
| | | | For parity with Ruby's Time::at
* Fix name of the test added by #32613bogdanvlviv2018-04-191-1/+1
|
* Fix exception in AS::Timezone.all when any tzinfo data is missingDominik Sander2018-04-181-0/+15
| | | | | | | | | | | | | | | | | | | | 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.
* Return all mappings for a timezone id in `country_zones`Andrew White2018-02-191-0/+10
| | | | | | | | | | | | | | 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.
* Make ActiveSupport::TimeZone.all independent of previous lookups (#31176)Chris LaRose2017-11-221-0/+7
|
* Handle `TZInfo::AmbiguousTime` errorsAndrew White2017-11-151-0/+26
| | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Remove time stubs after each testGeorge Claghorn2017-07-221-3/+0
| | | | Reverts 7abb6e0.
* [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
| |
| * Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | | | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
| * Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
| |
* | Mention and test for possible ArgumentError when parsing timesDorian Marié2017-04-081-0/+10
|/
* Return unmapped timezones from `country_zones`Andrew White2017-03-281-0/+4
| | | | | | | 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/+110
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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/+72
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* "Use assert_nil if expecting nil. This will fail in minitest 6."Akira Matsuda2016-12-251-1/+1
|
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-48/+48
|
* Fix `ActiveSupport::TimeZone#strptime` cannot parse timestamps (%Q, %s)denisovlev2016-10-211-0/+18
|
* improve error message when include assertions failMichael Grosser2016-09-161-4/+4
| | | | | | assert [1, 3].includes?(2) fails with unhelpful "Asserting failed" message assert_includes [1, 3], 2 fails with "Expected [1, 3] to include 2" which makes it easier to debug and more obvious what went wrong
* applies new string literal convention in activesupport/testXavier Noria2016-08-061-109/+109
| | | | | 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/+7
|
* Do not cache ActiveSupport::TimeZone#utc_offsetAlexey Shein2016-04-251-0/+11
| | | | | | | | | | | | | | | 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-0/+5
| | | | | | 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.
* Require yaml for time_zone isolation test.Kasper Timm Hansen2015-07-111-0/+1
| | | | See 2f26f611 for more info.
* Removed mocha stubbing in active_supportRonak Jangir2015-06-071-6/+8
|
* 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-0/+9
| | | | | 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/+65
| | | | This makes it easier to parse user-inputted times as from a given time zone.
* make zones_map privateTony Miller2015-02-061-2/+1
| | | | | Conflicts: activesupport/lib/active_support/values/time_zone.rb
* Use directly TZInfo::Timezone without proxybrainopia2015-01-041-9/+4
| | | | | Since real timezone is loaded anyway in `#utc_offset` which is called during `#create`
* Use Hash#each_key instead of Hash#keys.eachErik Michaels-Ober2014-09-291-1/+1
| | | | | | Hash#keys.each allocates an array of keys; Hash#each_key iterates through the keys without allocating a new array. This is the reason why Hash#each_key exists.
* Extract out with_env_tz helper method.Zuhao Wan2014-06-181-8/+3
| | | | | It’s used at so many places that extracting it out into a helper file is worth doing.
* Tidy up implementation of #15010Andrew White2014-05-111-4/+6
|
* Make TimeZone#parse behave more like Time#parse.Ulysse Carion2014-05-111-0/+7
| | | | | Namely, if the mday is omitted but any other upper components are, then instead of supplying the mday from the current time, it defaults to 1.
* travel_to travels back and re-raises if the block raisesXavier Noria2014-02-181-0/+12
|
* adds a missing travel backXavier Noria2014-02-181-4/+4
|
* time helpers honor the application time zone when passed a dateXavier Noria2014-02-181-0/+14
| | | | | | | | | | | | | | | | | Rails applications are expected to be always aware of the application time zone. To be consistent with that contract, we have to assume that a bare date passed to time helpers is a date in the application time zone, not in the system time zone. The system time zone is irrelevant, we should totally ignore it. For example, travel_to user.birth_date + 40.years should make that user be 40th years old regardless of the system time zone. Without this patch that may not be true.
* Remove automatic removal of Date/Time stubs after each test caseRafael Mendonça França2014-01-301-0/+3
| | | | | | This behavior is only work out-of-box with minitest and also add a downside to run after each test case, even if we don't used the travel or travel_to methods
* Add support for localized date referencesColin Bartlett2013-12-031-0/+22
| | | | | | | Ruby's Date class automatically gives us #yesterday, #today, and #tomorrow. And ActiveSupport has a handy Time.zone.today for getting a localized version. But there was no localized version of #yesterday or #tomorrow. Until now.
* Use travel_to convention in existing testColin Bartlett2013-12-031-4/+4
|
* Add regression tests for #9678Andrew White2013-03-131-0/+16
| | | | | The bug with `ActiveSupport::TimeZone.parse` described in #9678 was unwittingly fixed in 005d910 so add some tests to prevent regression.
* Only take the date parts from Time.zone.nowAndrew White2012-12-011-0/+7
| | | | | | | When there are missing components in the Hash returned by Date._parse only the date components should default to the value of Time.zone.now, the time components should all default to zero.
* Make `Time.zone.parse` to work with JavaScript date stringsAndrew White2012-12-011-14/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Chrome, Safari and Firefox serialize Date objects to strings such as 'Mon May 28 2012 00:00:00 GMT-0700 (PDT)'. When these strings are parsed the zone is interpreted as 'GMT-0700' which doesn't exist in the TzInfo list of timezones. By taking advantage of the improved date/time handling in 1.9.3 we can use `Date._parse` and the `:offset` value which is parsed correctly. Three tests were amended to make them pass: 1. test_parse_with_old_date This needed changing to a different value because the original value was before EST was adopted so was being changed to a LMT (Local Mean Time) value after the change. It didn't before because `DateTime` just has offsets from UTC not timezones. 2. test_parse_should_not_black_out_system_timezone_dst_jump Changed the implementation of this test as the stubs were dependent on internal implementation details of the test. Confirmed that the modified test still failed when the implementation of `parse` was restored to pre-#5571. 3. test_parse_should_black_out_app_timezone_dst_jump Ditto. Closes #5770.
* Fix #6962. AS::TimeWithZone#strftime responds incorrectly to %:z and %::z ↵kennyj2012-09-201-0/+8
| | | | format strings.
* [#5559] Do not black out the system timezone DST jump hour if Time.zone ↵Jarkko Laine2012-03-241-0/+18
| | | | | | | | differs from that. The system timezone DST jump hour should not be blacked out by Time.zone.parse if current Time.zone does not do the jump at that time. Fixes #5559.