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

Wrong times attached to dates after update to 6.0.5 #222

Closed
deniszhukov opened this issue Dec 8, 2016 · 7 comments
Closed

Wrong times attached to dates after update to 6.0.5 #222

deniszhukov opened this issue Dec 8, 2016 · 7 comments

Comments

@deniszhukov
Copy link

Hi Jay,
After updating from 6.0.2 to 6.0.5 I started getting wrong time in dates.
I think that this is connected to this issue
#210

I'm using calendar in UTC in configureCalendar method.

Before I was getting UTC dates with midnight time, which I think is the expected behavior.
Now, didSelectDate returns date with 7:00 UTC time.

I noticed that error because I had logic that was bound to differences between dates, which got broken, because of time difference.

@patchthecode
Copy link
Owner

patchthecode commented Dec 8, 2016

OK. hmm. let's discuss on this more. Here are my thoughts on this. Let me know where my ideas can be improves.

My possibly flawed ideas.... possibly.. :)

The calendar deals with dates. I have not coded anything in the calendar to handle times.
Since the calendar deals with dates, I didnt think anyone would be using the times attached to the dates. I am currently building a Scheduler View library.

Which looks like this:
ios-calendar-iphone-week-view_3-100588308-large

This will be able to handle times, because i believe the this library specifically deals with times.
I do not think it is necessary that the calendar which handles dates, should handle times.

These were my initial thoughts on this. Can you let me know how you're using times or what I can do to improve the ideas?

@patchthecode patchthecode changed the title Wrong dates after update to 6.0.5 Wrong times attached to dates after update to 6.0.5 Dec 8, 2016
@patchthecode patchthecode self-assigned this Dec 8, 2016
@deniszhukov
Copy link
Author

deniszhukov commented Dec 9, 2016

Thanks for a quick response.

I agree that this is a calendar and it's purpose to return dates not time.
But swift Date is just point in time without timezone, so adding time to dates can result in different date for different timezone.

How it was working before in 6.0.2

User passes calendar in local timezone -> didSelectDate method has date parameter with selected date and midnight time in local timezone
User passes calendar in UTC timezone -> didSelectDate method has date parameter with selected date and midnight time in UTC

Current logic:

User passes calendar in local timezone -> didSelectDate method has date with selected date and midnight time in local timezone
User passes calendar in UTC timezone -> didSelectDate method has date with selected date BUT TIME is neither midnight time in UTC nor in local timezone (it returns 07:00 UTC, while my current timezone midnight is 08:00 UTC).

I think returned time should be consistent, like it was before.

In my app I'm storing all dates in CoreData in UTC without time (with midnight time).
When user selects another date in calendar I'm calculating how many days have passed since previous selected date.
Right now the logic doesn't work, because calendar started returning time and difference is more/less than a day.
I can definitely overcome any time related difficulties on my side, I just need to know what is the meaning of returned time.
Should I treat that date as date in timezone from calendar that I set in configureCalendar method and just use month and day component to create new Date without time?

But, I think using your calendar (which is really good by the way) users expect having midnight time returned when they are selecting date in a calendar (at least that's what I expected :) )

@patchthecode
Copy link
Owner

patchthecode commented Dec 9, 2016

@deniszhukov understood. Your argument makes sense.
I will update this to what was there before. I'll do this this weekend.

@patchthecode
Copy link
Owner

Behavior change: JTAppleCalendar should not honor the time zones of the calendar instance passed into it.

@patchthecode
Copy link
Owner

patchthecode commented Dec 10, 2016

@deniszhukov i have made a change to the code. Can you let me know if it is working for you?

You can change your the data in your pod file to be:

pod 'JTAppleCalendar', :git => 'https://github.com/patchthecode/JTAppleCalendar.git'

then do a pod install

@deniszhukov
Copy link
Author

I verified it.
You pass the calendar with some timezone -> you get date with midnight in that timezone.

Works perfectly.
Thanks!

@patchthecode
Copy link
Owner

Alright. this will be added in the next update.

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

No branches or pull requests

2 participants