How to set a timezone / have DST apply automaticaly?

Hello :slight_smile: !

I wonder if there would be some way to actualy set a timezone, and have the time automaticaly adjusted to DST according to the TZ.

I am syncing the time using NTP ; however, it only provides a GMT time you need to adjust yourself according to your timezone and DST. This is easy to just add or remove hours, but does not apply DST “when needed”.

Within the NETMF API reference 4.1, I was able to find:

  • The Microsoft.SPOT.TimeZoneInformation class whish provides useful information for an unknow timezone (current ?)
  • The class Microsoft.SPOT.ExentedTimeZone with a SetTimeZone property, the whole class seeming not to be implemented (any more ?)
  • The System.TimeZone static class which provides a few methods (for the current timezone, but no way to change it ?)
  • The System.TimeZoneId enum which provides a list of Timezones (where to apply them ???)
  • The Microsoft.SPOT.Time classed seeming not beeing implemented ?

So, do we have any way of doing it using a netmf of GHI functionality ?
If not, do anyone know of an external class/reference somewhere that could be use to add this whithin the code ?

Thank you very much in advance !

Have you tried adding the Microsoft.SPOT.Time library?

Hello William,

Thank you for your answer !

Actually, yes, this was tried. Unfortunately this function brings nothing : it simply defines an “Offset” in minutes from UTC. This works as well as adding/removing yourself a few hours when receiving the NTP UTC time. But does not help fixing the DST issue.

BTW the function description is incorrect in the API reference. It states “Sets the time zone of the system” : WRONG. Is sets a static offset in minutes. However a timezone is more than just a static offset : it also gives the DST changes dates for summer and winter times… Which is what I am looking for !

A timezone might be, as for an example, “AMERICA/EST” which is standardized and provide such information. Since there is an enum with this kind of information, I was expecting to find a class where it can be used… but couldn’t. Probably didn’t look at the right spot…

Any other idea ?
Thank You !

I found a simple function in pearl that I use in my logger (I’ve since converted to C )


int DLS() // Day Light Saving returns 0 for winter and 1 for summer
	{
	struct date d;  // you need to modify this
	int Indx, D1,D2;

	getdate(&d);  // and this
	if (d.da_mon == 3 || d.da_mon  == 10)
		{
		for (Indx = 1 ; Indx < 32 ; Indx ++)
			{
			if (DOW(Indx,3,d.da_year) == 0) D1 = Indx ;
			if (DOW(Indx,10,d.da_year) == 0) D2 = Indx;
			}
		if (d.da_mon == 3 && d.da_day >= D1) return 1;
		if (d.da_mon == 10 && d.da_day < D2) return 1;
		}
	if (d.da_mon > 3 && d.da_mon < 10) return 1;
	return 0;
	}

int DOW(int d,int y, int z) // Returns Day Of Week (shouldn't need this bit ) 
	{
	int Da[13] = {0,0,3,2,5,0,3,5,1,4,6,2,4};
	float T;

	T = (d + Da[y] + z + ((float)(z-1) / 4) - ((float)z/100) + ((float)z/400));

	T +=.5;
	return (int)T % 7 ;

	}

It does actually work (I’ve called it DLS rather than DST)

Cheers Ian

What! Is! With! The! Bangs!? :slight_smile:

  1. If your syncing with NTP you should be able to get offset already adjusted to a supplied TZ. There should be an NTP with this ability.

  2. Because the tables are rather large for all edge cases (and are changed), I don’t think NETMF can/will includes those because of space. If you know what TZ you are in, you should be able to build a static table for next 100 years or so. Or just have some logic that always just keeps the Next time change hot. After a flip, the logic gets/sets the next hot time and keeps a timer set or some other periodic check logic.

  3. I can’t remember, but I don’t think you can reliably use a function for DST, as there is some odd edge cases in many timezones. IIRC EST has a few.

Thank both of you, I will either work with some code like IanR provided (but only valid for Noth America), or just give up with it for now, I mean untill FEZ boards are provided with 2Mb onboard flash and NETMF in v7.0 :wink:

Cheers,
Nicolas

Cobra (EMX) has more than 2Mb:

http://www.tinyclr.com/compare/

I’ve also found the .NETMF timezone management inadequate. I’ve written my own code to deal with SNTP timesync and automatic daylight/standard transition management. I use an xml file (on SD) to define the timezone details like this:



If you’re interested in having a look at what I’ve done, let me know and I’ll post it.

I’ve also found the .NETMF timezone management inadequate. I’ve written my own code to deal with SNTP timesync and automatic daylight/standard transition management. I use an xml file (on SD) to define the timezone details like this:


<Clock>
	<TimeZone>
		<Zone Name="AUS Eastern Standard Time" />
		<Location Name="Wandana Heights, Geelong, Australia" Longtitude="144.3" Latitude="-38.17" />
		<Bias Minutes="600" />
		<Daylight>
			<Enabled Value="1" />
			<Zone Name="AUS Eastern Daylight Time" />
			<Bias Minutes="660" />
			<Start Month="10" Week="1" Hour="2" />
			<End Month="4" Week="1" Hour="3" />
		</Daylight>
	</TimeZone>
	<TimeServers>
		<Server Name="au.pool.ntp.org" />
	</TimeServers>
</Clock>

If you’re interested in having a look at what I’ve done, let me know and I’ll post it.

Yea please

Looks great :smiley: ! Can you share ?

Post it on Fezzer so everybody else will benefit.

(edit) I agree, perfect example of using Fezzer to share this code!

yeah, TZ management was dropped in NetMF 4 or 4.1; in earlier versions there seemed to be much better support:

ExtendedTimeZone.SetTimeZone(TimeZoneID.yourzone);

That function is no longer available; but the TimeZoneID’s are still floating around somewhere, not sure if they can be used elsewhere…

Code ready to go …
I’ve isolated the TimeZone managment code into a demonstration project, so I’m ready to upload it.

I’ve jumped on to Fezzer, but I get "Logging in has been disabled."
I’ll try again later.

That is because fezzer was merged with this website on Friday evening

Code posted at: [url]http://code.tinyclr.com/project/274/timezone-management-via-xml/[/url]

Thank You ! This looks great !

Any clue where we can find information to populate the XML file ?

I included a zip attachment with the code. One of the files in the zip ([italic]TimeManager.chm[/italic]) is a compiled html help document. Look at the [italic]Related Pages\Important Usage and Configuration details[/italic] entry for an explanation of some aspects of the xml contents. If you’re uncertain of specific attribute values, ask here and I’ll respond.

John

Thanks. Does this handle seemingly arbitary DST changes that fall outside a formula?

Can you provide an example of where DST changes doesn’t work to a formular. The method here assumes that the change into and outof DST will occur on a Sunday morning (the hour is configurable). The Month and Week of the transitions are configurable. Note that week 5 means the LAST week of the month, regardless of whether that is actually week 4 or week 5.

It’s worth noting that MS use the same configuration options within Windows to drive automatic time adjustments.

I’m not aware of any TimeZones where transitions are completely abitrary - managing that would require storage of the abitrary dates and associated updates over time.