# DateTime new\_offset unexpected results

**URL:** <https://rubytalk.org/t/datetime-new-offset-unexpected-results/43555>\
**Category:** ruby-talk\
**Created:** [6 January 2008 20:04 UTC](https://rubytalk.org/t/datetime-new-offset-unexpected-results/43555 "2008-01-06T20:04:07Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Greg\_Go](https://avatars.discourse-cdn.com/v4/letter/g/7ab992/32.png) [@Greg\_Go](https://rubytalk.org/u/Greg_Go)\
**Post date:** [6 January 2008 20:04 UTC](https://rubytalk.org/t/datetime-new-offset-unexpected-results/43555/1 "2008-01-06T20:04:07Z")

</div>

Hello, everybody:

I'm new to ruby, but I'm pretty sure this isn't a problem with me.

I'm running ruby 1.8.6 on Windows XP, and using NetBeans as my IDE.

My application reads the rise, transit and set times for the sun at my  
location from a spreadsheet. The spreadsheet provides the date and time  
as an astronomical julian date that I then use to create a number of  
DateTime objects.

I manually check for Daylight Savings Time by creating two more DateTime  
objects, one for DST start, the other for DST end as class variables.

I have a method that returns the local time of the event as another  
DateTime object created with DateTime's new\_offset method.

Here's the code that actually determines whether it's DST or not, and  
creates the local time object accordingly:

offset = Rational(-7,24)  
if (@jd \> @@dstStart) && (@jd \< @@dstEnd)  
&nbsp;&nbsp;&nbsp;offset = Rational(-6,24)  
end  
@ld = @jd.new\_offset(offset)

@jd is the julian date of the event.

The problem is this:  
For some events, @ld is one hour off.

Here's an example:  
@jd.to\_s #=\> 2008-03-09T13:24:59+00:00  
@ld.to\_s #=\> 2008-03-09T06:24:59-06:00

In my book, 13 - 6 = 7, not 6.

I've tried with different offset values, as well:  
@jd.to\_s #=\> 2008-03-09T13:24:59+00:00  
@ld.to\_s #=\> 2008-03-09T08:24:59-05:00 - Correct

@jd.to\_s #=\> 2008-03-09T13:24:59+00:00  
@ld.to\_s #=\> 2008-03-09T05:24:59-08:00 - Correct

So, it appears that it's only when the offset is -6.

This is only happening to some events. However, all events are instances  
the same class, with the code above.

I've used this base class to do the same thing with lunar events, with  
no problem.

This seems like a bug to me.

Any ideas as to what's going on?

Thanks for your help!  
Greg

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Todd\_Benson](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@Todd\_Benson](https://rubytalk.org/u/Todd_Benson)\
**Post date:** [7 January 2008 19:09 UTC](https://rubytalk.org/t/datetime-new-offset-unexpected-results/43555/2 "2008-01-07T19:09:16Z")

</div>

Output your dstStart and dstEnd values while you run the program  
(inside the "if" construct). That should give you some idea. I don't  
think this is a bug in the new\_offset method, but who knows? You said  
"some" events. Is it always at the same time of day? A certain time  
of year?

Todd

> **···**
>
> On Jan 6, 2008 2:04 PM, Greg Go \<plant@ultraspace.com\> wrote:
> 
> > Hello, everybody:
> > 
> > I'm new to ruby, but I'm pretty sure this isn't a problem with me.
> > 
> > I'm running ruby 1.8.6 on Windows XP, and using NetBeans as my IDE.
> > 
> > My application reads the rise, transit and set times for the sun at my  
> > location from a spreadsheet. The spreadsheet provides the date and time  
> > as an astronomical julian date that I then use to create a number of  
> > DateTime objects.
> > 
> > I manually check for Daylight Savings Time by creating two more DateTime  
> > objects, one for DST start, the other for DST end as class variables.
> > 
> > I have a method that returns the local time of the event as another  
> > DateTime object created with DateTime's new\_offset method.
> > 
> > Here's the code that actually determines whether it's DST or not, and  
> > creates the local time object accordingly:
> > 
> > offset = Rational(-7,24)  
> > if (@jd \> @@dstStart) && (@jd \< @@dstEnd)  
> > &nbsp;&nbsp;&nbsp;offset = Rational(-6,24)  
> > end  
> > @ld = @jd.new\_offset(offset)
> > 
> > @jd is the julian date of the event.
> > 
> > The problem is this:  
> > For some events, @ld is one hour off.
> > 
> > Here's an example:  
> > @jd.to\_s #=\> 2008-03-09T13:24:59+00:00  
> > @ld.to\_s #=\> 2008-03-09T06:24:59-06:00
> > 
> > In my book, 13 - 6 = 7, not 6.
> > 
> > I've tried with different offset values, as well:  
> > @jd.to\_s #=\> 2008-03-09T13:24:59+00:00  
> > @ld.to\_s #=\> 2008-03-09T08:24:59-05:00 - Correct
> > 
> > @jd.to\_s #=\> 2008-03-09T13:24:59+00:00  
> > @ld.to\_s #=\> 2008-03-09T05:24:59-08:00 - Correct
> > 
> > So, it appears that it's only when the offset is -6.
> > 
> > This is only happening to some events. However, all events are instances  
> > the same class, with the code above.
> > 
> > I've used this base class to do the same thing with lunar events, with  
> > no problem.
> > 
> > This seems like a bug to me.
> > 
> > Any ideas as to what's going on?

---

<div class="post-metadata">

**Author:** ![Greg\_Go1](https://avatars.discourse-cdn.com/v4/letter/g/f19dbf/32.png) [@Greg\_Go1](https://rubytalk.org/u/Greg_Go1)\
**Post date:** [7 January 2008 21:05 UTC](https://rubytalk.org/t/datetime-new-offset-unexpected-results/43555/3 "2008-01-07T21:05:51Z")

</div>

Todd Benson wrote:

> Output your dstStart and dstEnd values while you run the program  
> (inside the "if" construct). That should give you some idea. I don't  
> think this is a bug in the new\_offset method, but who knows? You said  
> "some" events. Is it always at the same time of day? A certain time  
> of year?

Todd:

Thanks for your reply.  
dstStart and dstEnd are class variables, and are constants representing  
the UT of DST start and end for the United States for 2008. All of my  
astronomical data are in UT, so that works out for me.

I have a container object, day, that utilizes an array to wrangle my  
event objects. The array has three event objects in it:  
0 - rise  
1 - transit  
2 - set

It's only the rise object for this invocation of the day class that  
fails, and only for DST times.

In addition, the code works well for another very simmilar application.

Referring to (and expanding a bit on) my original post (snipped from the  
event class' code):

offset = Rational(-7,24)  
if (@jd \> @@dstStart) && (@jd \< @@dstEnd)  
&nbsp;&nbsp;&nbsp;offset = Rational(-6,24)  
end  
@ld = @jd.new\_offset(offset)

@jd.to\_s #=\> 2008-03-09T13:24:59+00:00  
@ld.to\_s #=\> 2008-03-09T06:24:59-06:00  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^^^^^^  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;!!!!!!

It's my understanding that 13:24:59 offset by -6 hours should result in  
7:24:59, not 6:24:59. The @ld instance seems to be confused?

But, these seem to be ok:

offset = Rational(-7,24)  
if (@jd \> @@dstStart) && (@jd \< @@dstEnd)  
&nbsp;&nbsp;&nbsp;offset = Rational(-5,24) # Changed for debugging  
end  
@ld = @jd.new\_offset(offset)

@jd.to\_s #=\> 2008-03-09T13:24:59+00:00  
@ld.to\_s #=\> 2008-03-09T08:24:59-05:00 - Correct

offset = Rational(-7,24)  
if (@jd \> @@dstStart) && (@jd \< @@dstEnd)  
&nbsp;&nbsp;&nbsp;offset = Rational(-8,24) # Changed for debugging  
end  
@ld = @jd.new\_offset(offset)

@jd.to\_s #=\> 2008-03-09T13:24:59+00:00  
@ld.to\_s #=\> 2008-03-09T05:24:59-08:00 - Correct

Sorry about the lack of actual code -- I don't want to post my pile of  
noobish fugly code, unless I have to 😉 -- but I will if it's helpful.

Thanks!  
Greg

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Todd\_Benson](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@Todd\_Benson](https://rubytalk.org/u/Todd_Benson)\
**Post date:** [8 January 2008 08:38 UTC](https://rubytalk.org/t/datetime-new-offset-unexpected-results/43555/4 "2008-01-08T08:38:42Z")

</div>

> Todd Benson wrote:  
> \> Output your dstStart and dstEnd values while you run the program  
> \> (inside the "if" construct). That should give you some idea. I don't  
> \> think this is a bug in the new\_offset method, but who knows? You said  
> \> "some" events. Is it always at the same time of day? A certain time  
> \> of year?
> 
> Todd:
> 
> Thanks for your reply.  
> dstStart and dstEnd are class variables, and are constants representing  
> the UT of DST start and end for the United States for 2008. All of my  
> astronomical data are in UT, so that works out for me.
> 
> I have a container object, day, that utilizes an array to wrangle my  
> event objects. The array has three event objects in it:  
> 0 - rise  
> 1 - transit  
> 2 - set
> 
> It's only the rise object for this invocation of the day class that  
> fails, and only for DST times.

And only with Rational(-6, 24) during the rise event?

> In addition, the code works well for another very simmilar application.
> 
> Referring to (and expanding a bit on) my original post (snipped from the  
> event class' code):
> 
> offset = Rational(-7,24)  
> if (@jd \> @@dstStart) && (@jd \< @@dstEnd)  
> &nbsp;&nbsp;&nbsp;offset = Rational(-6,24)  
> end  
> @ld = @jd.new\_offset(offset)

Try (#'s mark the additional/changed lines)...

offset = Rational(-7, 24)  
puts "dstStart before IF: " \<\< @@dstStart ###  
puts "dstEnd before IF: " \<\< @@dstEnd ###  
if (@jd \> @@dstStart) && (@jd \< @@dstEnd)  
&nbsp;&nbsp;puts "dstStart after IF: " \<\< @@dstStart ###  
&nbsp;&nbsp;puts "dstEnd after IF: " \<\< @@dstEnd ###  
&nbsp;&nbsp;offset = Rational(-6, 24)  
end  
@ld = @jd.new\_offset(offset)

puts @jd ###  
puts @ld ###

and see what you get for the rise event (just out of curiosity).

Todd

> **···**
>
> On Jan 7, 2008 3:05 PM, Greg Go \<ruby-forum@incognitology.com\> wrote:

---

<div class="post-metadata">

**Author:** ![Dirk\_Traulsen](https://avatars.discourse-cdn.com/v4/letter/d/48db29/32.png) [@Dirk\_Traulsen](https://rubytalk.org/u/Dirk_Traulsen)\
**Post date:** [8 January 2008 10:34 UTC](https://rubytalk.org/t/datetime-new-offset-unexpected-results/43555/5 "2008-01-08T10:34:03Z")

</div>

Hi Greg!

> @jd.to\_s #=\> 2008-03-09T13:24:59+00:00  
> @ld.to\_s #=\> 2008-03-09T06:24:59-06:00  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^^^^^^  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;!!!!!!
> 
> It's my understanding that 13:24:59 offset by -6 hours should result  
> in  
> 7:24:59, not 6:24:59. The @ld instance seems to be confused?

It looks like the reason could be the error that I found:

[http://rubyforge.org/tracker/?func=detail&atid=1698&aid=14540&](http://rubyforge.org/tracker/?func=detail&atid=1698&aid=14540&)  
group\_id=426

It is a rounding error inside Numeric#divmod, which I found while  
inquiring a similar error in date. This bug was confirmed for 1.8.6 and  
is fixed (for future versions). If you compile Ruby yourself, this  
patch could fix your problem too.

Hope this helps  
Dirk

> **···**
>
> Am 8 Jan 2008 um 6:05 hat Greg Go geschrieben:

---

<div class="post-metadata">

**Author:** ![Greg\_Go1](https://avatars.discourse-cdn.com/v4/letter/g/f19dbf/32.png) [@Greg\_Go1](https://rubytalk.org/u/Greg_Go1)\
**Post date:** [10 January 2008 04:11 UTC](https://rubytalk.org/t/datetime-new-offset-unexpected-results/43555/6 "2008-01-10T04:11:23Z")

</div>

Todd Benson wrote:

> > Thanks for your reply.  
> > It's only the rise object for this invocation of the day class that  
> > fails, and only for DST times.
> 
> And only with Rational(-6, 24) during the rise event?
> 
> > @ld = @jd.new\_offset(offset)
> 
> Try (#'s mark the additional/changed lines)...
> 
> offset = Rational(-7, 24)  
> puts "dstStart before IF: " \<\< @@dstStart ###  
> puts "dstEnd before IF: " \<\< @@dstEnd ###  
> if (@jd \> @@dstStart) && (@jd \< @@dstEnd)  
> &nbsp;&nbsp;puts "dstStart after IF: " \<\< @@dstStart ###  
> &nbsp;&nbsp;puts "dstEnd after IF: " \<\< @@dstEnd ###  
> &nbsp;&nbsp;offset = Rational(-6, 24)  
> end  
> @ld = @jd.new\_offset(offset)
> 
> puts @jd ###  
> puts @ld ###
> 
> and see what you get for the rise event (just out of curiosity).
> 
> Todd

Todd:

Although I'm not sure what this proves, I did this, and the two class  
variables (@@dstStart, @@dstEnd) didn't change. I'm unclear as to where  
you're going with this -- am I missing something with the way that ruby  
handles class variables?

Thanks!  
Greg

> **···**
>
> > On Jan 7, 2008 3:05 PM, Greg Go \<ruby-forum@incognitology.com\> wrote:
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Greg\_Go1](https://avatars.discourse-cdn.com/v4/letter/g/f19dbf/32.png) [@Greg\_Go1](https://rubytalk.org/u/Greg_Go1)\
**Post date:** [10 January 2008 04:24 UTC](https://rubytalk.org/t/datetime-new-offset-unexpected-results/43555/7 "2008-01-10T04:24:39Z")

</div>

Dirk Traulsen wrote:

> Hi Greg!
> 
> > @jd.to\_s #=\> 2008-03-09T13:24:59+00:00  
> > @ld.to\_s #=\> 2008-03-09T06:24:59-06:00  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^^^^^^  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;!!!!!!
> > 
> > It's my understanding that 13:24:59 offset by -6 hours should result  
> > in  
> > 7:24:59, not 6:24:59. The @ld instance seems to be confused?
> 
> It looks like the reason could be the error that I found:
> 
> [http://rubyforge.org/tracker/?func=detail&atid=1698&aid=14540&](http://rubyforge.org/tracker/?func=detail&atid=1698&aid=14540&)  
> group\_id=426
> 
> It is a rounding error inside Numeric#divmod, which I found while  
> inquiring a similar error in date. This bug was confirmed for 1.8.6 and  
> is fixed (for future versions). If you compile Ruby yourself, this  
> patch could fix your problem too.
> 
> Hope this helps  
> Dirk

Dirk:

Building ruby myself is a little outside my comfort zone. In my opinion,  
one of the major strengths of interpreted languages is that I can avoid  
the compilation process, which I find to be tedious and difficult.

Some questions:  
Is the bug fix included in 1.9.0?

If not, is there any way at all to work around the problem? I've tried a  
number of things, but nothing seems to help.

Thanks!  
Greg

> **···**
>
> > Am 8 Jan 2008 um 6:05 hat Greg Go geschrieben:
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Todd\_Benson](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@Todd\_Benson](https://rubytalk.org/u/Todd_Benson)\
**Post date:** [10 January 2008 12:42 UTC](https://rubytalk.org/t/datetime-new-offset-unexpected-results/43555/8 "2008-01-10T12:42:36Z")

</div>

Simple. Just wanted to see if your dstStart and dstEnd vars were  
correct, and if, in fact, you were actually entering the if condition.

It's probably the bug that was mentioned, but I can't reproduce your error.

Todd

> **···**
>
> On Jan 9, 2008 10:11 PM, Greg Go \<ruby-forum@incognitology.com\> wrote:
> 
> > Todd Benson wrote:  
> > \> On Jan 7, 2008 3:05 PM, Greg Go \<ruby-forum@incognitology.com\> wrote:  
> > \>\> Thanks for your reply.  
> > \>\> It's only the rise object for this invocation of the day class that  
> > \>\> fails, and only for DST times.  
> > \>  
> > \> And only with Rational(-6, 24) during the rise event?  
> > \>  
> > \>\> @ld = @jd.new\_offset(offset)  
> > \> Try (#'s mark the additional/changed lines)...  
> > \>  
> > \> offset = Rational(-7, 24)  
> > \> puts "dstStart before IF: " \<\< @@dstStart ###  
> > \> puts "dstEnd before IF: " \<\< @@dstEnd ###  
> > \> if (@jd \> @@dstStart) && (@jd \< @@dstEnd)  
> > \> puts "dstStart after IF: " \<\< @@dstStart ###  
> > \> puts "dstEnd after IF: " \<\< @@dstEnd ###  
> > \> offset = Rational(-6, 24)  
> > \> end  
> > \> @ld = @jd.new\_offset(offset)  
> > \>  
> > \> puts @jd ###  
> > \> puts @ld ###  
> > \>  
> > \> and see what you get for the rise event (just out of curiosity).  
> > \>  
> > \> Todd
> > 
> > Todd:
> > 
> > Although I'm not sure what this proves, I did this, and the two class  
> > variables (@@dstStart, @@dstEnd) didn't change. I'm unclear as to where  
> > you're going with this -- am I missing something with the way that ruby  
> > handles class variables?

---

<div class="post-metadata">

**Author:** ![Greg\_Go1](https://avatars.discourse-cdn.com/v4/letter/g/f19dbf/32.png) [@Greg\_Go1](https://rubytalk.org/u/Greg_Go1)\
**Post date:** [10 January 2008 15:33 UTC](https://rubytalk.org/t/datetime-new-offset-unexpected-results/43555/9 "2008-01-10T15:33:33Z")

</div>

Todd Benson wrote:

> > \>  
> > \> puts @jd ###  
> > you're going with this -- am I missing something with the way that ruby  
> > handles class variables?
> 
> Simple. Just wanted to see if your dstStart and dstEnd vars were  
> correct, and if, in fact, you were actually entering the if condition.
> 
> It's probably the bug that was mentioned, but I can't reproduce your  
> error.
> 
> Todd

Todd:

Ah, I see. What I was doing to confirm that I had entered the test  
condition was changing the value of offset to, for example  
Rational(-8,24), and Rational(-5,24).

I'll see if I can work up a test case and post it, just to be complete.

Thanks!  
Greg

> **···**
>
> > On Jan 9, 2008 10:11 PM, Greg Go \<ruby-forum@incognitology.com\> wrote:
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Todd\_Benson](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@Todd\_Benson](https://rubytalk.org/u/Todd_Benson)\
**Post date:** [10 January 2008 19:53 UTC](https://rubytalk.org/t/datetime-new-offset-unexpected-results/43555/10 "2008-01-10T19:53:29Z")

</div>

> Todd Benson wrote:  
> \>\> \>  
> \>\> \> puts @jd ###  
> \>\> you're going with this -- am I missing something with the way that ruby  
> \>\> handles class variables?  
> \>  
> \> Simple. Just wanted to see if your dstStart and dstEnd vars were  
> \> correct, and if, in fact, you were actually entering the if condition.

By this last statement, I meant if you were entering the if condition  
during rise event with -6.

> \> It's probably the bug that was mentioned, but I can't reproduce your  
> \> error.  
> \>  
> \> Todd

> Ah, I see. What I was doing to confirm that I had entered the test  
> condition was changing the value of offset to, for example  
> Rational(-8,24), and Rational(-5,24).
> 
> I'll see if I can work up a test case and post it, just to be complete.

You don't have to get super crazy :-). Do whatever you think will  
help. Like I said, I don't see the same error on my system, but I  
also don't have your data (your code might have changed the class  
variables before the if statement during the "rise" event is what I  
was thinking).

Todd

> **···**
>
> On Jan 10, 2008 9:33 AM, Greg Go \<ruby-forum@incognitology.com\> wrote:
> 
> > \> On Jan 9, 2008 10:11 PM, Greg Go \<ruby-forum@incognitology.com\> wrote:

---

<div class="post-metadata">

**Author:** ![Greg\_Go1](https://avatars.discourse-cdn.com/v4/letter/g/f19dbf/32.png) [@Greg\_Go1](https://rubytalk.org/u/Greg_Go1)\
**Post date:** [11 January 2008 02:58 UTC](https://rubytalk.org/t/datetime-new-offset-unexpected-results/43555/11 "2008-01-11T02:58:15Z")

</div>

Todd Benson wrote:

> > Todd Benson wrote:  
> > \>\> \>  
> > \>\> \> puts @jd ###  
> > \>\> you're going with this -- am I missing something with the way that ruby  
> > \>\> handles class variables?  
> > \>  
> > \> Simple. Just wanted to see if your dstStart and dstEnd vars were  
> > \> correct, and if, in fact, you were actually entering the if condition.
> 
> By this last statement, I meant if you were entering the if condition  
> during rise event with -6.
> 
> > \> It's probably the bug that was mentioned, but I can't reproduce your  
> > \> error.  
> > \>  
> > \> Todd
> 
> > Ah, I see. What I was doing to confirm that I had entered the test  
> > condition was changing the value of offset to, for example  
> > Rational(-8,24), and Rational(-5,24).
> > 
> > I'll see if I can work up a test case and post it, just to be complete.
> 
> You don't have to get super crazy :-). Do whatever you think will  
> help. Like I said, I don't see the same error on my system, but I  
> also don't have your data (your code might have changed the class  
> variables before the if statement during the "rise" event is what I  
> was thinking).
> 
> Todd

Todd, et al:

This demonstrates the bug:

@ut = DateTime.new!(2454535.05902777)

# According to [http://aa.usno.navy.mil/data/docs/JulianDate.php:](http://aa.usno.navy.mil/data/docs/JulianDate.php:)  
# JD 2454535.05902 is CE 2008 March 09 13:24:59.3 UT

puts @ut.to\_s #=\> 2008-03-09T13:24:59+00:00

(4..8).each do |i|  
&nbsp;&nbsp;&nbsp;puts @ut.new\_offset(Rational(-i,24))  
end

# 2008-03-09T09:24:59-04:00  
# 2008-03-09T08:24:59-05:00  
# 2008-03-09T06:24:59-06:00 \<- Should be 2008-03-09T07:24:59-06:00  
# 2008-03-09T06:24:59-07:00  
# 2008-03-09T05:24:59-08:00

Thanks,  
Greg

> **···**
>
> > On Jan 10, 2008 9:33 AM, Greg Go \<ruby-forum@incognitology.com\> wrote:
> > 
> > > \> On Jan 9, 2008 10:11 PM, Greg Go \<ruby-forum@incognitology.com\> wrote:
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Todd\_Benson](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@Todd\_Benson](https://rubytalk.org/u/Todd_Benson)\
**Post date:** [11 January 2008 03:59 UTC](https://rubytalk.org/t/datetime-new-offset-unexpected-results/43555/12 "2008-01-11T03:59:44Z")

</div>

March 9 at (6 - 6) is when your clock changed at midnight.

Todd

> **···**
>
> On Jan 10, 2008 8:58 PM, Greg Go \<ruby-forum@incognitology.com\> wrote:
> 
> > Todd Benson wrote:  
> > \> On Jan 10, 2008 9:33 AM, Greg Go \<ruby-forum@incognitology.com\> wrote:  
> > \>\> Todd Benson wrote:  
> > \>\> \> On Jan 9, 2008 10:11 PM, Greg Go \<ruby-forum@incognitology.com\> wrote:  
> > \>\> \>\> \>  
> > \>\> \>\> \> puts @jd ###  
> > \>\> \>\> you're going with this -- am I missing something with the way that ruby  
> > \>\> \>\> handles class variables?  
> > \>\> \>  
> > \>\> \> Simple. Just wanted to see if your dstStart and dstEnd vars were  
> > \>\> \> correct, and if, in fact, you were actually entering the if condition.  
> > \>  
> > \> By this last statement, I meant if you were entering the if condition  
> > \> during rise event with -6.  
> > \>  
> > \>\> \> It's probably the bug that was mentioned, but I can't reproduce your  
> > \>\> \> error.  
> > \>\> \>  
> > \>\> \> Todd  
> > \>  
> > \>\> Ah, I see. What I was doing to confirm that I had entered the test  
> > \>\> condition was changing the value of offset to, for example  
> > \>\> Rational(-8,24), and Rational(-5,24).  
> > \>\>  
> > \>\> I'll see if I can work up a test case and post it, just to be complete.  
> > \>  
> > \> You don't have to get super crazy :-). Do whatever you think will  
> > \> help. Like I said, I don't see the same error on my system, but I  
> > \> also don't have your data (your code might have changed the class  
> > \> variables before the if statement during the "rise" event is what I  
> > \> was thinking).  
> > \>  
> > \> Todd
> > 
> > Todd, et al:
> > 
> > This demonstrates the bug:
> > 
> > @ut = DateTime.new!(2454535.05902777)
> > 
> > # According to [http://aa.usno.navy.mil/data/docs/JulianDate.php:](http://aa.usno.navy.mil/data/docs/JulianDate.php:)  
> > # JD 2454535.05902 is CE 2008 March 09 13:24:59.3 UT
> > 
> > puts @ut.to\_s #=\> 2008-03-09T13:24:59+00:00
> > 
> > (4..8).each do |i|  
> > &nbsp;&nbsp;&nbsp;puts @ut.new\_offset(Rational(-i,24))  
> > end
> > 
> > # 2008-03-09T09:24:59-04:00  
> > # 2008-03-09T08:24:59-05:00  
> > # 2008-03-09T06:24:59-06:00 \<- Should be 2008-03-09T07:24:59-06:00  
> > # 2008-03-09T06:24:59-07:00  
> > # 2008-03-09T05:24:59-08:00

---

<div class="post-metadata">

**Author:** ![Todd\_Benson](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@Todd\_Benson](https://rubytalk.org/u/Todd_Benson)\
**Post date:** [11 January 2008 04:26 UTC](https://rubytalk.org/t/datetime-new-offset-unexpected-results/43555/13 "2008-01-11T04:26:13Z")

</div>

On Jan 10, 2008 9:59 PM, Todd Benson

> March 9 at (6 - 6) is when your clock changed at midnight.
> 
> Todd

Alright ... before anyone gets a chance to call me an idiot, this  
works (in the US) ...

require 'date'  
ut = DateTime.civil( 2007, 3, 9, 13, 24 )

puts ut.to\_s

(4..8).each do |e|  
&nbsp;&nbsp;puts ut.new\_offset( Rational(-e, 24) )  
end

Todd
