-
Notifications
You must be signed in to change notification settings - Fork 343
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
Set timezone for DayView after initialization #291
Comments
Hi, you'll need to instantiate DayView with the modified Calendar in order to make it run in a different TimeZone: override func loadView() {
calendar.timeZone = TimeZone(identifier: "Europe/Paris")!
dayView = DayView(calendar: calendar)
view = dayView
} Please, refer to the example project:
|
Thx for quick answer
I use storyboards with custom viewcontroller (not DayViewController) and I don't want to create a |
Currently it's not possible, as the proper Calendar has to be configured on view initialization and propagated to other modules of the CK. I highly suggest you subclassing Another approach would be to configure DayView programmatically. To sum up, in order to use CK with a custom timezone, you'll have to pass the calendar to it on initialization. |
How difficult is it to implement a function that will simply reset the state of the |
That shouldn't be too difficult, however, it might lead to bugs and inconsistencies, as CK hasn't been designed with Storyboaard/XIB support in mind. In short, this could be achieved by:
It might also require modifying other CalendarKit modules (e.g. Header) to support this state/calendar swap after initialization. The whole library has been developed with assumption of Calendar instance not changing after initialization. Feel free to submit a pull request with this change. |
I started working on the ability to change the calendar after |
Thanks for the initial pull request. The direction looks good to me, I've left some comments. I'm looking forward to a finalized version. I see two approaches to continue:
|
I plan to use the second approach as this will not result in modules being dependent on the state object. I think this will lead to better independence of the modules from each other. But could you please describe in detail the pros and cons of each of these approaches. I do not know all the details of the CalendarKit source code and I am wondering how my decision can affect the overall architecture |
Sounds good. To sum up, the purpose of the Rule: any event sent via As for the pros & cons to the two approaches: Storing Calendar in the DayViewState:➕One source of truth as to which calendar is used Propagating Calendar changes down via view hierarchy:➕ Parent views already have access to the child views - adding this functionality is simple To me the 2nd approach also seems natural, as there is no feedback-loop problem which was the reason to move to the |
Thanks for the answer. However, I ran into an additional problem. Why is the project using the let originDate = vc.timeline.date.addingTimeInterval(TimeInterval(vc.timeline.calendar.timeZone.secondsFromGMT()))
vc.timeline.calendar = newCalendar
vc.timeline.date = originDate.dateOnly(calendar: newCalendar) Why bother cutting off hours, minutes and seconds from a date object at all? Now I have to use a lot of boilerplate to fix this. |
The The reason for this addition is mainly to simplify debugging, as the time information has no meaning in the context of controlling the navigation in the CalendarKit. To put it simply, if one module tells another module to move to a date which is not fixed at 0:00, there is an issue. Of course, there is at least one opportunity to use the time information, for example, to keep the scroll position of the Calendar: #211 What is the problem and why does the use of |
It took me 24 days, a bunch of burned out nerve cells, to realize that cutting off time really makes debugging much easier. I was constantly having problems updating dates to match the new time zones. Now I understand that it would be much more difficult for me to debug without cutting off the time. All this time, I have been fixing various bugs, which just appeared due to the incorrect "zeroing" of dates to a new timezone. Please take a look at my improved solution and share your thoughts. |
@RareScrap I've reviewed the changes, please take a look. Let's continue the discussion only in your pull request, as it's pretty close to the completion. |
New Issue Checklist
Issue Description
I want to set a specific timezone for
DayView
so as not to depend on the device timezone.Code I'm using with CalendarKit
I tried to set the timezone as follows, but it didn't work - the
DayView
's timezone still depends on the device's timezoneResult I am trying to achieve
I want the
DayView
s to always be displayed at the same position on the timeline, regardless of the device's timezoneThe text was updated successfully, but these errors were encountered: