The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Dates Don't Always Add Up

2 replies on 1 page. Most recent reply: Oct 28, 2008 7:32 PM by Amos King

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Amos King

Posts: 78
Nickname: adkron
Registered: Jan, 2007

Amos King is a Web Developer for the US Postal Service and for Ramped Media.
Dates Don't Always Add Up Posted: Oct 28, 2008 5:13 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Amos King.
Original Post: Dates Don't Always Add Up
Feed Title: DirtyInformation
Feed URL: http://feeds.feedburner.com/Dirtyinformation
Feed Description: Information about Ruby/Rails/JRuby/WebDevelpoment/whatever.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Amos King
Latest Posts From DirtyInformation

Advertisement

I don't even know what to say about this? Anyone know why this happens?

>> Date.today -1
=> Sat, 25 Oct 2008
>> Date.today - 1
=> Fri, 24 Oct 2008
>> Date.today
=> Sat, 25 Oct 2008

Read: Dates Don't Always Add Up


Coty Rosenblath

Posts: 1
Nickname: coty
Registered: Oct, 2008

Re: Dates Don't Always Add Up Posted: Oct 28, 2008 9:41 AM
Reply to this message Reply
> <p>
> I don't even know what to say about this? Anyone know why
> this happens?
> </p>
> <pre>
> >> Date.today -1
> => Sat, 25 Oct 2008

Here you are calling Date.today with -1 as the first parameter. (Check the doc., it takes an optional parameter.) You could have equivalently written Date.today(-1). That parameter doesn't do anything relevant in this case (In fact, I'm not clear on its function.), so you get today's date.

> >> Date.today - 1
> => Fri, 24 Oct 2008

Here you are subtracting 1 from today, so you get yesterday.

> >> Date.today
> => Sat, 25 Oct 2008

No surprise here.

> </pre>

Amos King

Posts: 78
Nickname: adkron
Registered: Jan, 2007

Re: Dates Don't Always Add Up Posted: Oct 28, 2008 7:32 PM
Reply to this message Reply
I figured it out, but for a while this through me for a loop. I was completely perplexed

Flat View: This topic has 2 replies on 1 page
Topic: Little Known Ways to Ruby Mastery by Chris O'Sullivan Previous Topic   Next Topic Topic: Wide Finder 2: processing 42GB of httpd logs, 300X faster than naïve Ruby

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use