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

2 ACCEPTED SOLUTIONS

Accepted Solutions
leandropoblet
Frequent Contributor

Re: Daylight saving issue

I just receive this from support and it's quite useful. Thanks guys!

 

 

function DST()
{
  var key, valueName, i;

  key = Storages["Registry"]("System\\CurrentControlSet\\Control\\TimeZoneInformation", HKEY_LOCAL_MACHINE, 0, true);

  ActiveTimeBias = key["GetOption"]("ActiveTimeBias", "");
  Bias = key["GetOption"]("Bias", "");
 
  if (ActiveTimeBias == Bias)
    Log.Message("DST is inactive");
  else
    Log.Message("DST is active");
}

 

View solution in original post

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

15 REPLIES 15
leandropoblet
Frequent Contributor

Re: Daylight saving issue

I just receive this from support and it's quite useful. Thanks guys!

 

 

function DST()
{
  var key, valueName, i;

  key = Storages["Registry"]("System\\CurrentControlSet\\Control\\TimeZoneInformation", HKEY_LOCAL_MACHINE, 0, true);

  ActiveTimeBias = key["GetOption"]("ActiveTimeBias", "");
  Bias = key["GetOption"]("Bias", "");
 
  if (ActiveTimeBias == Bias)
    Log.Message("DST is inactive");
  else
    Log.Message("DST is active");
}

 

View solution in original post

leandropoblet
Frequent Contributor

Re: Daylight saving issue

Hey so this function is no longer valid for some reason.

 

I migrated TC to a Windows 2008 computer so that might be the reason.

 

Any ideas on how to change it so it works again?

Colin_McCrae
Community Hero

Re: Daylight saving issue

What's failing? Have you stepped through the function to see if it's picking up a value at all?

 

From what I can see, that reg key should still be valid on a Win Server 2008 install?

 

(assume you mean Win Server 2008 when you say Windows 2008?)

 

Other thing that springs to mind is that Server installs tend to be a little more "protective" than desktop ones. So maybe it's a rights issue for reading the registry via script or something? I'm not familiar enough with Server installs to say for sure ...

leandropoblet
Frequent Contributor

Re: Daylight saving issue

 

Hi Colin,

 

It's failing as it's always falling into "DST is inactive" and you'll see in the attachment it is active.

 

Does it change when the PC is in a domain? As it might be updating date and time from there maybe?

Colin_McCrae
Community Hero

Re: Daylight saving issue

Works OK for me? (But I'm on a Win7 Pro x64 VM)

 

Two questions ...

 

1. Did you search the registry for the key and check the path? Mine was slightly different. Mine was located at:

 

Storages["Registry"]("SYSTEM\\ControlSet001\\Control\\TimeZoneInformation", HKEY_LOCAL_MACHINE, 1, true)

 

So "CurrentControlSet" was changed to "ControlSet001" for me.

 

2. Is the Server 2008 box 32 or 64 bit? The third parameter in the call specifies the architecture. 64 bit machine for me so changed to 1. (Set to 0 in the example)

joseph_michaud
Moderator

Re: Daylight saving issue

DST is currently not active in Auckland.  It starts up again on Sep 25.

 

http://www.timeanddate.com/worldclock/new-zealand/auckland

 

 

-----
Joseph
leandropoblet
Frequent Contributor

Re: Daylight saving issue

Hahaha that confirms then we've got a bug here in our product.

Very helpful thank you!

 

I'm going to answer some questions anyways for the sake of having the information here in one post.

 

Colin:

1. Yes I did search in registry but I didn't realized the change to "ControlSet001"

 

2. The third parameter doesn't seem to change anything here.

 

Joseph:

I was totally convinced it was detecting if DST is enabled in the OS or not... not the actual value

 

 

Thanks again!

Colin_McCrae
Community Hero

Re: Daylight saving issue

Ha ha! 

 

I never thought to check the time zone in you image. Assumed you were getting a wrong result! Smiley LOL

leandropoblet
Frequent Contributor

Re: Daylight saving issue

Hi Colin,

 

I just realised it wasn't a bug at all, it wasn't a problem in that function at all it's a logical problem (and we might need a different post after all)

 

The situation is this: I'm retrieving a date/time value from the DB, getting local time against UCT time and calculating the time difference (usually 12 or 13 hours here in Auckland depending on DST as discussed earlier).

 

So far so good but the problem is I need to determine if that date in the DB is inside the DST (13 hs difference) or not (12 hours difference)

 

So for example: 

A. Date in DB is in DST:       10/01/2010 00:00 UTC 

                                                It's in DST, so local time for that date is: 10/01/2010 13:00 

 

B. Date in DB is NOT in DST:       10/06/2010 00:00 UTC 

                                                         It's NOT in DST, so local time for that date is: 10/06/2010 12:00 

 

Does it make sense?

So in order to determine if date is 12 or 13 difference with local time I need to determine somehow if the date itself is in DST and if we're now in DST (or not)

 

 

 

cancel
Showing results for 
Search instead for 
Did you mean: