aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/time_with_zone_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Change the empty block style to have space inside of the blockRafael Mendonça França2018-09-251-1/+1
|
* Add `before?` and `after?` methods to date and time classesNick Holden2018-03-061-0/+14
| | | | | | | | Equality comparisons between dates and times can take some extra time to comprehend. I tend to think of a date or time as "before" or "after" another date or time, but I naturally read `<` and `>` as "less than" and "greater than." This change seeks to make date/time comparisons more human readable.
* Remove usage of strip_heredoc in the framework in favor of <<~Rafael Mendonça França2018-02-161-5/+4
| | | | | Some places we can't remove because Ruby still don't have a method equivalent to strip_heredoc to be called in an already existent string.
* Remove extra whitespaceDaniel Colson2018-01-251-15/+15
|
* Use assert_predicate and assert_not_predicateDaniel Colson2018-01-251-7/+7
|
* Use respond_to test helpersDaniel Colson2018-01-251-6/+6
|
* Enable `Layout/LeadingCommentSpace` to not allow cosmetic changes in the futureRyuta Kamizono2017-12-141-2/+2
| | | | Follow up of #31432.
* Enable `Layout/SpaceBeforeComma` rubocop rule, and fixed moreRyuta Kamizono2017-12-121-7/+7
| | | | Follow up of #31390.
* Handle `TZInfo::AmbiguousTime` errorsAndrew White2017-11-151-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | 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.
* [Active Support] `rubocop -a --only Layout/EmptyLineAfterMagicComment`Koichi ITO2017-07-111-0/+1
|
* 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
|
* Add additional options to time `change` methodsAndrew White2017-04-141-0/+6
| | | | | | | Support `:offset` in `Time#change` and `:zone` or `:offset` in `ActiveSupport::TimeWithZone#change`. Fixes #28723.
* Merge pull request #28147 from kmcphillips/master-time-freezeAndrew White2017-03-161-5/+24
|\ | | | | Allow Time#to_time on frozen objects. Return frozen time rather than "RuntimeError: can't modify frozen Time"
| * Handle #to_time and memoization taking into account memoization, frozen ↵Kevin McPhillips2017-03-061-5/+24
| | | | | | | | state, and preserve_timezone flag.
* | Add `rfc3339` aliases to `xmlschema`Andrew White2017-03-031-0/+10
|/ | | | | For naming consistency when using the RFC 3339 profile of ISO 8601 in applications.
* Preload to_datetime before freezing a TimeWithZone instanceAdam Rice2017-02-221-0/+1
|
* Add tests for `blank?`kenta-s2017-02-061-0/+4
|
* "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-97/+97
|
* Revert "Merge pull request #26677 from tbalthazar/26644"Andrew White2016-10-021-6/+0
| | | | | | | | Turns out trying to cache on localtime with arguments is too hard so we'll do it on DateAndTime::Compatibility#to_time instead. This reverts commit 9ce2d1b1a43fc4ef3db59849b7412d30583a4074, reversing changes made to 53ede1aff2025d4391d0e05ba471fdaf3110a99c.
* Fix `ActiveSupport::TimeWithZone#localtime`Thomas Balthazar2016-10-011-0/+6
| | | | | | | | | | | | | | | | | Previously memoization in `localtime` wasn't taking the `utc_offset` parameter into account when returning a cached value. It now caches the computed value depending on the `utc_offset` parameter, e.g: Time.zone = "US/Eastern" t = Time.zone.local(2016,5,2,11) # => Mon, 02 May 2016 11:00:00 EDT -04:00 t.localtime(-7200) # => 2016-05-02 13:00:00 -0200 t.localtime(-3600) # => 2016-05-02 14:00:00 -0100
* Fix ActiveSupport::TimeWithZone#inThomas Balthazar2016-09-241-1/+31
| | | | | | | | | | | | | | | Previously calls to `in` were being sent to the non-DST aware method `Time#since` via `method_missing`. It is now aliased to the DST aware `ActiveSupport::TimeWithZone#+` which handles transitions across DST boundaries, e.g: Time.zone = "US/Eastern" t = Time.zone.local(2016,11,6,1) # => Sun, 06 Nov 2016 01:00:00 EDT -05:00 t.in(1.hour) # => Sun, 06 Nov 2016 01:00:00 EST -05:00
* Add three new rubocop rulesRafael Mendonça França2016-08-161-4/+4
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* modernizes hash syntax in activesupportXavier Noria2016-08-061-47/+47
|
* applies new string literal convention in activesupport/testXavier Noria2016-08-061-177/+177
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Add :weeks to the list of variable duration partsAndrew White2016-08-031-0/+32
| | | | | | | | Since 434df00 week durations are no longer converted to days. This means we need to add :weeks to the parts that ActiveSupport::TimeWithZone will consider being of variable duration to take account of DST transitions. Fixes #26039.
* Make getlocal and getutc always return instances of TimeAndrew White2016-04-231-0/+5
| | | | | | | | | | | | | | | Previously these methods could return either a DateTime or a Time depending on how the ActiveSupport::TimeWithZone instance had been constructed. Changing to always return an instance of Time eliminates a possible stack level too deep error in to_time where it was wrapping a DateTime instance. As a consequence of this the internal time value is now always an instance of Time in the UTC timezone, whether that's as the UTC time directly or a representation of the local time in the timezone. There should be no consequences of this internal change and if there are it's a bug due to leaky abstractions.
* Expand support for ActiveSupport::TimeWithZone#utc?David Celis2015-10-151-0/+15
| | | | | | | | | | | | | | | | | Currently, ActiveSupport::TimeWithZone#utc? simply runs a check to see if the linked ActiveSupport::TimeZone's name is "UTC". This will only return true for ActiveSupport::TimeZone["UTC"], but not for time zones such as "Etc/UTC", "Etc/Universal", or other time zones that are aliases for UTC. Interestingly enough, ActiveSupport::TimeWithZone#utc? is also aliased as #gmt? but will return false for the "GMT" timezone (along with other TZInfo aliases for GMT). Instead of running a simple check on the TimeZone name, we can rely on the underlying TZInfo::TimezonePeriod and TZInfo::TimezoneOffset which keep a record of of the offset's abbreviated name. The possibilities here for UTC time zones are `:UTC`, `:UCT`, and `:GMT`. Signed-off-by: David <me@davidcel.is>
* TimeWithZone#xmlschema should be able to display more than 6 digitsFumiaki MATSUSHIMA2015-09-301-2/+2
|
* Fix `TimeWithZone#eql?` to handle `TimeWithZone` created from `DateTime`Roque Pinel2015-07-191-0/+4
| | | | | | | | | | | | | | | | | | | | Before: ```ruby twz = DateTime.now.in_time_zone twz.eql?(twz.dup) => false ``` Now: ```ruby twz = DateTime.now.in_time_zone twz.eql?(twz.dup) => true ``` Please notice that this fix the `TimeWithZone` comparison to itself, not to `DateTime`. Based on #3725, `DateTime` should not be equal to `TimeWithZone`.
* Require yaml for time_with_zone isolation testPrem Sichanugrist2015-07-101-0/+1
| | | | | Same fix as 109e71d2bb6d2305a091fe7ea96d4f6e9c7cd52d but after mocha got removed in 2f28e5b6417fd4e5d6060983b36262737558b613.
* Removed use of mocha in active_supportRonak Jangir2015-07-101-11/+13
|
* Removed mocha stubbing in active_supportRonak Jangir2015-06-071-28/+35
|
* Improve ActiveSupport::TimeWithZone conversion to YAMLAndrew White2015-04-221-2/+45
| | | | | | | | | | | 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.
* Revert "Take DST into account when locating TimeZone from Numeric."Andrew White2015-03-091-7/+0
| | | | | | | | | | | | | | | | 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.
* Take DST into account when locating TimeZone from Numeric.Yasyf Mohamedali2015-03-031-0/+7
| | | | | | When given a specific offset, use the first result found where the total current offset (including any periodic deviations such as DST) from UTC is equal.
* Merge pull request #16749 from robin850/rbx-name-errorRafael Mendonça França2015-01-021-0/+2
|\ | | | | Rely on NameError#name instead of its error message
| * Skip an error message related assertion on RubiniusRobin Dupret2014-10-281-0/+2
| | | | | | | | | | | | Rubinius' error messages don't call `#inspect` on the concerned object while the assertion is here to address a wrong inspection on MRI with time zones so let's keep this test for now on Rubinius.
* | Optimize TimeWithZoneTest#strftimePablo Herrero2014-10-271-0/+5
|/
* missing activesupport test coverageEugene Gilburg2014-07-191-0/+1
|
* Extract out with_env_tz helper method.Zuhao Wan2014-06-181-50/+12
| | | | | It’s used at so many places that extracting it out into a helper file is worth doing.
* Fixed `ActiveSupport::TimeWithZone#-` so precision is not unnecessarily lostGordon Chan2014-05-301-0/+15
| | | | | | | | | | | | | | | | | | | | When working with objects with a nanosecond component, the `-` method may unnecessarily cause loss of precision. `ActiveSupport::TimeWithZone#-` should return the same result as if we were using `Time#-`: Time.now.end_of_day - Time.now.beginning_of_day #=> 86399.999999999 Before: Time.zone.now.end_of_day.nsec #=> 999999999 Time.zone.now.end_of_day - Time.zone.now.beginning_of_day #=> 86400.0 After: Time.zone.now.end_of_day - Time.zone.now.beginning_of_day #=> 86399.999999999
* Maintain the current timezone in wrap_with_time_zoneAndrew White2014-01-311-0/+5
| | | | | | | Extend the solution from the fix for #12163 to the general case where `Time` methods are wrapped with a time zone. Fixes #12596.
* Make ActiveSupport::TimeWithZone#xmlschema consistentAndrew White2014-01-261-0/+4
| | | | | | Both Time#xmlschema and DateTime#xmlschema can accept nil values for the fraction_digits parameter. This commit makes this so for TimeWithZone values as well.
* Consolidate JSON encoding tests in one fileAndrew White2014-01-261-35/+0
|
* Customize subsecond digits when encoding DateWithTimeParker Selbert2014-01-261-7/+22
| | | | | | | | | | | The subsecond fraction digits had been hardcoded to 3. This forced all timestamps to include the subsecond digits with no way to customize the value. While the subsecond format is part of the ISO8601 spec, it is not adhered to by all parsers (notably mobile clients). This adds the ability to customize the number of digits used, optionally setting them to 0 in order to eliminate the subsecond fraction entirely: ActiveSupport::JSON::Encoding.subsecond_fraction_digits = 0
* Maintain current timezone when changing time during DST overlapAndrew White2014-01-261-0/+5
| | | | | | | | | | | | | | Currently if a time is changed during DST overlap in the autumn then the method `period_for_local` will return the DST period. However if the original time is not DST then this can be surprising and is not what is generally wanted. This commit changes that behavior to maintain the current period if it's in the list of periods returned by `periods_for_local`. It is possible to alter the behavior of `period_for_local` by specifying a second argument but since we may be change from another time that could be either DST or not then this would give inconsistent results. Fixes #12163.
* Fix unused variable warningAndrew White2013-08-041-0/+1
| | | | | | We need to call `in_time_zone` to test that it isn't modifying the receiver but since the variable isn't used it raises a warning so add an assertion to make Ruby think it's being used.