Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTimeElement displays wrong date for current locale #111

Closed
johnsimons opened this issue Mar 16, 2012 · 4 comments
Closed

DateTimeElement displays wrong date for current locale #111

johnsimons opened this issue Mar 16, 2012 · 4 comments

Comments

@johnsimons
Copy link
Contributor

To reproduce this issue, set iPhone simulator settings in General | International to:
_Region Format = _Australia**

The run the Sample and go to:
Reflection API | Time Samples
As you can see the Alarm text says 6:30P even though in the code we have set it to 7:30AM.
When you click on it the picker initialises the time to 7:30AM.

Also, if you set the birthday to 29 July 1976 the application output displays:
Birthday: 28/07/1976 2:00:00 PM

@johnsimons
Copy link
Contributor Author

Done a bit more investigation and the problem is actually in the implicit conversion between NSDate and DateTime.
According to https://bugzilla.novell.com/show_bug.cgi?id=621366 this should have been fixed in MonoTouch 4.2.0, but I'm running the latest 5.3.0!

The following code replicates the problem:

var originalDate = new DateTime (1975, 7, 29);
Console.WriteLine("DateTime={0}", originalDate);
NSDate convertedToNSDate = originalDate;
Console.WriteLine("NSDate={0}", convertedToNSDate);
DateTime convertedBackToDateTime = convertedToNSDate;
Console.WriteLine("DateTime={0}", convertedBackToDateTime);

That produces the following output:

DateTime=29/07/1975 12:00:00 AM
NSDate=1975-07-28 14:00:00 +0000
DateTime=28/07/1975 2:00:00 PM

@johnsimons
Copy link
Contributor Author

Added fix in my fork:
johnsimons@58f5062

@rolfbjarne
Copy link
Collaborator

Actually the conversion is correct, you're not taking into account that the first DateTime= line has Kind=Unspecified, while the last has Kind=Utc.

I get this output if I add that information:
DateTime=7/29/1975 12:00:00 AM Kind: Unspecified
NSDate=1975-07-28 22:00:00 +0000
DateTime=7/28/1975 10:00:00 PM Kind: Utc

@rolfbjarne
Copy link
Collaborator

This has been fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants