johnvuko / JTCalendar

A customizable calendar view for iOS.
MIT License
2.76k stars 534 forks source link

Date selected is showing wrong #345

Closed saikirannani123 closed 7 years ago

saikirannani123 commented 7 years ago

I have tried your sample code. when i click on a date in month calendar it is showing the previous day. for ex if i click on 23 In NSLog it is showing as 22. I have tried one of the previous issue . In this if i use NSDate formatter dayView.date is showing right but the date selected is showing the previous day. How to solve this?

johnvuko commented 7 years ago

Can you show me what is in dayView.date in the method didTouchDayView with:

The main problem is coming from the timezone. Maybe you have to set a locale or a timezone to your dateformatter.

saikirannani123 commented 7 years ago

'start_Date = dayView.date;

end_Date=dayView.date;

_dateSelected=dayView.date;

 NSLog(@"date selected is %@",_dateSelected);

NSDateFormatter *dateFormatter = [_calendarManager.dateHelper

createDateFormatter];

dateFormatter.dateFormat = @"yyyy'-'MM'-'dd' 'HH':'mm':'ss";

NSLog(@"%@", [dateFormatter stringFromDate:_dateSelected]);

NSLog(@"daview.date is %@",_dateSelected);

// Animation for the circleView

dayView.circleView.transform = CGAffineTransformScale(

CGAffineTransformIdentity, 0.1, 0.1);

[UIView transitionWithView:dayView

                  duration:.3

                   options:0

                animations:^{

                    dayView.circleView.transform =

CGAffineTransformIdentity;

                    [_calendarManager reload];

                } completion:nil];

// Don't change page in week mode because block the selection of days

in first and last weeks of the month

if(_calendarManager.settings.weekModeEnabled)

{

    return;

}

// Load the previous or next page if touch a day from another month

if(![_calendarManager.dateHelper date:_calendarContentView.date

isTheSameMonthThan:dayView.date])

{

    // NSLog(@"%@",dayView.date);

    if([_calendarContentView.date compare:dayView.date] ==

NSOrderedAscending)

    {

        [_calendarContentView loadNextPageWithAnimation];

    }

    else

    {

        [_calendarContentView loadPreviousPageWithAnimation];

    }

}

eventsArray=[[NSMutableArray alloc]init];

[self fetchAllevent];

' This is the code that i have written in didtouch dayview. if i keep dateformatter the date selected is showing correct. if i keep just nslog the date selected is showing the previous day.

But in both cases I cant fetch the events correctly.

For Ex. there are 4 events in 24 date but when i selected 24 it is showing 2 3 4 events of 24 and when i click on 23rd date is is showing 1 2 events of 24 date

On Thu, Aug 17, 2017 at 3:46 AM, Jonathan Tribouharet < notifications@github.com> wrote:

Can you show me what is in dayView.date in the method didTouchDayView with:

  • a simple NSLog / print
  • with a dateformatter

The main problem is coming from the timezone. Maybe you have to set a locale or a timezone to your dateformatter.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jonathantribouharet/JTCalendar/issues/345#issuecomment-322915070, or mute the thread https://github.com/notifications/unsubscribe-auth/AaAKQShBrU5C_9-Qm_3PS0PHY-5IsVHOks5sY2pTgaJpZM4O4dks .

johnvuko commented 7 years ago

I just rewrite your code with styling:

start_Date = dayView.date;
end_Date=dayView.date;
_dateSelected=dayView.date;
NSLog(@"date selected is %@",_dateSelected);

NSDateFormatter *dateFormatter = [_calendarManager.dateHelper createDateFormatter];
dateFormatter.dateFormat = @"yyyy'-'MM'-'dd' 'HH':'mm':'ss";
NSLog(@"%@", [dateFormatter stringFromDate:_dateSelected]);
NSLog(@"daview.date is %@",_dateSelected);

// Animation for the circleView
dayView.circleView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.1, 0.1);
[UIView transitionWithView:dayView
  duration:.3
  options:0
  animations:^{
    dayView.circleView.transform =
    CGAffineTransformIdentity;
    [_calendarManager reload];
} completion:nil];

// Don't change page in week mode because block the selection of days in first and last weeks of the month
if(_calendarManager.settings.weekModeEnabled){
    return;
}

// Load the previous or next page if touch a day from another month
if(![_calendarManager.dateHelper date:_calendarContentView.date isTheSameMonthThan:dayView.date]) {
    // NSLog(@"%@",dayView.date);
    if([_calendarContentView.date compare:dayView.date] == NSOrderedAscending){
        [_calendarContentView loadNextPageWithAnimation];
    }
    else{
        [_calendarContentView loadPreviousPageWithAnimation];
    }
}

eventsArray = [[NSMutableArray alloc] init];
[self fetchAllevent];

If the dateformatter is correct, so the problem is coming from your fetchAllevent method or from your prepareDayView method.

saikirannani123 commented 7 years ago

What if the dateformatter is wrong. How to change it?