Ask a Question related to Ruby, Design and Development.
-
Emmanuel Touzery #1
Time: safe way to go to next day?
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
Emmanuel Touzery Guest
-
CFMX7.0.1 Administrator date time issue showing 13hrsbehind server time
I am running a W2k SP4 box that has been upgraded from CFMX6 to CFMX7.0.1. The CFMX7.0.1 server is showing the date on the Server Settings >... -
SAFE MODE
Hi Bill, Hit F8 at boot to access the boot options. -- Best of Luck, Rick Rogers aka "Nutcase" MS-MVP - Win9x... -
Formatting a time field to 24 hour time (Military time) in the Datagrid
Anyone know how to do this? -
$SAFE = 5 and Safe Ruby Misleading?
Hey folks. With all this talk of duck typing and such, I got to thinking about some of my code that I *thought* executed untrusted code... -
Can't log in to Safe Mode
Thanks, I'll give that a try! Michael "Rick "Nutcase" Rogers" <rick@mvps.org> wrote in message news:%23RJyfWjPDHA.1584@TK2MSFTNGP11.phx.gbl...... -
nobu.nokada@softhome.net #2
Re: Time: safe way to go to next day?
Hi,
At Tue, 21 Oct 2003 15:16:44 +0900,
Emmanuel Touzery wrote:If you just want dates, what about date.rb?> 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...
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
nobu.nokada@softhome.net Guest
-
Emmanuel Touzery #3
Re: Time: safe way to go to next day?
Hello,
[email]nobu.nokada@softhome.net[/email] wrote:
but where is all this stuff documented?>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.
>
>
>
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
Emmanuel Touzery Guest
-
Dalibor Sramek #4
Re: Time: safe way to go to next day?
Quoting Emmanuel Touzery <emmanuel.touzery@wanadoo.fr>:
If you need just the date part you may probably ignore timezone as well. Use> 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...
UTC:
irb(main):027:0> ary = Time.now
=> Tue Oct 21 09:45:14 Central Europe Daylight Time 2003
irb(main):028:0> t = Time.gm(*ary)
=> Tue Oct 21 09:45:14 UTC 2003
irb(main):029:0> t += 7 * 86400
=> Tue Oct 28 09:45:14 UTC 2003
irb(main):030:0>
Regards,
Dalibor Sramek
--
Dalibor Sramek [url]http://www.insula.cz/dali[/url] | In the eyes of cats,
[email]dalibor.sramek@insula.cz[/email] | all things belong to cats.
Dalibor Sramek Guest
-
Dalibor Sramek #5
Re: Time: safe way to go to next day?
Quoting Emmanuel Touzery <emmanuel.touzery@wanadoo.fr>:
Ruby has:> 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(
a, built-in classes (e.g. Array, String, Time etc.)
b, standard library (organized in files and modules - e.g. date.rb)
Pickaxe has a chapter on the standard library and another one on the network
library. Unfortunately it is not complete (and situation became worse with
1.8). Anyway browsing Ruby directory is a good learning exercise.
Dalibor
--
Dalibor Sramek [url]http://www.insula.cz/dali[/url] | In the eyes of cats,
[email]dalibor.sramek@insula.cz[/email] | all things belong to cats.
Dalibor Sramek Guest
-
Sabby and Tabby #6
Re: Time: safe way to go to next day?
Emmanuel Touzery <emmanuel.touzery@wanadoo.fr> wrote:
Here's half a solution:> [email]nobu.nokada@softhome.net[/email] 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...
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
Sabby and Tabby Guest
-
Mark J. Reed #7
Re: Time: safe way to go to next day?
Given a Time representing the instant you care about, you
can get the time N days later by just adding N days' worth
of seconds. Here's a simple method definition:
class Time
SECONDS_PER_DAY = 86_400
def add_days(n)
self + n * SECONDS_PER_DAY
end
end
No Date required.
irb(main):001:0> t = Time.now
=> Tue Oct 21 13:15:03 EDT 2003
irb(main):002:0> t.add_days(5)
=> Sun Oct 26 12:15:03 EST 2003
-Mark
Mark J. Reed Guest
-
gabriele renzi #8
Re: Time: safe way to go to next day?
il Tue, 21 Oct 2003 16:19:48 +0900, Emmanuel Touzery
<emmanuel.touzery@wanadoo.fr> ha scritto::
some is in the pickaxe.>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 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 ;)
gabriele renzi Guest



Reply With Quote

