aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/date_time
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* Add missing at_end_of_* aliasesAndrew White2012-12-111-0/+2
|
* Add #seconds_until_end_of_day to DateTime and TimeOlek Janiszewski2012-11-291-0/+9
|
* Make caller attribute in deprecation methods optionalAlexey Gaziev2012-10-301-1/+1
|
* update AS/core_ext docs [ci skip]Francesco Rodriguez2012-09-123-32/+41
|
* Expand documentation for change() method in Time, Date, and DateTimeJeff Shantz2012-08-291-2/+7
|
* Improve performance of DateTime#seconds_since_unix_epochAndrew White2012-07-021-2/+5
| | | | | | | | | | | | | | | | | | | Calculate the seconds since the UNIX epoch using the difference in Julian day numbers from the epoch date. By reducing the Rational math to just the offset component this gives a significant improvement. Benchmark: Calculating -------------------------------------------- new 27733 i/100ms current 15031 i/100ms new 27737 i/100ms current 15549 i/100ms -------------------------------------------------------- new 548182.1 (±0.9%) i/s - 2745567 in 5.008943s current 216380.9 (±1.6%) i/s - 1082232 in 5.002781s new 510281.9 (±1.2%) i/s - 2551804 in 5.001525s current 219858.3 (±1.8%) i/s - 1103979 in 5.023039s
* Revert "Use strftime to convert DateTime to numeric"Andrew White2012-07-011-1/+2
| | | | | | | There appears to be a bug with DateTime#strftime("%s") on 32-bit platforms. Bug report: http://bugs.ruby-lang.org/issues/6683 This reverts commit 210cd756a628cc19c0d6e44bee8c33dfb2d9d598.
* Remove DateTime#to_time overrideAndrew White2012-07-011-14/+0
| | | | | | | | Currently if the offset is not zero then to_time returns self which can lead to errors where a developer assumes that the value is a Time. To solve this we can use the native implementation of DateTime#to_time in Ruby 1.9.3 as it handles offsets properly and is faster than our override.
* Use strftime to convert DateTime to numericAndrew White2012-07-011-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The native implementation of the seconds since the UNIX epoch in strftime is significantly faster than our method. Benchmark: ---------- require 'benchmark/ips' require 'date' require 'time' date = DateTime.civil(1253,7,6,20,4,0) Benchmark.ips do |x| x.report("strftime.to_i") { date.strftime('%s').to_i } x.report("ssue.to_i") { ((date - DateTime.civil(1970)) * 86400).to_i } x.report("strftime.to_f") { date.strftime('%s').to_f } x.report("ssue.to_f") { ((date - DateTime.civil(1970)) * 86400).to_f } end Output: ------- Calculating ------------------------------------- strftime.to_i 26480 i/100ms ssue.to_i 13818 i/100ms strftime.to_f 26561 i/100ms ssue.to_f 14479 i/100ms ------------------------------------------------- strftime.to_i 616937.3 (±2.4%) i/s - 3098160 in 5.024749s ssue.to_i 200108.8 (±6.9%) i/s - 994896 in 4.999278s strftime.to_f 553581.3 (±2.2%) i/s - 2788905 in 5.040397s ssue.to_f 204260.3 (±4.3%) i/s - 1028009 in 5.043072s
* stop `to_s`ing method namesAkira Matsuda2012-06-061-1/+1
| | | | Module#methods are Symbols in Ruby >= 1.9
* removing unnecessary 'examples' noise from activesupportFrancesco Rodriguez2012-05-132-3/+0
|
* added beginning_of_hour support to core_ext calculations for Time and DateTimeMark J. Titorenko2012-05-041-0/+11
|
* String quotes and trailing spacesAlexey Gaziev2012-04-291-1/+1
|
* AS core_ext refactoring pt.2Alexey Gaziev2012-04-292-4/+10
|
* AS core_ext refactoringAlexey Gaziev2012-04-291-12/+21
|