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

calendarCurrentPageDidChange not showing correct Date #246

Closed
lynchjbrendan opened this issue Mar 30, 2016 · 4 comments
Closed

calendarCurrentPageDidChange not showing correct Date #246

lynchjbrendan opened this issue Mar 30, 2016 · 4 comments

Comments

@lynchjbrendan
Copy link

Hi all,

I've been messing with the calendar and have come across an issue in calendarCurrentPageDidChange not showing the correct Date. Here is an example. Today is 30th March 2016. so it shows March 2016 on launch. I am printing the calendar.currentPage variable here:

calendarCurrentPageDidChange: 2016-02-01 00:00:00 +0000 <-scroll to Feb from March
calendarCurrentPageDidChange: 2016-03-01 00:00:00 +0000 <- scroll back to March from Feb
calendarCurrentPageDidChange: 2016-03-31 23:00:00 +0000 <- now scroll to April!?! (is currently displaying April on screen)

Also at this point, if i select a date, it is wrong by one day. in didSelectDate, I selected 20th April. this is what shows:
(Date Selected: 2016-04-19 23:00:00 +0000)

Am i overlooking something here or is this actually unusual behaviour? Thanks!

I am using Swift 2.2, Xcode 7.3. iphone 6 with ios 9.3. I have tested in objective C using your example project, it doesn't seem to be an issue there at all

@lynchjbrendan lynchjbrendan changed the title calendarCurrentMonthDidChange not showing correct Date calendarCurrentPageDidChange not showing correct Date Mar 30, 2016
@lynchjbrendan
Copy link
Author

I think this is something to do with the timezone hour change difference in March/October. It shows -1 hour from April to September, then corrects itself at November again.

Correction, problem is also in Objective C, in your DelegateAppearanceViewController. I added

  • (void)calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date
    {
    NSLog(@"didSelectDate: %@", date);
    }

-(void)calendarCurrentPageDidChange:(FSCalendar *)calendar{
NSLog(@"calendarCurrentPageDidChange: %@", calendar.currentPage);
}

The results:

2016-03-30 17:36:22.108 FSCalendarExample[1799:1247730] calendarCurrentPageDidChange: 2015-08-31 23:00:00 +0000
2016-03-30 17:36:28.244 FSCalendarExample[1799:1247730] calendarCurrentPageDidChange: 2015-09-30 23:00:00 +0000
2016-03-30 17:36:28.759 FSCalendarExample[1799:1247730] calendarCurrentPageDidChange: 2015-11-01 00:00:00 +0000
2016-03-30 17:36:29.244 FSCalendarExample[1799:1247730] calendarCurrentPageDidChange: 2015-12-01 00:00:00 +0000
2016-03-30 17:36:29.676 FSCalendarExample[1799:1247730] calendarCurrentPageDidChange: 2016-01-01 00:00:00 +0000
2016-03-30 17:36:30.013 FSCalendarExample[1799:1247730] calendarCurrentPageDidChange: 2016-02-01 00:00:00 +0000

@WenchaoD
Copy link
Owner

@lynchjbrendan The example doesn't print NSDate object directly, it prints [calendar stringFromDate:date];

@lynchjbrendan
Copy link
Author

@WenchaoD , Thanks for the prompt reply. Thanks! :)

I was getting confused that it wasn't printing in UTC. If anyone else comes across this and is confused, you can see the date in UTC by using this the following:

func getDateAsStringInUTC(date: NSDate) -> String{
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss ZZZ"
let UTCTimeAsString = dateFormatter.stringFromDate(date)
return UTCTimeAsString
}

func calendar(calendar: FSCalendar, didSelectDate date: NSDate) {
print(getDateAsStringInUTC(date))
}

func calendarCurrentPageDidChange(calendar: FSCalendar) {
print(getDateAsStringInUTC(calendar.currentPage))
}

@WenchaoD
Copy link
Owner

Actually, you can just use

[calendar stringFromDate:date format:@"yyyy-MM-dd HH:mm:ss ZZZ"];

But still thanks.

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

3 participants
@WenchaoD @lynchjbrendan and others