[Mono-dev] TimeZoneInfo.Local on Windows

Jonathan Shore jonathan.shore at gmail.com
Tue Jan 3 18:02:21 EST 2012


So I have a mono application which works fine on OSX and Linux that uses System.TimeZoneInfo.Local, amongst other TimeZoneInfo facilities.

On windows calling TimeZoneInfo.Local throws a TimeZoneNotFoundException.

Looking at the class library code in "mcs/class/System.Core/System/TimeZoneInfo.cs" it is clear why this will throw an exception:

public static TimeZoneInfo Local {
	get { 
		if (local == null) {
#if MONODROID
			local = ZoneInfoDB.Default;
#elif MONOTOUCH
			using (Stream stream = GetMonoTouchDefault ()) {
				return BuildFromStream ("Local", stream);
			}
#elif LIBC
			try {
				local = FindSystemTimeZoneByFileName ("Local", "/etc/localtime");	
			} catch {
				try {
					local = FindSystemTimeZoneByFileName ("Local", Path.Combine (TimeZoneDirectory, "localtime"));				} catch {
					throw new TimeZoneNotFoundException ();
				}
			}
#else
			throw new TimeZoneNotFoundException ();
#endif
		}
		return local;
	}
}

I noticed that there is windows specific code to find the time zone info in the registry for FindSystemTimeZoneById().  Is there not a setting in the registry which indicates which of these timezones is local?

The code looks broken for windows, proper on unix variants, and covered on Andriod and iOS.

Any pointers / comments on a fix or workaround for this?

Jonathan



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20120103/06dfb4c0/attachment-0001.html 


More information about the Mono-devel-list mailing list