Ruby on Rails
Monday, October 6, 2014
Of course I can. I wanted to know if this seems useful to other people using Rails so I can start to work on this feature.
On Monday, 6 October 2014 16:45:21 UTC+3, jsnark wrote:
-- On Monday, 6 October 2014 16:45:21 UTC+3, jsnark wrote:
You can extend the class yourself:
DateTime.class_eval do
define_method(:truncate_precision) { |amount|
puts amount
}
end
=> #<Proc:0x0000001fa649a0@(irb):8 (lambda)>
DateTime.now.truncate_precision(sec: 10)
{:sec=>10}
=> nil
On Monday, October 6, 2014 8:17:58 AM UTC-4, powi wrote:Hello.I thought of adding a method in ActiveSupport that would be able to truncate custom precision amounts from a `DateTime` object.For example:DateTime.now.truncate_precision(sec: 10) # => a new DateTime object minus the specified precision I've needed this in a feature of mine and thought it might be useful to others.What do you think? If we find this useful, I'd prepare a PR soon.Cheers!
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/d82184ba-92c7-4fc6-bdb7-fbe30bebeacc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment