Ask a Question

Daylight saving issue

SOLVED
leandropoblet
Frequent Contributor

Re: Daylight saving issue

Same here hahaha
Colin_McCrae
Community Hero

Re: Daylight saving issue

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
Moderator

Re: Daylight saving issue


@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. ⬇️⬇️⬇️

View solution in original post

Colin_McCrae
Community Hero

Re: Daylight saving issue

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?)

leandropoblet
Frequent Contributor

Re: Daylight saving issue

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

Re: Daylight saving issue

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: