aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/numeric
Commit message (Collapse)AuthorAgeFilesLines
* ActiveSupport module may not always already defined hereAkira Matsuda2018-10-201-121/+123
| | | | `ruby -ractive_support/core_ext/range/conversions.rb -ep` dies with uninitialized constant ActiveSupport
* Deprecate "active_support/core_ext/numeric/inquiry"bogdanvlviv2018-03-021-25/+2
| | | | | | Numeric#positive? and Numeric#negative? was added to Ruby since 2.3, see https://github.com/ruby/ruby/blob/ruby_2_3/NEWS Rails 6 requires Ruby 2.4.1+ since https://github.com/rails/rails/pull/32034
* Rails 6 requires Ruby 2.4.1+Jeremy Daer2018-02-171-7/+1
| | | | | | Skipping over 2.4.0 to sidestep the `"symbol_from_string".to_sym.dup` bug. References #32028
* Enable `Style/RedundantReturn` rubocop rule, and fixed a couple moreRyuta Kamizono2017-11-011-7/+7
| | | | Follow up of #31004.
* Simplify API documentation of methods that return a Durationbogdanvlviv2017-10-241-17/+5
| | | | Related to #30972
* Make clear that Time core extensions are split between Numeric and IntegerJoão Fernandes2017-10-241-6/+8
| | | | | | | The documentation wrongly suggests that Time extensions to Numeric include methods months and years, when these belong to Integer. Update both classes and guides.
* [Active Support] require_relative => requireAkira Matsuda2017-10-212-8/+8
| | | | This basically reverts 8da30ad6be34339124ba4cb4e36aea260dda12bc
* [Active Support] `rubocop -a --only Layout/EmptyLineAfterMagicComment`Koichi ITO2017-07-114-0/+4
|
* Use frozen-string-literal in ActiveSupportKir Shatrov2017-07-094-0/+4
|
* [Active Support] require => require_relativeAkira Matsuda2017-07-012-8/+8
|
* Allocation free Integer#to_sJean Boussier2017-01-191-16/+15
|
* Add duration constructors for use in Numeric extensionsAndrew White2017-01-121-6/+6
| | | | | The Numeric extensions like 1.day, 1.month, etc. shouldn't know how the internals of ActiveSupport::Duration works.
* Fix inconsistent results when parsing large durations and constructing ↵Andrey Novikov2017-01-091-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | durations from code ActiveSupport::Duration.parse('P3Y') == 3.years # It should be true Duration parsing made independent from any moment of time: Fixed length in seconds is assigned to each duration part during parsing. Changed duration of months and years in seconds to more accurate and logical: 1. The value of 365.2425 days in Gregorian year is more accurate as it accounts for every 400th non-leap year. 2. Month's length is bound to year's duration, which makes sensible comparisons like `12.months == 1.year` to be `true` and nonsensical ones like `30.days == 1.month` to be `false`. Calculations on times and dates with durations shouldn't be affected as duration's numeric value isn't used in calculations, only parts are used. Methods on `Numeric` like `2.days` now use these predefined durations to avoid duplicating of duration constants through the codebase and eliminate creation of intermediate durations.
* Remove deprecated method Numeric#to_formatted_sAndrew White2016-11-141-5/+0
|
* Fixnum and Bignum are deprecated in Ruby trunkMatthew Draper2016-10-081-1/+1
| | | | https://bugs.ruby-lang.org/issues/12739
* applies remaining conventions across the projectXavier Noria2016-08-061-1/+0
|
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-21/+21
|
* applies new string literal convention in activesupport/libXavier Noria2016-08-062-8/+8
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Support for unified Integer class in Ruby 2.4+Jeremy Daer2016-05-181-2/+8
| | | | | | | | Ruby 2.4 unifies Fixnum and Bignum into Integer: https://bugs.ruby-lang.org/issues/12005 * Forward compat with new unified Integer class in Ruby 2.4+. * Backward compat with separate Fixnum/Bignum in Ruby 2.2 & 2.3. * Drops needless Fixnum distinction in docs, preferring Integer.
* Change 1.week to create 1 week durations instead of 7 days durations.Andrey Novikov2016-04-281-8/+8
| | | | This is just to remove astonishment from getting `3600 seconds` from typing `1.hour`.
* Revert "Change 1.week to create 1 week durations instead of 7 days durations."Jeremy Daer2016-04-271-8/+8
| | | | | | Regression: adding minutes/hours to a time would change its time zone This reverts commit 1bf9fe75a6473cb7501cae544cab772713e68cef.
* Change 1.week to create 1 week durations instead of 7 days durations.Andrey Novikov2016-04-181-8/+8
| | | | This is just to remove astonishment from getting `3600 seconds` from typing `1.hour`.
* Show correct return types for examples [ci skip]Gert Goet2016-02-201-49/+49
|
* Fix - to_s(:db) on Numeric rangeAkshay Vishnoi2015-12-291-1/+5
|
* Merge pull request #22822 from maclover7/fix-22805Richard Schneeman2015-12-281-0/+1
|\ | | | | Add a missing require to ActiveSupport::NumericWithFormat
| * Add a missing require to ActiveSupport::NumericWithFormatJon Moss2015-12-281-0/+1
| |
* | Add support for Petabyte and Exabyte in number to human sizeAkshay Vishnoi2015-12-221-0/+2
|/
* Merge pull request #20038 from imanel/numeric_prependSean Griffin2015-10-201-25/+12
|\ | | | | Use Module.prepend instead of alias_method and unify behavior of all Numeric extensions
| * Unify behavior of all Numeric extensions and use Module.prepend instead of ↵Bernard Potocki2015-05-281-25/+12
| | | | | | | | alias_method
* | Corrected numeric conversions output [ci skip]amitkumarsuroliya2015-09-191-2/+2
| |
* | Only define #positive? and #negative? on Ruby 2.2Rafael Mendonça França2015-05-191-0/+7
| | | | | | | | | | | | | | The feature was accepted and added to Ruby 2.3+ so we don't need to define it again. See https://bugs.ruby-lang.org/issues/11151
* | Move Integer#positive? and Integer#negative? query methods to Numeric classMehmet Emin İNAÇ2015-05-131-0/+19
|/ | | | By this way Integer, Rational, Float, Fixnum, Bignum classes have the same behaviour
* Remove reference to Numeric#from_now, as it is no longer supportednerdinand2015-03-231-15/+0
|
* fix dependencyJian Weihang2015-01-121-0/+2
|
* Add docs for Numeric time-related methodsclaudiob2014-12-171-0/+18
| | | | | | | Add docs for `minutes`, `hours`, `days`, `weeks` and `fortnights`. Fix docs for `in_milliseconds`. [ci skip]
* Replace `#=>` with `# =>` [ci skip]claudiob2014-12-171-7/+7
| | | | | | | | @rafaelfranca suggested in f7c7bcd9 that code examples should display the result after `# =>` and not after `#=>`. This commit replaces *all* the occurrences of `#=>` in the code documentation (mostly added by me :sob:) with the suggested `# =>`.
* Add docs for Numeric#*_bytes methodsclaudiob2014-12-171-0/+20
| | | | | | | Add docs for `kilobytes`, `megabytes`, `gigabytes`, `terabytes`, `petabytes` and `exabytes`. Fix docs for `bytes`. [ci skip]
* Prevent Numeric#to_s from allocating an arrayJean Boussier2014-11-281-9/+19
|
* :scissors: removed deprecated `Numeric#ago` and friendsGodfrey Chan2014-05-301-19/+1
| | | | | | | | | | | | | | Replacements: 5.ago => 5.seconds.ago 5.until => 5.seconds.until 5.since => 5.seconds.since 5.from_now => 5.seconds.from_now The removed tests does not affect coverage – we have equivalent test cases in the tests for `AS::Duration`. See #12389 for the history and rationale behind this.
* Deprecated Numeric#{ago,until,since,from_now}Godfrey Chan2013-11-261-0/+2
| | | | | | | | | | | | | | | | | | | | | | The user is expected to explicitly convert the value into an AS::Duration, i.e. `5.ago` => `5.seconds.ago` This will help to catch subtle bugs like: def recent?(days = 3) self.created_at >= days.ago end The above code would check if the model is created within the last 3 **seconds**. In the future, `Numeric#{ago,until,since,from_now}` should be removed completely, or throw some sort of errors to indicate there are no implicit conversion from `Numeric` to `AS::Duration`. Also fixed & refactor the test cases for Numeric#{ago,since} and AS::Duration#{ago,since}. The original test case had the assertion flipped and the purpose of the test wasn't very clear.
* Added Numeric#in_milliseconds, like 1.hour.in_milliseconds, so we can feed ↵David Heinemeier Hansson2013-11-021-0/+6
| | | | them to JavaScript functions like getTime().
* Squashed commit of the following:Aaron Patterson2013-05-031-9/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Remove unnecessary requiresRafael Mendonça França2013-01-031-2/+0
|
* Added ability to compare date/time with infinitybUg2013-01-041-0/+11
| | | | | | | | | | | | | | | | | 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.
* update some AS code examples to 1.9 hash syntax [ci skip]Francesco Rodriguez2012-09-122-67/+67
|
* Review requires from number helperCarlos Antonio da Silva2012-05-281-6/+6
| | | | | | | | Some of these requires are now only necessary in ActiveSupport::NumberHelper. Add hash/keys require due to symbolize_keys usage in number helpers. Also remove some whitespaces. Closes #6414
* Moving NumberHelpers from ActionView to ActiveSupportAndrew Mutz2012-05-271-0/+135
|
* Changes for numeric api for Time because Time.current works differentAlexey Gaziev2012-05-071-3/+3
|
* update stdlib doc urls in comments - ↵Trevor Wennblom2012-04-071-3/+3
| | | | | | active_support/core_ext/[integer|numeric]/time.rb http://stdlib.rubyonrails.org/ last updated in 2005
* add some missing requires for AS core_ext/numeric/time. Closes #1038Josh Kalderimis2011-05-181-0/+2
|