aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/date_time
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* Fix issue where duration where always rounded up to a second:Edouard CHIN2018-10-121-1/+1
| | | | | | | | | | | | | | | | | | | | - Adding a Float as a duration to a datetime would result in the Float being rounded. Doing something like would have no effect because the 0.45 seconds would be rounded to 0 second. ```ruby time = DateTime.parse("2018-1-1") time += 0.45.seconds ``` This behavior was intentionally added a very long time ago, the reason was because Ruby 1.8 was using `Integer#gcd` in the constructor of Rational which didn't accept a float value. That's no longer the case and doing `Rational(0.45, 86400)` would now perfectly work fine. - Fixes #34008
* Move implementation of `before?` and `after?` to `DateAndTime::Calculations`bogdanvlviv2018-03-311-2/+0
| | | | | | | | This prevents duplication of code. Prevent duplication of tests by moving them to `DateAndTimeBehavior`. Related to #32185.
* Add `before?` and `after?` methods to date and time classesNick Holden2018-03-061-0/+2
| | | | | | | | 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.
* Fix "the the " [ci skip]Ryuta Kamizono2018-01-101-1/+1
|
* Update incorrect backtick usage in RDoc to teletypeT.J. Schuck2017-11-221-2/+2
| | | [ci skip]
* [Active Support] require_relative => requireAkira Matsuda2017-10-213-7/+7
| | | | This basically reverts 8da30ad6be34339124ba4cb4e36aea260dda12bc
* Clarify intentions around method redefinitionsMatthew Draper2017-09-011-2/+2
| | | | | | | | | Don't use remove_method or remove_possible_method just before a new definition: at best the purpose is unclear, and at worst it creates a race condition. Instead, prefer redefine_method when practical, and silence_redefinition_of_method otherwise.
* [Active Support] `rubocop -a --only Layout/EmptyLineAfterMagicComment`Koichi ITO2017-07-115-0/+5
|
* Use frozen-string-literal in ActiveSupportKir Shatrov2017-07-095-0/+5
|
* [Active Support] require => require_relativeAkira Matsuda2017-07-013-7/+7
|
* Add missing require for `remove_possible_method`Eugene Kenny2017-04-281-0/+1
| | | | | | https://github.com/rails/rails/commit/505537082849d912e8e29819655b80a573e93c0c added a call to `remove_possible_method`, but didn't require the file that defines it.
* Move `to_time` to `DateTime` compatibility.rb fileAndrew White2017-03-161-1/+11
| | | | | | 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.
* Update `DateTime#change` to support usec and nsecAndrew White2017-03-021-4/+14
| | | | | | | | | | | Adding support for these options now allows us to update the `DateTime#end_of` methods to match the equivalent `Time#end_of` methods, e.g: datetime = DateTime.now.end_of_day datetime.nsec == 999999999 # => true Fixes #21424.
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-1/+1
|
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-6/+6
|
* modernizes hash syntax in activesupportXavier Noria2016-08-061-8/+8
|
* applies new string literal convention in activesupport/libXavier Noria2016-08-065-10/+10
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Make getlocal and getutc always return instances of TimeAndrew White2016-04-231-14/+18
| | | | | | | | | | | | | | | 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.
* Add DateTime#subsecAndrew White2016-04-231-0/+7
| | | | | Mirrors the Time#subsec method by returning the fraction of the second as a Rational.
* Add additional aliases for DateTime#utcAndrew White2016-04-231-0/+2
|
* Move `DateTime#getlocal` to `/core_ext/date_time/calculations.rb`yui-knk2016-04-232-11/+12
| | | | | | | | `DateTime#getlocal` is newly added public API. It's responsible is same as `DateTime#utc`, so `calculations.rb` is a best plase to define this method. For keeping consistency with `DateTime#utc`, defines `#localtime` and defines `getlocal` as an alias method.
* 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.
* Call super instead of returning nil for DateTime#<=>Andrew White2016-04-031-5/+2
| | | | | | | | The native DateTime#<=> implementation can be used to compare instances with numeric values being considered as astronomical julian day numbers so we should call that instead of returning nil. Fixes #24228.
* Remove not needed includingyui-knk2016-04-021-6/+0
| | | | | Because `DateTime` inherits `Date` and `Date` includes `DateAndTime::Zones`, `DateTime` not need to include `DateAndTime::Zones` again.
* Update docs for `formatted_offset` Ronak Jangir2015-09-291-0/+2
| | | 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]
* Short-circuit `blank?` on date and time valuesAndrew White2015-09-211-0/+12
| | | | | | | The concept of a blank date or time doesn't make sense so we can short circuit the calls for `blank?` on these classes to gain small speed boost. Fixes #21657
* DateTime#<=> return nil when compare to the invalid String as Time.pocke2015-01-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | before: p Time.now == 'a' # => false p Time.now <=> 'a' # => nil require 'active_support' require 'active_support/core_ext' p Time.now == 'a' # => false p Time.now <=> 'a' # => invalid date (ArgumentError) and on ruby 2.2, Time.now == 'a' warning. warning: Comparable#== will no more rescue exceptions of #<=> in the next release. warning: Return nil in #<=> if the comparison is inappropriate or avoid such comparison. after: - Error handling. - Quiet warnings.
* Better doc for AS::DateTime#seconds_since_midnightclaudiob2014-12-041-1/+5
| | | | | Adds examples and keeps coherent with the documentation of the similar method `seconds_until_end_of_day`. [ci skip]
* Fix DateTime comparison with DateTime::Infinity objectRafael Mendonça França2014-08-061-1/+3
| | | | Fixes #16406
* `DateTime#to_f` now preserves fractional seconds.John Paul Ashenfelter2014-07-021-2/+2
| | | | | | | Previously this method always returns `.0` in the fractional part. This commit changes it to preserve the fractional seconds instead. Fixes #15994.
* Merge pull request #12080 from ShayDavidson/fix_datetime_partial_datesMatthew Draper2014-05-281-1/+11
|\ | | | | | | Added partial days support to `DateTime`'s `advance` method.
| * Added partial days support to `DateTime`'s `advance` method.Shay Davidson2013-08-301-5/+15
| | | | | | | | | | You can now add partial days (e.g. 2.5.days) to `DateTime` with the advance method. This was acheived by mimicing the `advance` implementation in `Time`.
* | Check `respond_to` before delegation due to: ↵Aaron Patterson2014-01-091-1/+5
|/ | | | https://github.com/ruby/ruby/commit/d781caaf313b8649948c107bba277e5ad7307314
* Refactor Date, Time, DateTime timezone methodsGilad Zohari2013-08-011-21/+2
| | | | | | Similar implementations of #in_time_zone exists for Date, Time and DateTime so method is extracted into its own module. Also some logic is extracted into private method.
* Remove duplication from date_time calculationsGilad Zohari2013-07-311-10/+0
| | | | | | Methods: :past? and :future? are already defined identically in date_and_time/calculations.rb which is included in Date. Because DateTime is a subclass of Date, it can call them.
* Merge pull request #10879 from makaroni4/masterAndrew White2013-07-291-0/+10
|\ | | | | Added Time#middle_of_day method
| * Added Time#middle_of_dayAnatoli Makarevich2013-07-281-0/+10
| | | | | | | | Added middle_of_day method to Date and DateTime
* | Fix handling of offsets with Time#to_s(:iso8601)Andrew White2013-07-291-0/+1
| | | | | | | | | | | | Use a lambda to ensure that the generated string respects the offset of the time value. Also add DateTime#to_s(:iso8601) and Date#to_s(:iso8601) for completeness.
* | Add missing require so that DateTime has the right superclassAndrew White2013-07-101-0/+1
| | | | | | | | | | | | | | | | If the DateTime core extensions were loaded before the Date core extensions then you would get a superclass mismatch as DateTime hasn't been defined yet so it gets set to Object by the acts_like core extension. Fixes #11206
* | Removed unsued deprecation requireRashmi Yadav2013-07-041-1/+0
| |
* | Remove deprecated `DateTime.local_offset`Arun Agrawal2013-07-031-7/+0
| |
* | Keep sub-second resolution when wrapping a DateTime valueAndrew White2013-06-131-0/+10
|/ | | | | | | Add `DateTime#usec` and `DateTime#nsec` so that `ActiveSupport::TimeWithZone` keeps sub-second resolution when wrapping a `DateTime` value. Fixes #10855
* Squashed commit of the following:Aaron Patterson2013-05-032-5/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | commit 2683de5da85135e8d9fe48593ff6167db9d64b18 Author: Aaron Patterson <aaron.patterson@gmail.com> Date: Fri May 3 11:29:20 2013 -0700 cannot support infinite ranges right now commit cebb6acef2c3957f975f6db4afd849e535126253 Author: Aaron Patterson <aaron.patterson@gmail.com> Date: Fri May 3 11:26:12 2013 -0700 reverting infinity comparison commit 385f7e6b4efd1bf9b89e8d607fcb13e5b03737ea Author: Aaron Patterson <aaron.patterson@gmail.com> Date: Fri May 3 11:23:28 2013 -0700 Revert "Added ability to compare date/time with infinity" This reverts commit 38f28dca3aa16efd6cc3af6453f2e6b9e9655ec1. Conflicts: activesupport/CHANGELOG.md activesupport/lib/active_support/core_ext/numeric/infinite_comparable.rb activesupport/test/core_ext/date_ext_test.rb activesupport/test/core_ext/date_time_ext_test.rb activesupport/test/core_ext/numeric_ext_test.rb activesupport/test/core_ext/time_ext_test.rb activesupport/test/core_ext/time_with_zone_test.rb commit 0d799a188dc12b18267fc8421675729917610047 Author: Aaron Patterson <aaron.patterson@gmail.com> Date: Fri May 3 11:18:53 2013 -0700 Revert "Refactor infinite comparable definition a bit" This reverts commit dd3360e05e4909f2f0c74a624cccc2def688f828. commit 42dec90e49745bbfae546f0560b8783f6b48b074 Author: Aaron Patterson <aaron.patterson@gmail.com> Date: Fri May 3 11:18:47 2013 -0700 Revert "Require 'active_support/core_ext/module/aliasing' in the infinite_comparable module" This reverts commit 7003e71c13c53ec3d34250560fbf80b8381df693.
* Fixes Dependency bug in Active SupportTomohiko Himura2013-05-023-0/+3
| | | | DateTime defined in date.rb
* Keep second fraction when DateTime#change is called.Chris Baynes2013-02-251-1/+1
|
* Correct comment for (beginning|end)_of_minuteGert Goet2013-02-221-2/+2
|
* Added beginning_of_minute support to core_ext calculations for Time and DateTimeGagan Awhad2013-02-211-0/+12
|
* Clarified the minute option on DateTime#changeJakob Waller2013-01-101-1/+1
|
* Added ability to compare date/time with infinitybUg2013-01-042-7/+5
| | | | | | | | | | | | | | | | | Date, DateTime, Time and TimeWithZone can now be compared to infinity, so it's now possible to create ranges with one infinite bound and date/time object as another bound. Ex.: @range = Range.new(Date.today, Float::INFINITY) Also it's possible to check inclusion of date/time in range with conversion. Ex.: @range.include?(Time.now + 1.year) # => true @range.include?(DateTime.now + 1.year) # => true Ability to create date/time ranges with infinite bound is required for handling postgresql range types.