Forum Discussion

leandropoblet's avatar
leandropoblet
Frequent Contributor
10 years ago

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

  • 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");
    }

     


  • 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));
  • HKosova's avatar
    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));
    • Colin_McCrae's avatar
      Colin_McCrae
      Community Hero

      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's avatar
      leandropoblet
      Frequent Contributor
      Helen that's once again exactly what I was looking for.
      Big thank you to all of you!!
  • leandropoblet's avatar
    leandropoblet
    Frequent Contributor

    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");
    }

     

    • leandropoblet's avatar
      leandropoblet
      Frequent Contributor

      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's avatar
        Colin_McCrae
        Community Hero

        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 ...