What are the units for the time zone on SystemTime.SetTime

SystemTime.SetTime has a variant that looks like this (and a number of other routines that also take int timeZoneOffset) :

public static void SetTime(DateTime utcTime, int timeZoneOffset);

What are the units for timeZoneOffset? hours, minutes, seconds, mS?

Perhaps ticks ?

good question! I am curious if we even handle it properly as I have never used it!

Ah this is a very interesting topic.

There will need to be a way to easily update the Time Zone list in TinyCLR. (If it exists.) Time zones change quite frequently. Mainly because of Daylight Savings start and end dates.

Of all the issues I have had to deal with when working with cloud services and data logging, time zones have been the most difficult. Servers are UTC, devices and users can be anywhere in the world.

Yeah, I use UTC everywhere internally in code and on the wire, but local time zones are just for display to humans. That said, it wasn’t apparent how to use these API entry points.

Should this take minutes?

Yes, as far as i know it’s in minutes.
I tried to port the “FixedTimeService” for NETMF posted by @eolson in GHI Codeshare in 2013 to TinyCLR
-https://github.com/RoSchmi/TimeService_TinyCLR_Example
from the code there I think that it is in minutes

Sorry I kind of hijacked this post, my post regarding time zones doesn’t help answer the original question asked.

To answer my own question, looking at TinyCLR there appears to be no list of time zones. Looking at old NETMF code I had to create my own timezone list. I would assume TinyCLR 2 will be the same

Yes, as some countries are to 15 min differences. Eg, Australia has some strange ones.

https://www.timeanddate.com/time/zone/australia

1 Like

Oh wow!! I have learned something new today

just a note. there’s only a handful of people in the Eucla district, so if you didn’t have their TZ there’s probably not many people who would be angry with you :slight_smile:

3 Likes

The value is in ticks but then this does not allow for negative numbers easily. We will change to minutes or something else in preview 5.

1 Like

Why do you now think, that the unit is in ticks?
For me it stays to be in minutes!

In times of corona I took some time to play with time.

        Debug.WriteLine("\r\nWhen TinyCLR is started, DateTime(UtcNow) and DateTime.Now are as follows:\r\n");
        Debug.WriteLine("DateTime.UtcNow is: " + DateTime.UtcNow);                 //Result: 01/01/2017 00:00:01
        Debug.WriteLine("DateTime.Now is:    " + DateTime.Now + "\r\n\r\n");       //Result: 01/01/2017 00:00:01


        Debug.WriteLine("As you can see, DateTime.Now and DateTime.UtcNow give the same result as TinyCLR doesn't know in which timeZone you are.\r\n");

        
        Debug.WriteLine("Now we set SystemTime with the first variant: SystemTime.SetTime(DateTime utcTime) to some day, 10 o clock.\r\n");
        Debug.WriteLine("SystemTime.SetTime(new DateTime(2020, 04, 04, 10, 00, 00));\r\n");

        SystemTime.SetTime(new DateTime(2020, 04, 04, 10, 00, 00));

        Debug.WriteLine("DateTime.UtcNow is: " + DateTime.UtcNow);                 //Result: 04/04/2020 10:00:00
        Debug.WriteLine("DateTime.Now is:    " + DateTime.Now + "\r\n\r\n");       //Result: 04/04/2020 10:00:00

        Debug.WriteLine("As you can see, DateTime.Now and DateTime.UtcNow give the same result as TinyCLR doesn't know in which timeZone you are.\r\n");

        Debug.WriteLine("Now we set SystemTime with the second variant: SystemTime.SetTime(DateTime utcTime, 60) to some day, 10 o clock.\r\n" +
            "and take a timeOffset of 60 in unit minutes for the timeZoneOffset of Germany (+60)");
        Debug.WriteLine("SystemTime.SetTime(new DateTime(2020, 04, 04, 10, 00, 00), 60);\r\n");

        SystemTime.SetTime(new DateTime(2020, 04, 04, 10, 00, 00), 60);

        Debug.WriteLine("DateTime.UtcNow is: " + DateTime.UtcNow);                 //Result: 04/04/2020 10:00:00
        Debug.WriteLine("DateTime.Now is:    " + DateTime.Now + "\r\n\r\n");       //Result: 04/04/2020 11:00:00

        Debug.WriteLine("As you can see, now DateTime.Now gives the correct local time and  DateTime.UtcNow gives the correct utc time.\r\n");

        Debug.WriteLine("Consideration of  DayLightSavingTime in another thing.");
3 Likes

Wish I could press “like” more than once. Thanks for digging into that!

1 Like

Did you verify that a negative also number works?

@Mike Good point, yes, negative numbers work as well. If the offset exceeds the limits of the current day (see example), DateTime.Now gives the time of a day that yet nowhere exists.

SystemTime.SetTime(new DateTime(2020, 04, 04, 10, 00, 00), 16 * 60);

DateTime.UtcNow is: 04/04/2020 10:00:00
DateTime.Now is: 04/05/2020 02:00:00

Should it better throw an exception?

3 Likes

The code showed that this is in ticks but maybe it gets converted somewhere internally. We will be testing on our end as well and document the formal answer. Anyway you have proven is is minutes!