Hello group.
Is there any simple method to get Time object like Time.now but with
yesterday date, without worrying about end of month or begining new one
?
Hello group.
Is there any simple method to get Time object like Time.now but with
yesterday date, without worrying about end of month or begining new one
?
On Thursday 17 November 2005 8:57 am, Marcin J. wrote:
Hello group.
Is there any simple method to get Time object like Time.now but with
yesterday date, without worrying about end of month or begining new one ?
Time.now - 86400
Kirk H.
Kirk H. wrote:
On Thursday 17 November 2005 8:57 am, Marcin J. wrote:
Hello group.
Is there any simple method to get Time object like Time.now but with
yesterday date, without worrying about end of month or begining new one ?Time.now - 86400
Kirk H.
I knew that is something simple - but not so simple
Tha
greg@oracle ~ $ irb
irb(main):001:0> Time.now
=> Thu Nov 17 11:38:02 EST 2005
irb(main):002:0> class Time
irb(main):003:1> def self.yesterday
irb(main):004:2> now - 86400
irb(main):005:2> end
irb(main):006:1> end
=> nil
irb(main):007:0> Time.yesterday
=> Wed Nov 16 11:38:27 EST 2005
class Time
def Time.yesterday
t=Time.now
Time.at(t.to_i-86400)
end
end
p Time.yesterday
I knew that is something simple - but not so simple
Tha
proste
lopex
even shorter:
def Time.yesterday; now - 86400; end
You don’t need the intermediate variable
class Time
def self.yesterday
now - 86400
end
end
Time.yesterday works just fine
Peter E. wrote:
def Time.yesterday; now - 86400; end
Haha very nice.
Marcin MielżyÅ?ski napisaÅ?(a):
Tha
proste
lopex
like a stick
On Nov 17, 2005, at 10:57 AM, Gene T. wrote:
It’s in Active Support:
No, Time.yesterday is not in active_support, Time#yesterday is.
Also, active_support emits far, far, far too many warnings. I could
maybe deal with 1 or two warnings, but not 169:
$ cat yesterday.rb
#!/usr/local/bin/ruby -w
require ‘rubygems’
require ‘active_support’
p Time.yesterday
$ ruby yesterday.rb
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/
active_support/class_inheritable_attributes.rb:116: warning:
discarding old inherited
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/
active_support/inflections.rb:2: warning: ambiguous first argument;
put parentheses or even spaces
[snip 167 lines of warnings]
yesterday.rb:6: undefined method `yesterday’ for Time:Class
(NoMethodError)
On Nov 17, 2005, at 2:13 PM, Eric H. wrote:
No, Time.yesterday is not in active_support, Time#yesterday is.
Also, active_support emits far, far, far too many warnings. I
could maybe deal with 1 or two warnings, but not 169:
Ditto. Whenever I see that sort of thing, I start to wonder
what I’m getting myself into.
Gary W.
Marcin J. [email protected] writes:
Hello group.
Is there any simple method to get Time object like Time.now but with
yesterday date, without worrying about end of month or begining new one ?
Pedantic to be sure, but keep in mind all the variations on the
“… - 86400” scheme universally fail during the Daylight Savings
Time cutovers that some of us are unfortunate to have to suffer.
Probably this won’t affect you.
In article [email protected],
Michael C. [email protected] wrote:
Probably this won’t affect you.
Even more pedantic: even if it does not, the assumption that every day
has 86400 seconds is still incorrect. A day with a leap second has 86401
or 86399 (has not happened yet) seconds.
Reinder
Well… if a time wasn’t essential, and a Date could be used instead:
require ‘date’
Date.today - 1
By the way, for anyone playing with date/time functions, date also will
increment/decrement months:
Date.today >> 1 # Adds a month
Date.today << 1 # Subtracts a month
Might be handy,
.adam
Reinder V. [email protected] writes:
Pedantic to be sure, but keep in mind all the variations on the
“… - 86400” scheme universally fail during the Daylight Savings
Time cutovers that some of us are unfortunate to have to suffer.Probably this won’t affect you.
Even more pedantic: even if it does not, the assumption that every
day has 86400 seconds is still incorrect. A day with a leap second
has 86401 or 86399 (has not happened yet) seconds.
Chuckle I completely forgot about that too; good catch. =)
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs