# TzInfo and DST and UTC to Easter convert help

**URL:** <https://www.ruby-forum.com/t/tzinfo-and-dst-and-utc-to-easter-convert-help/225997>\
**Category:** Rails\
**Created:** [March 9, 2008, 2:08pm UTC](https://www.ruby-forum.com/t/tzinfo-and-dst-and-utc-to-easter-convert-help/225997 "2008-03-09T14:08:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [March 9, 2008, 2:08pm UTC](https://www.ruby-forum.com/t/tzinfo-and-dst-and-utc-to-easter-convert-help/225997/1 "2008-03-09T14:08:15Z")

</div>

We created a calendar on ruby on rails using the TzInfo add-in. The  
users set a timezone in their preference and all dates/times are saved  
to the DB in UTC. This worked great up until March 8/9 for Eastern  
because of the DST change and we moved ahead one hour. Therefore, if  
an entry saved to the db for 8:40am Eastern it was put in the system  
as 5 hours ahead. However, it has now changed to 4 hours ahead and  
all new entries saved for this time period are off. If an event  
started on the 7th of March and went to the 10th of March, everything  
prior to DST is fine but everything else is off by an hour. How do I  
compensate for this extra hour? I am sure it will be fine in a few  
weeks when UTC reflect their DST. I am running TzInf v0.3.6, RoR  
2.0.2 and gems 1.0.1.

Is there a difference between UTC and GMT?

# 

* * *

private  
def setdatetoutc(enddateyn)  
if @appointment.StartTime!=nil and @appointment.StartTime.to\_s!=’’  
@tempsdated=Time.parse(@appointment.StartDate.to\_s)  
@tempsdatet=Time.parse(@appointment.StartTime.to\_s)  
@tempsdate=Time.local(@tempsdated.to\_date.strftime(’%Y’),  
@tempsdated.to\_date.strftime(’%m’), @tempsdated.strftime(’%d’),  
@tempsdatet.strftime("%H"), @tempsdatet.strftime("%M"),  
@tempsdatet.strftime("%S"))

end

if @appointment.EndTime!=nil and @appointment.EndTime.to\_s!=’’

@tempedated=Time.parse(@appointment.StartDate.to\_s)  
@tempedatet=Time.parse(@appointment.EndTime.to\_s)  
@tempedate=Time.local(@tempedated.strftime(’%Y’),  
@tempedated.strftime(’%m’), @tempedated.strftime(’%d’),  
@tempedatet.strftime("%H"), @tempedatet.strftime("%M"),  
@tempedatet.strftime("%S"))  
end

if enddateyn==‘y’  
if @appointment.EndDate!=nil and @appointment.EndDate.to\_s!=’’  
@tempaedated=Time.parse(@appointment.EndDate.to\_s)  
@tempaedatet=Time.parse(@appointment.EndTime.to\_s)  
@tempaedate=Time.local(@tempaedated.strftime(’%Y’),  
@tempaedated.strftime(’%m’), @tempaedated.strftime(’%d’),  
@tempaedatet.strftime("%H"), @tempaedatet.strftime("%M"),  
@tempaedatet.strftime("%S"))  
end  
end

if @tempsdate.to\_s!=""  
@appointment.StartDate=@tz.local\_to\_utc(@tempsdate)  
@appointment.StartTime=@tz.local\_to\_utc(@tempsdate)  
end

if @tempedate.to\_s!=""  
@appointment.TZEndDate=@tz.local\_to\_utc(@tempedate)  
@appointment.EndTime=@tz.local\_to\_utc(@tempedate)  
end

if @tempaedate.to\_s!=""  
@appointment.EndDate=@tz.local\_to\_utc(@tempaedate)  
end

end

# 

* * *

private  
def setdatetolocal(enddateyn)

if @appointment.StartTime!=nil and @appointment.StartTime.to\_s!=’’

@tempsdated=Time.parse(@appointment.StartDate.to\_s)  
@tempsdatet=Time.parse(@appointment.StartTime.to\_s)  
@tempsdate=Time.local(@tempsdated.to\_date.strftime(’%Y’),  
@tempsdated.to\_date.strftime(’%m’), @tempsdated.strftime(’%d’),  
@tempsdatet.strftime("%H"), @tempsdatet.strftime("%M"),  
@tempsdatet.strftime("%S"))

end

if @appointment.EndTime!=nil and @appointment.EndTime.to\_s!=’’  
@tempedated=Time.parse(@appointment.StartDate.to\_s)  
@tempedatet=Time.parse(@appointment.EndTime.to\_s)  
@tempedate=Time.local(@tempedated.strftime(’%Y’),  
@tempedated.strftime(’%m’), @tempedated.strftime(’%d’),  
@tempedatet.strftime("%H"), @tempedatet.strftime("%M"),  
@tempedatet.strftime("%S"))

end

if enddateyn==‘y’  
if @appointment.EndDate!=nil and @appointment.EndDate.to\_s!=’’  
@tempaedated=Time.parse(@appointment.EndDate.to\_s)  
@tempaedatet=Time.parse(@appointment.EndTime.to\_s)  
@tempaedate=Time.local(@tempaedated.strftime(’%Y’),  
@tempaedated.strftime(’%m’), @tempaedated.strftime(’%d’),  
@tempaedatet.strftime("%H"), @tempaedatet.strftime("%M"),  
@tempaedatet.strftime("%S"))

end  
end

if @tempsdate.to\_s!=""  
@appointment.StartDate=@tz.utc\_to\_local(@tempsdate)  
@appointment.StartTime=@tz.utc\_to\_local(@tempsdate)  
end

if @tempedate.to\_s!=""  
@appointment.TZEndDate=@tz.utc\_to\_local(@tempedate)  
@appointment.EndTime=@tz.utc\_to\_local(@tempedate)  
end

if @tempaedate.to\_s!=""  
@appointment.EndDate=@tz.utc\_to\_local(@tempaedate)  
end

end

# 

* * *

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [March 9, 2008, 2:32pm UTC](https://www.ruby-forum.com/t/tzinfo-and-dst-and-utc-to-easter-convert-help/225997/2 "2008-03-09T14:32:30Z")

</div>

On 9 Mar 2008, at 13:07, David wrote:

> compensate for this extra hour? I am sure it will be fine in a few  
> weeks when UTC reflect their DST. I am running TzInf v0.3.6, RoR  
> 2.0.2 and gems 1.0.1.
> 
> Is there a difference between UTC and GMT?  
> Technically yes, in practical senses no. If you care about things like  
> leap seconds being added because the rotation of the earth is slowing,  
> then yes.

> @tempsdated.to\_date.strftime(’%m’), @tempsdated.strftime(’%d’),  
> @tempsdatet.strftime("%H"), @tempsdatet.strftime("%M"),  
> @tempsdatet.strftime("%S"))

What timezone is your server using? That will affect the result of  
these calls of Time.local an strftime  
Also I can’t help but think that this all looks very complicated.

Fred

> end

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [March 9, 2008, 2:45pm UTC](https://www.ruby-forum.com/t/tzinfo-and-dst-and-utc-to-easter-convert-help/225997/3 "2008-03-09T14:45:26Z")

</div>

The server is using UTC. This works fine up until the date of DST  
switchover. Then it all goes haywire.
