How to read and write TimeZones from an application in C#?

We have an application in C # that works in WEC 6, and we are currently doing what is necessary to make it work 100% in WEC7. One of the things we need to solve is the reading and writing of TimeZones.

In WEC 6 we do it in the following way:

private void cmdTimezone_Click (object sender, EventArgs e)
{
        try {
              fApp.Widgets.ListPicker.show (fApp.translate ("datetime_choosetimezone"), cmdTimezone, 
              CIBRTC.GetTimeZones (), i => CIBRTC.SetTimeZone (i.Text));
               }
               catch (Exception aE) {
                          fApp.alert (aE);
               }
}

In WEC7 it does not work correctly, it can be selected once but the next time the error “Can not get TimeZone” appears, and it only disappears until the time zone is set from the BSP.

Do you have an example of what instructions do we need for this?

Dear @RamonM,

We are not expert on this topic. We just looked in WEC7 source code and found following places would be helpful for you.

\WINCE700\public\wceshellfe\oak\ctlpnl\cplmain\datetime.cpp
\WINCE700\public\wceshellfe\oak\CtlPnl2\XmlCpls\DateTime\datetimecplbase.cpp
\WINCE700\public\wceshellfe\oak\CtlPnl2\Exe\UnitTests\ctlpnl2_unittests.cpp
\WINCE700\private\servers\timesvc2\dst\dynamicdst.cpp

You need to install trial edition of WEC7 to refer those code.

Also, we found below links, it might help you.

thanks @raja.tx I will review this information,

regards

Hi @raja.tx we do not have the solution yet

We found a problem in reading and writing TimeZone in C #En este enlace esta el codigo fuente y el ejecutable de la aplicación

we create a simple application in C # that reads and writes the TimeZone, we are using the OpenNETCF library.

This is the code

using System;
using System.Drawing;
using System.Windows.Forms;
using OpenNETCF.WindowsCE;

namespace TimeZone
{     
    public partial class Form1 : Form
    {
       
        string[] husos_horarios = new string[150];
        string huso;
    
        public Form1()
        {           
            InitializeComponent();            
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Location = new Point(0,0);
           
        }

        private void Btn_Consultar_Click(object sender, EventArgs e)
        {
           
            TimeZoneCollection tzc = new TimeZoneCollection();
            tzc.Initialize();
            
            listBox1.Items.Clear();
            
            foreach (TimeZoneInformation tzi in tzc)
            {
                listBox1.Items.Add(tzi);       
            }          
            
        }


        private void Btn_Horario_Click(object sender, EventArgs e)
        {

                 
            listBox1.Items.Clear();
            
            TimeZoneInformation currentTz = new TimeZoneInformation();
            DateTimeHelper.GetTimeZoneInformation(ref currentTz);
            listBox1.Items.Add(currentTz.StandardName);

         }
        


        private void IgnoreDaylightSavingTime()
        {

            TimeZoneInformation tzi = new TimeZoneInformation();
            DateTimeHelper.GetTimeZoneInformation(ref tzi);

            // Daylight saving time should be 60

            tzi.DaylightBias = 0;

            DateTimeHelper.SetTimeZoneInformation(tzi);

            //TimeZone.Form1.listBox1.Items.Add(tzi.StandardName);

            label1.Text = tzi.DisplayName.ToString();        
           
        }
            
       
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {


            label1.Text = listBox1.SelectedItem.ToString();

        }



        private void Btn_Salir_Click(object sender, EventArgs e)
        {
            Close();

        }

        private void Btn_Set_Time_Click(object sender, EventArgs e)
        {
            /*
            if (lstZones.SelectedItem != null)
            {
                TimeZoneInformation tzi = (TimeZoneInformation)lstZones.SelectedItem;       
                DateTimeHelper.SetTimeZoneInformation(tzi);

                // this verifies that the time zone did indeed get changed
                TimeZoneInformation tz = new TimeZoneInformation((byte[])Registry.LocalMachine.OpenSubKey(“Time”).GetValue("TimeZoneInformation”));
                MessageBox.Show(“Current Timezone in Registry is:rn” 
                 + tz.StandardName, “Verified”);
            }
            */
        }

        private void label1_ParentChanged(object sender, EventArgs e)
        {

        }

       

    } // end public class
    
} //end namespace

This app gets the time zones installed in the OS, creates an arrangement to display them graphically in an interface where you can select any and set it. It also has a button to check the set time zone.
When trying to fix any time zone throws an exception.

As mentioned this code works in windows CE6 but when passing it to Windows CE7 it throws us the error “Can not get TimeZones”
Comparing the registry of WEC6 vs WEC7 I realized that there are differences in HKEY_LOCAL_MACHINE \ Time Zones. In WEC7 several Timezones does not have the TZI, Dlt and Std registrys,
which are the ones that hold the information of each time zone, unlike WEC6, where all time zones contain these registrys

For that reason, our code will not work correctly, since it is based on the reading of this registry key.
My question is there is something wrong with this registry in the OS or if the get/set of the timezone has to be done differently from WEC6?
the code we use is based on OpenNETCF https://opennetcf.com/category/compact-framework-code/page/10/

best regards
ramon mendez

@ecamacho .

Dear @RamonM,

Is it SetTimeZoneInformation not working for all timezone or only specific timezone.

There are many timezone updates on Windows Embedded Compact, Could you please try with latest Windows Embedded Compact update and let us know the result. Please refer WEC fixes list here for more timezone updates information.

Also, check our roadmap issues System time does not behave correctly when DST is not activated and Timezone can only be set once in RemoteAdmin interface it may be related to your case.

Could you please share simple native code to produce the issue on our side like this one and share with us. It will help us to find the problem easily.

Hi @raja.tx

It does not work in any TimeZone.

How can we install the WEC7 updates? Is it necessary to reflash with a new image?

Ramon Mendez

Dear @RamonM,

Thank you for the reply. Please install Windows Embedded Compact 7 and VS2008 to build a custom image using Toradex binary BSP and workspace. Yes, you need to reflash the new image.

I will look into this topic and get back to you soon. Meanwhile, If possible, could you please share a native code application, how did you do the test this.