# Time: safe way to go to next day?

**URL:** <https://rubytalk.org/t/time-safe-way-to-go-to-next-day/8582>\
**Category:** ruby-talk\
**Created:** [21 October 2003 06:16 UTC](https://rubytalk.org/t/time-safe-way-to-go-to-next-day/8582 "2003-10-21T06:16:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emmanuel\_Touzery](https://avatars.discourse-cdn.com/v4/letter/e/e274bd/32.png) [@Emmanuel\_Touzery](https://rubytalk.org/u/Emmanuel_Touzery)\
**Post date:** [21 October 2003 06:16 UTC](https://rubytalk.org/t/time-safe-way-to-go-to-next-day/8582/1 "2003-10-21T06:16:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [21 October 2003 07:13 UTC](https://rubytalk.org/t/time-safe-way-to-go-to-next-day/8582/2 "2003-10-21T07:13:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Emmanuel\_Touzery](https://avatars.discourse-cdn.com/v4/letter/e/e274bd/32.png) [@Emmanuel\_Touzery](https://rubytalk.org/u/Emmanuel_Touzery)\
**Post date:** [21 October 2003 07:19 UTC](https://rubytalk.org/t/time-safe-way-to-go-to-next-day/8582/3 "2003-10-21T07:19:48Z")

</div>

Hello,

> 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

> **···**
>
> [nobu.nokada@softhome.net](mailto:nobu.nokada@softhome.net) wrote:

---

<div class="post-metadata">

**Author:** ![Dalibor\_Sramek1](https://avatars.discourse-cdn.com/v4/letter/d/50afbb/32.png) [@Dalibor\_Sramek1](https://rubytalk.org/u/Dalibor_Sramek1)\
**Post date:** [21 October 2003 07:46 UTC](https://rubytalk.org/t/time-safe-way-to-go-to-next-day/8582/4 "2003-10-21T07:46:35Z")

</div>

Quoting Emmanuel Touzery [emmanuel.touzery@wanadoo.fr](mailto:emmanuel.touzery@wanadoo.fr):

> 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…

If you need just the date part you may probably ignore timezone as well. Use  
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 [insula.cz](http://www.insula.cz/dali) | In the eyes of cats,  
> dalibor.sramek@insula.cz | all things belong to cats.
