aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/date_and_time
Commit message (Collapse)AuthorAgeFilesLines
* Missing require "AS/core_ext/date_time/conversions"Akira Matsuda2019-08-011-0/+1
| | | | | This causes "NameError: undefined local variable or method `nsec' for #<DateTime:0x0000559163cdd878>"
* Delete `DateAndTime` method definition in rails that is compatible with ruby ↵soartec-lab2019-06-161-30/+0
| | | | | | | | | | | | definition Tests are also only on the `Time` class Update doc forgetting to erase when moved Update guide `Date` class to `Time` class and defined file Update guide correction omission
* Enable `Layout/EmptyLinesAroundAccessModifier` copRyuta Kamizono2019-06-131-1/+0
| | | | | | | | | | | We sometimes say "✂️ newline after `private`" in a code review (e.g. https://github.com/rails/rails/pull/18546#discussion_r23188776, https://github.com/rails/rails/pull/34832#discussion_r244847195). Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style `EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059). That cop and enforced style will reduce the our code review cost.
* Refactor calculating beginning_of_quarter and end_of_quarter (#34927)Krzysztof Rybka2019-01-141-2/+2
| | | | | | | * Calculate first month of quarter instead of finding * Calculate last month of quarter instead of finding [Krzysztof Rybka + Rafael Mendonça França]
* Merge pull request #33106 from marcandre/datecalcRafael Mendonça França2018-06-111-15/+12
|\ | | | | | | Improve some DateAndTime calculations
| * Use fetch for better error handlingMarc-Andre Lafortune2018-06-091-2/+2
| |
| * Use same weekday correspondance as Date#wday.Marc-Andre Lafortune2018-06-091-13/+10
|/ | | | | | | | | DeepCover revealed that most of these `wday != 0 ? wday - 1 : 6` were not entirely covered, i.e. the case of `wday == 0` was not tested: https://deep-cover.github.io/rails-cover/activesupport/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb.html#L351 There's actually no valid reason to consider Sunday a special case, so this commit simply reajusts the values used for calculations.
* Improve grammar for DateAndTime before? and after? calculations [ci skip]Aaron Sumner2018-05-241-2/+2
|
* Move implementation of `before?` and `after?` to `DateAndTime::Calculations`bogdanvlviv2018-03-311-0/+10
| | | | | | | | This prevents duplication of code. Prevent duplication of tests by moving them to `DateAndTimeBehavior`. Related to #32185.
* Refactor Date/Time next_occurring and prev_occurringT.J. Schuck2017-11-281-4/+12
| | | | | | | | | | | | | | | | | | These methods were originally added in https://github.com/rails/rails/pull/26600 This includes a couple of refactors to make these methods behave more similarly to other Date/Time extensions added by Active Support: 1. Use `advance` instead of `since` and `ago` to time-travel — this is particularly important to keep the returned instance’s class matching `self`. Before this change: today = Date.today # => Tue, 28 Nov 2017 today.class # => Date today.next_occurring(:wednesday) # => Wed, 29 Nov 2017 00:00:00 UTC +00:00 today.next_occurring(:wednesday).class # => ActiveSupport::TimeWithZone After this change, a Date (or Time, or DateTime) instance is properly returned (just like is shown in the new docs). This is generally how everything else in DateAndTime::Calculations works. 2. Move the tests from the DateTime tests to the DateAndTimeBehavior tests. The latter location is mixed in to the core_ext tests for _all_ of Date, Time, and DateTime to test the behavior across all of the classes. The previous location is for testing core_ext functionality added specifically just to DateTime. 3. Better docs!
* Allows pass argument for `Time#prev_year` and `Time#next_year`.bogdanvlviv2017-10-241-5/+9
|
* Allows pass argument for `Time#prev_month` and `Time#next_month`bogdanvlviv2017-10-241-5/+9
|
* Allows pass argument for `Time#prev_day` and `Time#next_day`bogdanvlviv2017-10-241-6/+6
|
* [Active Support] require_relative => requireAkira Matsuda2017-10-212-2/+2
| | | | This basically reverts 8da30ad6be34339124ba4cb4e36aea260dda12bc
* [Active Support] `rubocop -a --only Layout/EmptyLineAfterMagicComment`Koichi ITO2017-07-113-0/+3
|
* Use frozen-string-literal in ActiveSupportKir Shatrov2017-07-093-0/+3
|
* [Active Support] require => require_relativeAkira Matsuda2017-07-012-2/+2
|
* Use mattr_accessor default: option throughout the projectGenadi Samokovarov2017-06-031-1/+1
|
* Add next occur and previous occurred day of week API (#26600)Shota Iguchi2017-05-301-0/+16
|
* Move `to_time` to `DateTime` compatibility.rb fileAndrew White2017-03-161-4/+0
| | | | | | We are overriding it in `Time` and `ActiveSupport::TimeWithZone` so there's no point in having it in the `DateAndTime::Compatibility` module. Also add some docs for the `to_time` implementations.
* Handle #to_time and memoization taking into account memoization, frozen ↵Kevin McPhillips2017-03-061-5/+1
| | | | state, and preserve_timezone flag.
* Fix copy_time_to: Copy nsec instead of usecJosua Schmid2016-10-201-1/+1
| | | | | | | | | | | | | `copy_time_to` is a helper function for date and time calculations. It's being used by `prev_week`, `next_week` and `prev_weekday` to keep the time fraction when jumping around between days. Previously the nanoseconds part was lost during the operation. This lead to problems in practice if you were using the `end_of_day` calculation. Resulting in the time fraction of `end_of_day` not being the same as next week's `end_of_day`. With this fix `copy_time_to` doesn't forget the `nsec` digits.
* Cache to_time to improve performance when comparingAndrew White2016-10-021-1/+5
| | | | | | | | | | | | | | | | In #25880 we tried to cache localtime to fix the performance regression but that proved to be difficult due to the fact that localtime/getlocal can take a utc_offset argument. We tried caching based on the argument but since the argument can be nil sometimes that meant that if the TZ environment variable changed then the cached value for nil became invalid. By moving the caching to DateAndTime#compatibility we don't have to worry about arguments since it doesn't take any. There is a possible edge condition where preserve_timezone is set to false and the system timezone changes then it could result in a cached value being incorrect but the only way to fix this would be to remove all caching and live with the performance issue.
* fix typo in `DateAndTime::Calculations#all_week` doc [ci skip]yuuji.yaginuma2016-09-271-1/+1
| | | | | `Date.week_start` does not exist. `Date.beginning_of_week` seems to be correct. Ref: #5339
* code gardening: removes redundant selfsXavier Noria2016-08-081-1/+1
| | | | | | | | | A few have been left for aesthetic reasons, but have made a pass and removed most of them. Note that if the method `foo` returns an array, `foo << 1` is a regular push, nothing to do with assignments, so no self required.
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-7/+6
|
* modernizes hash syntax in activesupportXavier Noria2016-08-061-20/+20
|
* applies new string literal convention in activesupport/libXavier Noria2016-08-062-2/+2
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Introduce Date#all_dayHenrik Nyh2016-05-111-0/+5
| | | | | | | | | Useful for queries like: Item.where(created_at: Date.current.all_day) There was already a Time#all_day with the same behaviour, but for queries like the above, Date is more convenient.
* Merge branch 'master' of github.com:rails/docrailsVijay Dev2016-04-291-2/+2
|\ | | | | | | | | Conflicts: guides/source/configuring.md
| * [ci skip] Aline results of code examples in commentsyui-knk2016-04-201-2/+2
| |
* | Add require of mattr_accessor since Compatibility relies on it.Jason Frey2016-04-251-0/+2
| | | | | | | | | | Follow up to https://github.com/rails/rails/commit/c9c5788a527b70d7f983e2b4b47e3afd863d9f48
* | Follow up of ↵Vipul A M2016-04-241-4/+4
| | | | | | | | | | | | https://github.com/rails/rails/commit/c9c5788a527b70d7f983e2b4b47e3afd863d9f48 [ci skip]
* | Add compatibility for Ruby 2.4 `to_time` changesAndrew White2016-04-231-0/+16
|/ | | | | | | | | | | | | | | In Ruby 2.4 the `to_time` method for both `DateTime` and `Time` will preserve the timezone of the receiver when converting to an instance of `Time`. Since Rails 5.0 will support Ruby 2.2, 2.3 and later we need to introduce a compatibility layer so that apps that upgrade do not break. New apps will have a config initializer file that defaults to match the new Ruby 2.4 behavior going forward. For information about the changes to Ruby see: https://bugs.ruby-lang.org/issues/12189 https://bugs.ruby-lang.org/issues/12271 Fixes #24617.
* Add missing require to tryRafael Mendonça França2016-03-111-0/+2
|
* Add `#on_weekday?` method to `Date`, `Time`, and `DateTime`.Vipul A M2016-02-151-0/+5
|
* Renamed ‘Return’ to ‘Returns’ [ci skip]Ronak Jangir2015-09-281-1/+1
|
* Improving `in_time_zone` docs [ci skip]amitkumarsuroliya2015-09-131-2/+1
| | | `DateTime.utc` is not a valid method. It gives `NoMethodError: undefined method `utc` for DateTime:Class`. As we know that we can calculate `utc` time from `Time` Class, but we can’t calculate `utc` time from `DateTime` Class.
* added examples to DateAndTime::Calculations [ci skip]Julio Lopez2015-07-181-9/+34
|
* Revert "Replace use of alias chains with prepend at core_ext/date and ↵Roque Pinel2015-05-291-23/+0
| | | | core_ext/time"
* Merge pull request #19878 from pabloh/replace_alias_chains_with_prependRafael Mendonça França2015-05-281-0/+23
|\ | | | | Replace use of alias chains with prepend at core_ext/date and core_ext/time
| * Replace use of alias chains with prepend at core_ext/datePablo Herrero2015-05-041-0/+23
| |
* | Merge pull request #20049 from iamvery/patch-1Yves Senn2015-05-071-1/+13
|\ \ | |/ |/| | | Amend `next_week` documentation [ci skip]
| * Add examples of Date and Time `next_week` usageJay Hayes2015-05-071-0/+7
|/ | | | [skip ci]
* Use Ruby's #include? to avoid relying on AS extensionCarlos Antonio da Silva2015-01-061-1/+1
| | | | | | | | The build has failed when running the date/time ext tests in isolation due to the missing extension, so better than adding a require is using just Ruby in this case. https://travis-ci.org/rails/rails/jobs/46107954#L1077
* Add #prev_day and #next_day as counterparts to #yesterday and #tomorrow for ↵George Claghorn2015-01-061-6/+16
| | | | Date, Time, and DateTime
* Add same_time option to #prev_week and #next_week for Date, Time, and DateTimeGeorge Claghorn2015-01-061-17/+22
|
* Add #on_weekend?, #next_weekday, and #prev_weekday methods to Date, Time, ↵George Claghorn2015-01-061-0/+25
| | | | | | | | | | | | | and DateTime `#on_weekend?` returns true if the receiving date/time falls on a Saturday or Sunday. `#next_weekday` returns a new date/time representing the next day that does not fall on a Saturday or Sunday. `#prev_weekday` returns a new date/time representing the previous day that does not fall on a Saturday or Sunday.
* Added Date#all_week/month/quarter/year for generating date rangesDimko2013-12-031-0/+21
|
* No need to use blocks hereAndrew White2013-08-041-11/+9
|