Hi,
I'm subscribing to the monthViewDayTapped event handler which has two parameters, IGCalendarView calView and NSDate date. the date parameter is always a day ahead of the calendar day I have tapped.
I am based in the uk and working with a group of developers in the US so presume its a time zone issue although its always the next day even when my colleagues are in the same day as myself.
Any help would be greatly appreciated.
Cheers,
Matt
Hello ,
When your environment is localized for UK environment, date parameters returns you the tapped date localized with your environment current localization settings. So if you want to get the true date you should use code like:
-(BOOL)calendarView:(IGCalendarView *)calView monthViewDayTapped:(NSDate *)date { NSCalendar* calendar = [NSCalendar currentCalendar]; NSDateComponents* comps = [calendar components:NSYearCalendarUnit |NSMonthCalendarUnit | NSDayCalendarUnit fromDate:date]; NSLog(@"Value of date is %d/%d/%d", comps.month, comps.day, comps.year); return YES; }
-(BOOL)calendarView:(IGCalendarView *)calView monthViewDayTapped:(NSDate *)date
{
NSCalendar* calendar = [NSCalendar currentCalendar];
NSDateComponents* comps = [calendar components:NSYearCalendarUnit |NSMonthCalendarUnit | NSDayCalendarUnit fromDate:date];
NSLog(@"Value of date is %d/%d/%d", comps.month, comps.day, comps.year);
return YES;
}
Please let me know if you have any further questions.
Actually, Matt has got this slightly the wrong way around.
We're in the BST timezone (UTC + 1). If we tap the 4th of July, the MonthTapped event is raised in the delegate, but the date that is returned is 3rd July 23:00. Clearly the IG code is taking the tapped date (04/07/2014 00:00) and doing a ToLocalTime conversion on it (setting the time back an hour to 03/07/2014 23:00).
Tapped Date: 4th July 2014
Date in MonthViewDayTapped: 3rd July 2014 23:00
Clearly this is a defect. No matter what time zone the user is in, the Date returned by the IGGridView should always relate to the actual date tapped. If the user taps a given date, that is the date we should see in the eventing. Whilst we can manually fix it by performing our own conversion, developers should not have to do this to make use of your product. Please log a defect for this, and keep us informed on the progress of having this fixed in the product
Hello Fergal,
The IGCalendarView just creates a date using the current NSCalendar and the default locale(although this is customizable). The date created simply uses the Month, Day and year, with no time specified. Thats all that is returned, no additional modifications are made to the NSDate. If you were to simply print the description of the date in question, it would at that point localize it to the time, and since the time is 00:00:00, it could at that point change days, but again the raw date provided has no ties to a specific time zone.
The code provided to you by my colleague will always provide you will always provide you with the correct date information.
-SteveZ
No problem!
Glad we were able to clear things up.
Yep, you are right, looks like it's Xamarins fault, not IG - Apologies for getting on at you guys.
Hey Fergal,
Sure.
Here's the actual code: (translated to C#) that we're using to create the date thats passed in:
NSCalendar calendar = NSCalendar.CurrentCalendar; NSDateComponents comps = new NSDateComponents (); comps.Month = 7; comps.Day = 4; comps.Year = 2014; NSDate d = calendar.DateFromComponents (comps);
(Note the same exact problem arises)
Hmm. That seems really strange - I could understand it displaying the data wrong in intellisense somehow, but I would expect that the code would still work fine - however it is not.
Let me investigate further, see if I can replicate this in Xamarin alone (without IG components). If so, its probably their problem.
Thanks
Fergal
Actually, thats the problem you're seeing.
I just tried it out in Xamarin. The difference just appears to be the value displayed in the Watch windows. In objective-c it will display the correct date, with no time. It appears that Xamarin is displaying the description, of the date, which is a time localized version of it.
However, the date object is still in tact, and you can still get the correct date information:
NSCalendar calendar = NSCalendar.CurrentCalendar;NSDateComponents comps = calendar.Components (NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day | NSCalendarUnit.Hour, date);
In the code snippet above, i also added the Hour unit. If you take a look at it, you'll see that the hour you're actually getting is 0, which is the neutral time we're giving you.