when the clock is adjusted forward, any time in the period that isskipped is invalid

P

pamela fluente

Hi friend, take the following simple code (vb or c#)

It raises the exception:

The supplied DateTime represents an invalid time. For example,
when the clock is adjusted forward, any time in the period that is
skipped is invalid.
Parameter name: dateTime

Could i have some enlightening on this? (should be related with
daylight)
And how should i modify my loop to proceed normally in the generation
of new dates avoiding the error ?


[BTW i am generating time series of random prices, this is time, the
"x" axis]


-Pam



-----------------------------------------------
Public TimeZoneInfo_LOCAL As TimeZoneInfo = TimeZoneInfo.Local
Public TimeZoneInfo_EDT As TimeZoneInfo =
TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click

Dim d As New Date(Now.Year, Now.Month, Now.Day)
Do
Dim NewDate = d.AddMinutes(-1)
Dim NewDate_EDT As Date =
TimeZoneInfo.ConvertTime(NewDate, TimeZoneInfo_EDT,
TimeZoneInfo_LOCAL)

d = NewDate
Loop

End Sub
-----------------------------------------------


-----------------------------------------------
public TimeZoneInfo TimeZoneInfo_LOCAL = TimeZoneInfo.Local;
public TimeZoneInfo TimeZoneInfo_EDT =
TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");

private void Button1_Click(System.Object sender, System.EventArgs e)
{
System.DateTime d = new System.DateTime(DateAndTime.Now.Year,
DateAndTime.Now.Month, DateAndTime.Now.Day);
do {
dynamic NewDate = d.AddMinutes(-1);
System.DateTime NewDate_EDT = TimeZoneInfo.ConvertTime(NewDate,
TimeZoneInfo_EDT, TimeZoneInfo_LOCAL);

d = NewDate;
} while (true);

}

-----------------------------------------------
 
P

pamela fluente

Or maybe it's clearer if i pose the question in a time "forward" mode:

This also gives the same error:

--------------------------

Public TimeZoneInfo_LOCAL As TimeZoneInfo = TimeZoneInfo.Local
Public TimeZoneInfo_EDT As TimeZoneInfo =
TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click


Dim d As New Date(2011, 3, 1)
Do
Dim NewDate = d.AddMinutes(1)
Dim NewDate_EDT As Date =
TimeZoneInfo.ConvertTime(NewDate, TimeZoneInfo_EDT,
TimeZoneInfo_LOCAL)

d = NewDate
Loop

End Sub

--------------------------

I am looking for a way to have the loop proceed normally generating
edt dates (a gap of 1 hour is fine, no problem).

-Pam
 
A

Arne Vajhøj

Hi friend, take the following simple code (vb or c#)

It raises the exception:

The supplied DateTime represents an invalid time. For example,
when the clock is adjusted forward, any time in the period that is
skipped is invalid.
Parameter name: dateTime

Could i have some enlightening on this? (should be related with
daylight)
And how should i modify my loop to proceed normally in the generation
of new dates avoiding the error ?

[BTW i am generating time series of random prices, this is time, the
"x" axis]

If your app is to be able to handle DST changes, then you should
use UTC time internally and only convert to local time in display.

Arne
 
P

pamela fluente

Hi friend, take the following simple code (vb or c#)
It raises the exception:
     The supplied DateTime represents an invalid time.  For example,
when the clock is adjusted forward, any time in the period that is
skipped is invalid.
Parameter name: dateTime
Could i have some enlightening on this?  (should be related with
daylight)
And how should i modify my loop to proceed normally in the generation
of new dates avoiding the error ?
[BTW i am generating time series of random prices, this is time, the
"x" axis]

If your app is to be able to handle DST changes, then you should
use UTC time internally and only convert to local time in display.

Arne

Yes. It' seemed just more convenient for me to deal with real dates
because these are real prices.
After all i need only 2 version of dates: LOCAL and EDT when i display
it.
If possible i'd like just to find an easy way to skip the hour. It's
right after all: these are prices randomly generated.

-Pam
 
P

pamela fluente

[...]
If possible i'd like just to find an easy way to skip the hour. It's
right after all: these are prices randomly generated.

There is an easy way: use UTC time internally and only convert to local
time in display.

Hopefully, that advice sounds familiar to you.  :)

BTW, if you're going to post code in the C# newsgroup, it would be best
if you would make sure that code is C# code.  If you want help with
VB.NET code, there's a different forum for that.

Pete

thanks.

(c# and vb.net are the same to me.)

-Pam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top