Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Time: safe way to go to next day?

Reply
Thread Tools

Time: safe way to go to next day?

 
 
Emmanuel Touzery
Guest
Posts: n/a
 
      10-21-2003
Hello,

When i have a Time object, to get to next day i do: myTime += (60*60*24)
Not very elegant, but it works and I didn't find a nicer way.
well, i thought it worked...

now we are going to change the time in europe...
So it breaks my assumption...

any proper way to fix it?

emmanuel

irb(main):008:0> now = Time.now
Tue Oct 21 08:14:44 Central Europe Daylight Time 2003
irb(main):009:0> todayMidnight = Time.local(now.year, now.month,
now.day, 0,0,0)
Tue Oct 21 00:00:00 Central Europe Daylight Time 2003 # today at 0:00

irb(main):010:0> todayMidnight + (60*60*24)
Wed Oct 22 00:00:00 Central Europe Daylight Time 2003 # tomorrow at 0:00

[..]

irb(main):014:0> todayMidnight + (60*60*24)*5
Sun Oct 26 00:00:00 Central Europe Daylight Time 2003 # sun at 0:00
irb(main):015:0> todayMidnight + (60*60*24)*6
Sun Oct 26 23:00:00 Central Europe Standard Time 2003 # <----------
!!!! sun at 23:00



 
Reply With Quote
 
 
 
 
nobu.nokada@softhome.net
Guest
Posts: n/a
 
      10-21-2003
Hi,

At Tue, 21 Oct 2003 15:16:44 +0900,
Emmanuel Touzery wrote:
> When i have a Time object, to get to next day i do: myTime += (60*60*24)
> Not very elegant, but it works and I didn't find a nicer way.
> well, i thought it worked...
>
> now we are going to change the time in europe...
> So it breaks my assumption...


If you just want dates, what about date.rb?

require 'date'
today = Date.today
today.to_s # => "2003-10-21"
(today+5).to_s # => "2003-10-26"

I've not tested it with DST though.

--
Nobu Nakada

 
Reply With Quote
 
 
 
 
Emmanuel Touzery
Guest
Posts: n/a
 
      10-21-2003
Hello,

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

>If you just want dates, what about date.rb?
>
> require 'date'
> today = Date.today
> today.to_s # => "2003-10-21"
> (today+5).to_s # => "2003-10-26"
>
>I've not tested it with DST though.
>
>
>

but where is all this stuff documented?
find.rb, base64.rb, date.rb, the other day someone wanted to remove
recursively a dir, and was given another one of those magic files...
which doc did i miss? :O(

otherwise, yes it's probably what i want. unfortunately i now sit on a
lot of code to convert :O(
if someone has a way with Time, it would simplify things for me...

thanks,

emmanuel



 
Reply With Quote
 
Sabby and Tabby
Guest
Posts: n/a
 
      10-21-2003
Emmanuel Touzery <(E-Mail Removed)> wrote:

> (E-Mail Removed) wrote:
>
> >If you just want dates, what about date.rb?
> >
> > require 'date'
> > today = Date.today
> > today.to_s # => "2003-10-21"
> > (today+5).to_s # => "2003-10-26"
> >
> >I've not tested it with DST though.

>
> otherwise, yes it's probably what i want. unfortunately i now sit on a
> lot of code to convert :O(
> if someone has a way with Time, it would simplify things for me...


Here's half a solution:

class Time
require 'date'
DAY = 60*60*24

alias add +
def +(s)
return add(s) unless s % DAY == 0
d = Date.new(year, mon, day) + s / DAY
Time.local(d.year, d.mon, d.day, hour, min, sec, usec)
end
end
 
Reply With Quote
 
gabriele renzi
Guest
Posts: n/a
 
      10-21-2003
il Tue, 21 Oct 2003 16:19:48 +0900, Emmanuel Touzery
<(E-Mail Removed)> ha scritto::


>but where is all this stuff documented?
>find.rb, base64.rb, date.rb, the other day someone wanted to remove
>recursively a dir, and was given another one of those magic files...
>which doc did i miss? :O(
>


some is in the pickaxe.
Some you may just found looking at ruby-dir/lib, for the classes like
Array or String there is ri.

You may like to look at rj (as in 'ri'.succ) wich works like ri but
incorporates some more stuff (see on rubyforge).

ruby-doc.org has ri++ wich is 'ri + documentation via web' . Quite
useful too

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading of file by next of map file and by next of file descriptor. =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki C++ 1 07-10-2007 02:46 AM
Perl 5.00404 - Label not found for "next " , next() function Liora Perl Misc 5 01-12-2007 03:36 AM
Next (the other next) Gen "DVD" storage Alan Browne Digital Photography 13 05-31-2005 05:53 PM
CurrentElement->next = CurrentElement->next->next (UNDEFINED?) Deniz Bahar C Programming 2 03-09-2005 12:45 AM
Skipping content in Array within loop and go to the next (of NEXT function) Tad McClellan Perl Misc 3 05-13-2004 10:14 PM



Advertisments