Ask a Question

Daylight saving issue

SOLVED
leandropoblet
Frequent Contributor

Daylight saving issue

Hi all!

 

Just a question regarding daylight saving and the time difference between UTC and local time.

 

Every time we have to add (or substract) one hour because of that it causes the test's run to stop becuase it finds there's an 'error' on the date/time displayed in the application.

 

The question is if there's any function in C# script similar to 

bool isDaylight = TimeZoneInfo.Local.IsDaylightSavingTime(thisTime);

in C# that can be used on TestComplete scripts to determine if I should be happy with the date/time retreived from the DB (stored in UTC, of course) or I should add/substract one hour.

 

As you can see in the second file attached the daylight saving day changes every year, so it's rather annoying to build a custom function that needs to be updated every year.

 

Cheers,

Leandro

15 REPLIES 15

Same here hahaha

Ah right.

 

So you want to verify that a datestamp in DB is correct? So if DST was applicable to it, you would expect the DST adjustment to be applied to the stored time? And you have a UTC stamp, and offset (Time Zone info) to work with?

 

So what you really need is some way of pulling back DST ranges. So you can determine if DST should have been applied.

 

Do you need that for ALL time zones or just your local one?

 

I have some tests where I have to alter the system date time through script. BUT .... I also have to revert it back once the test is complete. Given that I have no simple way of knowing the elapsed time since I altered the system time (without resorting to stored times and background stopwatches ... which all seemed awfully fiddly), I decided it would be easier to use a free online service that has an API which will give me the current local time.

 

I ended up using: http://www.geonames.org/

 

Who provide a free API for just such data. As long as you don't plan on making, like, a million calls a day!

 

Good chance they may have Zone specific DST dates in there somewhere if you have a rake about?

HKosova
SmartBear Alumni (Retired)


@leandropoblet wrote:

 

The question is if there's any function in C# script similar to 

bool isDaylight = TimeZoneInfo.Local.IsDaylightSavingTime(thisTime);

You can access .NET classes via the dotNET object, so the TestComplete version of this code would be:

var thisTime = dotNET.System.DateTime.zctor_6(2010, 1, 10, 0, 0, 0, dotNET.System.DateTimeKind.Utc);
var isDaylight = dotNET.System.TimeZoneInfo.Local.IsDaylightSavingTime(thisTime));

Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

Nice.

 

Much easier than faffing with online API's!

 

(I didn't have much choice for reverting back to the current/correct local time .... unless @HKosova has another nifty .NET shortcut up her sleeve?)

Yes Colin that's exactly what I need now (as requirements changed since original post)
I only need to determine if X date is in DST or not for only one time zone.
leandropoblet
Frequent Contributor

Helen that's once again exactly what I was looking for.
Big thank you to all of you!!
cancel
Showing results for 
Search instead for 
Did you mean: