aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/duration.rb
Commit message (Collapse)AuthorAgeFilesLines
* [skip ci] Update documentation for Duration#to_sAnton Davydov2015-05-251-0/+4
|
* Add documentation for Duration#to_i for clarificationnerdinand2015-03-231-0/+24
|
* Removing :en in favor of I18n.default_locale in duration#inspectDominik Masur2015-01-121-1/+1
| | | | | | | | | | | | | | | | | Hi there, i have an app without english as available locale. So i got an error when we try to inspect something like 1.day. This is done automatically when we use the dalli cache. I would like to change the :en to ::I18n.default_locale to be sure that this is always constant and is an available locale. Tests are all green with this change. Calculating ------------------------------------- :locale => :en 2.024k i/100ms :locale => ::I18n.default_locale 2.236k i/100ms ------------------------------------------------- :locale => :en 25.758k (±26.3%) i/s - 117.392k :locale => ::I18n.default_locale 26.311k (±18.1%) i/s - 127.452k
* Remove workaround to a Ruby 2.0.0 bugRafael Mendonça França2015-01-041-7/+0
|
* Fix syntax error with RDoc directive,Zachary Scott2014-12-201-1/+1
| | | | this should be `:nodoc:` in order to be parsed.
* Merge pull request #17493 from petewest/duration-comparableAaron Patterson2014-11-071-0/+2
|\ | | | | Delegate comparison operator to value
| * Delegate comparison operator to valuePeter West2014-11-031-0/+2
| |
* | Removed the unused require of proxy_object and test related to itPrathamesh Sonpatki2014-11-051-1/+0
|/ | | | | - Reference : https://github.com/rails/rails/pull/17493#issuecomment-61739359 - Duration stopped inheriting from ProxyObject in https://github.com/rails/rails/pull/16574
* define hash on durationlsylvester2014-10-031-0/+4
|
* Merge pull request #11794 from yoazt/duration-eqlRafael Mendonça França2014-09-171-1/+3
|\ | | | | | | | | | | | | | | | | Added method `#eql?` to `ActiveSupport::Duration`, in addition to `#==`. Conflicts: activesupport/CHANGELOG.md activesupport/lib/active_support/duration.rb activesupport/test/core_ext/duration_test.rb
| * Added method `#eql?` to `ActiveSupport::Duration`, in addition to `#==`.Joost Lubach2013-08-071-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | Currently, the following returns `false`, contrary to expectation: 1.minute.eql?(1.minute) Adding method `#eql?` will make this behave like expected. Method `#eql?` is just a bit stricter than `#==`, as it checks whether the argument is also a uration. Their parts may be different though. 1.minute.eql?(60.seconds) # => true 1.minute.eql?(60) # => false
* | add implementation of respond_to? for ActiveSupport::Durationlsylvester2014-09-151-1/+9
| |
* | Follow-up to #16560Robin Dupret2014-08-241-2/+2
| | | | | | | | | | | | | | For the sake of backward-compatibility, we need to make #instance_of? return true for Fixnum. On the other hand, the method should still give true for ActiveSupport::Duration itself which was not the case before.
* | Define the Duration#instance_of? methodRobin Dupret2014-08-181-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | Since Duration is extending from ProxyObject which extends itself from BasicObject, the Duration object doesn't respond to the #instance_of? method. Thus, the #method_missing hook get triggered, delegating the method to its `value` attribute. However, Rubinius' #eql? definition relies on #instance_of?, thus this will equal to true with a Fixnum (since its `value` attribute is a Fixnum) while it should not. The previous behavior was wrong anyway, no matter the implementation.
* | [ci skip] Remove Duration#=== when we drop support for 2.0.0-p353Akshay Vishnoi2014-05-231-2/+1
| |
* | Fixed problem where `1.day.eql?(1.day)` is falseEmily Dobervich2014-04-081-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes: 1.second.eql?(1.second) #=> false The new `eql?` requires that `other` is an `ActiveSupport::Duration`. This requirement makes `ActiveSupport::Duration`'s behavior consistent with other numeric types in Ruby. 1.eql?(1.0) #=> false 1.0.eql?(1) #=> false 1.second.eql?(1) #=> false (was true) 1.eql?(1.second) #=> false { 1 => "foo", 1.0 => "bar" } #=> { 1 => "foo", 1.0 => "bar" } { 1 => "foo", 1.second => "bar" } # now => { 1 => "foo", 1.second => "bar" } # was => { 1 => "bar" } And though the behavior here hasn't changed, for reference: 1 == 1.0 #=> true 1.0 == 1 #=> true 1 == 1.second #=> true 1.second == 1 #=> true
* | Fix segmentation fault in Ruby 2.0.0-p353.Dmitriy Kiriyenko2013-11-301-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | In Ruby 2.0.0-p353 there was a [commit](https://github.com/ruby/ruby/commit/66915c507777c5e3a978fa73de25db763efd9206) that switched case matching from actual sending `===` method to magic lookup, that does not see it in `method_missing`. It's hard to predict how exactly and when exactly this bug will be solved so here I suggest a solution of defining it in Duration directly. In Ruby 2.0.0-p353 without the added fix added test crashes to segmentation fault.
* | Revert "Merge pull request #12480 from iwiznia/master"Jeremy Kemper2013-10-111-20/+0
| | | | | | | | | | This reverts commit e5f5a838b96a362534d9bb60d02334439ed9784c, reversing changes made to d7567f3290a50952494e9213556a1f283a6cf3a0.
* | flatten and flatten! methods for ActiveSupport::DurationIonatan Wiznia2013-10-111-0/+20
| |
* | Reduce Duration#inspect to a single series of transformationsDavid Chelimsky2013-09-111-6/+4
| | | | | | | | | | | | | | | | | | | | | | * eliminates need for temp Hash Also added a couple of examples to DurationTest to specify: * duration can be defined with units out of order e.g. 1.month + 1.year + 1.second + 1.day * equality with a Fixnum works regardless of which operand is on which side of the operator
* | Refactor Duration#inspectDavid Chelimsky2013-08-121-7/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In preparing https://github.com/rails/rails/pull/11855, it took me a minute to understand what was going on due to naming (parts refers first to an attr_accessor, then to a local, and is then reassigned), but also because the iterator conditionally builds nulls and then removes them. I refactored to something much more functional-looking that I find easier to read, but you may or may not. If you do, great! Enjoy! If not, oh well, I tried. Can't win 'em all :) Rationale: * no name conflict between local var and attr_accessor * no reassignment of local var * algorithm spelled out in steps * unused items in initial list filtered out early * empty-list case handled early instead of reassigning local var * no duplication of formatting strings ("0 seconds") Benchmarks (after PR #11855 merged): 10000.times do 1.second.inspect end original #inspect 0.350000 0.000000 0.350000 ( 0.354709) 0.330000 0.000000 0.330000 ( 0.331885) 0.330000 0.000000 0.330000 ( 0.334441) refactored #inspect 0.340000 0.000000 0.340000 ( 0.340080) 0.340000 0.010000 0.350000 ( 0.345069) 0.330000 0.000000 0.330000 ( 0.335873) 10000.times do (1.day + 1.month + 2.minutes + 1.day).inspect end original #inspect 0.400000 0.000000 0.400000 ( 0.403027) 0.400000 0.000000 0.400000 ( 0.403781) 0.390000 0.000000 0.390000 ( 0.387596) refactored #inspect 0.400000 0.010000 0.410000 ( 0.399792) 0.400000 0.000000 0.400000 ( 0.404145) 0.400000 0.000000 0.400000 ( 0.403820)
* | Use chop instead of singularize in Duration#inspectDavid Chelimsky2013-08-121-1/+1
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Even though singularize tells a better story, chop is more than 50% faster and is all that is necessary in the case of Duration#inspect, in which all of the candidates for chopping appear in the same method and are all singularized by removing the final 's'. Benchmarks: 10000.times do 1.second.inspect end original #inspect 0.740000 0.000000 0.740000 ( 0.739065) 0.740000 0.000000 0.740000 ( 0.741458) 0.740000 0.010000 0.750000 ( 0.744011) refactored #inspect 0.330000 0.000000 0.330000 ( 0.333390) 0.330000 0.000000 0.330000 ( 0.331013) 0.320000 0.000000 0.320000 ( 0.330103) 10000.times do (1.day + 1.month + 2.minutes + 1.day).inspect end original #inspect 0.790000 0.000000 0.790000 ( 0.794624) 0.770000 0.000000 0.770000 ( 0.774577) 0.770000 0.010000 0.780000 ( 0.771295) refactored #inspect 0.390000 0.000000 0.390000 ( 0.392921) 0.400000 0.000000 0.400000 ( 0.397412) 0.370000 0.000000 0.370000 ( 0.379660)
* Rename ActiveSupport::BasicObject to ActiveSupport::ProxyObjectFrancesco Rodriguez2012-12-071-2/+2
| | | | | AS::BasicObject is used for proxy classes. Let's give it a less concerning name. Also, it avoids the confusion with Ruby's Basic Object.
* update AS docs [ci skip]Francesco Rodriguez2012-09-171-3/+3
|
* let ruby decompose the tuples in the iteratorAaron Patterson2012-08-061-1/+1
|
* removing unnecessary 'examples' noise from activesupportFrancesco Rodriguez2012-05-131-1/+0
|
* ruby 1.8 ActiveSupport BasicObject no longer availableVishnu Atrai2011-12-301-1/+0
|
* Fix AS::Duration#duplicable? on 1.8thedarkone2011-05-211-0/+1
|
* Fix Duration#to_jsonPratik Naik2010-12-291-0/+4
|
* Make ActiveSupport::Duration#method_missing delegate blocks to value [#5498 ↵Krekoten' Marjan2010-09-011-1/+1
| | | | | | state:resolved] Signed-off-by: José Valim <jose.valim@gmail.com>
* Deletes trailing whitespaces (over text files only find * -type f -exec sed ↵Santiago Pastorino2010-08-141-1/+1
| | | | 's/[ \t]*$//' -i {} \;)
* making comments sentence more conciseNeeraj Singh2010-07-231-2/+2
|
* 1.day should respond_to kind_of tooNeeraj Singh2010-05-211-0/+1
| | | | | | [#4656 state:resolved] Signed-off-by: José Valim <jose.valim@gmail.com>
* Qualify constant lookup in BasicObjectJeremy Kemper2010-01-071-1/+1
|
* Remove unneeded reliance on super -> method_missing quirkJeremy Kemper2010-01-071-2/+4
|
* duration.rb needs active_support/core_ext/object/acts_likeXavier Noria2010-01-011-0/+1
|
* make #inspect if zero length duration return '0 seconds' instead of empty ↵Levin Alexander2009-07-021-2/+4
| | | | | | string [#2838 state:resolved] Signed-off-by: Yehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>
* Fix dependencies revealed by testing in isolationJeremy Kemper2009-04-221-0/+1
|
* Force all internal calls to Array#to_sentence to use English [#2010 ↵David Heinemeier Hansson2009-02-271-1/+1
| | | | state:resolved]
* Duration requires BasicObject in case it's autoloaded earlyJeremy Kemper2008-11-231-0/+2
|
* Duration #since and #ago with no argument (e.g., 5.days.ago) return ↵gbuesing2008-04-201-3/+3
| | | | TimeWithZone when config.time_zone is set. Introducing Time.current, which returns Time.zone.now if config.time_zone is set, otherwise just returns Time.now
* Ruby 1.9 compat: add #raise to AS::BasicObject, fixup Duration argument ↵Jeremy Kemper2008-01-021-1/+1
| | | | | | error. Closes #10594. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8523 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
* Revert const_missing bypass in favor of Duration constant lookup tweakJeremy Kemper2007-12-151-1/+1
| | | | git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8412 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
* Ruby 1.9 compat: define Duration#== [chuyeow]Jeremy Kemper2007-12-151-25/+35
| | | | git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8399 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
* Introduce BasicObject as Builder::BlankSlate for Ruby 1.9 forward compatibility.Jeremy Kemper2007-10-071-2/+2
| | | | git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7762 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
* Add Date#since, ago, beginning_of_day, and end_of_day. Date + seconds works ↵Jeremy Kemper2007-06-041-4/+1
| | | | | | now. Closes #8575. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6937 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
* Time durations use since instead of + for accuracy. Closes #8513.Jeremy Kemper2007-05-301-1/+1
| | | | git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6901 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
* Added test coverage for Inflector.inflections.clear. Closes #7179. [Rich ↵Rick Olson2007-01-231-1/+1
| | | | | | Collins]. Remove unused code from Duration#inspect. Closes #7180. [Rich Collins] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6022 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
* change Duration to use the new Object#acts_like? helper to do duck typingJamis Buck2007-01-151-2/+2
| | | | git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5952 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
* Make sure Duration uses duck-typing instead of explicit classes, so apps can ↵Jamis Buck2007-01-151-3/+4
| | | | | | pass proxy objects around and have it all "just work" git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5948 5ecf4fe2-1ee6-0310-87b1-e25e094e27de