[Mono-dev] TimeZoneInfo.Local on Windows

Jonathan Shore jonathan.shore at gmail.com
Tue Jan 3 18:05:47 EST 2012


I should also mention that this in an embedded application (so I cannot use the MS VM).  I have tried running this as a pure C# test app just to make sure is not a problem with my embedding.  Hence, need to either fix or avoid using this part of the API.

On Jan 3, 2012, at 6:02 PM, Jonathan Shore wrote:

> 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/ec85c27c/attachment-0001.html 


More information about the Mono-devel-list mailing list