Time.yesterday ? :)

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 ?

···

--
Spock ... Earth ..

Time.now - 86400

Kirk Haines

···

On Thursday 17 November 2005 8:57 am, Marcin Jurczuk 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 ?

Marcin Jurczuk <mj-usunto@tkb.pl> 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.

···

--
I tend to view "truly flexible" by another term: "Make everything
equally hard". -- DHH

Kirk Haines wrote:

···

On Thursday 17 November 2005 8:57 am, Marcin Jurczuk 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 Haines

:stuck_out_tongue:
I knew that is something simple - but not so simple :slight_smile:

Tha
--
Spock ... Earth ..

In article <ufypux4u2.fsf@atlmicampbell.checkfree.com>,

···

Michael Campbell <michael.campbell@gmail.com> wrote:

Marcin Jurczuk <mj-usunto@tkb.pl> 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.

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

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 :slight_smile:

Tha

proste :smiley:

lopex

Reinder Verlinde <reinder@verlinde.invalid> writes:

In article <ufypux4u2.fsf@atlmicampbell.checkfree.com>,

> Marcin Jurczuk <mj-usunto@tkb.pl> 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.

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. =)

···

Michael Campbell <michael.campbell@gmail.com> wrote:

--
I tend to view "truly flexible" by another term: "Make everything
equally hard". -- DHH

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

even shorter:

def Time.yesterday; now - 86400; end

···

--- Ursprüngliche Nachricht ---
Von: "Greg Brown" <greg7224@gmail.com>
An: ruby-talk@ruby-lang.org (ruby-talk ML)
Betreff: Re: Time.yesterday ? :slight_smile:
Datum: Fri, 18 Nov 2005 01:37:18 +0900

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

You don't need the intermediate variable

class Time
  def self.yesterday
     now - 86400
  end
end

Time.yesterday works just fine :slight_smile:

Marcin Mielżyński napisał(a):

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 :slight_smile:

Tha

proste :smiley:

lopex

like a stick :slight_smile:

Peter Ertl wrote:

def Time.yesterday; now - 86400; end

Haha very nice.

It's in Active Support:

http://as.rubyonrails.com/

Gregory Brown wrote:

···

You don't need the intermediate variable

class Time
  def self.yesterday
     now - 86400
  end
end

Time.yesterday works just fine :slight_smile:

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 10:57 AM, Gene Tani wrote:

Gregory Brown wrote:

You don't need the intermediate variable

class Time
  def self.yesterday
     now - 86400
  end
end

Time.yesterday works just fine :slight_smile:

It's in Active Support:

http://as.rubyonrails.com/

--
Eric Hodel - drbrain@segment7.net - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

Ditto. Whenever I see that sort of thing, I start to wonder
what I'm getting myself into.

Gary Wright

···

On Nov 17, 2005, at 2:13 PM, Eric Hodel 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: