[Mono-dev] TimeZoneInfo.Local on Windows

Jonathan Shore jonathan.shore at gmail.com
Mon Jan 9 08:03:31 EST 2012


Added as a bug report.   I did not have time to implement the windows part.   I did find a site indicating what needs to be done in terms of locating the local time in the registry:

http://search.cpan.org/~drolsky/DateTime-TimeZone-1.42/lib/DateTime/TimeZone/Local/Win32.pm

On another note, on unix we have timezones like "America/New_York" and on windows "Eastern Standard Time".    I understand that the later is window's standard, but in reality the prior style of specification <country>/<region> is much more correct way to indicate n that does not specify a particular timezone setting.   "Eastern Standard Time" is only applicable (as a name), given that it takes on a different name during the daylight-savings period.

It is unfortunate that MS chose the naming convention that they did.  In the interest of portability, would be keen to have a mapping of all unix like timezone names to MS names and vice-versa in the TimeZoneInfo class.

On Jan 9, 2012, at 7:28 AM, Rodrigo Kumpera wrote:

> Hi Jonathan,
> 
> Do you mind filling a bug report for this? Or, if you have a working patch for it, please do a pull request on github and I'll merge is promptly.
> 
> On Tue, Jan 3, 2012 at 9:05 PM, Jonathan Shore <jonathan.shore at gmail.com> wrote:
> 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
>> 
>> 
>> 
> 
> 
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
> 
> 

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


More information about the Mono-devel-list mailing list