Daylight saving issue
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@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. ⬇️⬇️⬇️
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?)
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I only need to determine if X date is in DST or not for only one time zone.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Big thank you to all of you!!

- « Previous
-
- 1
- 2
- Next »
- « Previous
-
- 1
- 2
- Next »