This project is archived and is in readonly mode.
If 1.year = 365.25.days, then 1.month should be equal to 30.4375.days
-
Rohit Arondekar
- State changed from new to invalid
- Importance changed from to Low
These are convenience methods. The API docs explain how the should be used:
# These methods use Time#advance for precise date calculations when using from_now, ago, etc. # as well as adding or subtracting their results from a Time object. For example: # # # equivalent to Time.now.advance(:months => 1) # 1.month.from_nowAnd also how not to use them:
# While these methods provide precise calculation when used as in the examples above, care # should be taken to note that this is not true if the result of `months', `years', etc is # converted before use: # # # equivalent to 30.days.to_i.from_now # 1.month.to_i.from_nowAnd also suggest what to use for precision arithmetic:
# In such cases, Ruby's core # Date[http://stdlib.rubyonrails.org/libdoc/date/rdoc/index.html] and # Time[http://stdlib.rubyonrails.org/libdoc/time/rdoc/index.html] should be used for precision # date and time arithmeticMost importantly they behave as expected. :)
If you can provide a good reason as to why this change needs to be done I'll reopen the ticket.
-
Jose Luis Duran
Ok. Will do.
It's just:
if 1.year.to_i != 12.months.to_i puts "something must be wrong!" endThank you.
-
Rohit Arondekar
# While these methods provide precise calculation when used as in the examples above, care # should be taken to note that this is not true if the result of `months', `years', etc is # converted before use: -
Jose Luis Duran
OK got it. Sorry!
require 'timecop' Timecop.freeze(Time.now) if 1.year.ago == 12.months.ago puts "Everything is OK!" end