HorizonCalendar icon indicating copy to clipboard operation
HorizonCalendar copied to clipboard

Selected day not accurate

Open jl-mobitech opened this issue 1 year ago • 2 comments

I am using HorizonCalendar that allows the user to select a date and enter some data based on the selected date. I am parsing the Day object to date like this:

let parsedDate = sharedDataStore.gregorianCalendar.date(from: day.components)!

sharedDataStore.gregorianCalendar's implementation is: gregorianCalendar = Calendar(from: .gregorian)

Now for example, today's date is June 8, 2023 but when I am tapping June 7th, 2023, the parsedDate value is 2023-06-06 16:00:00 +0000

image

Any idea what's happening? I am currently on a country where the timezone is GMT +8, I don't know if it will help to diagnose my problem.

Also note, I am using a single instance of the calendar sharedDataStore.gregorianCalendar as I believe you mentioned that somewhere in the issues to only use one calendar.

Thanks!

jl-mobitech avatar Jun 08 '23 13:06 jl-mobitech

CaleandrViewRepresentable code:

CalendarViewRepresentable(calendar: vm.sharedDataStore.gregorianCalendar,
                          visibleDateRange: vm.startDateRange...Date(),
                          monthsLayout: .horizontal,
                          dataDependency: vm.selectedDate,
                          proxy: calendarViewProxy)
.dayItemProvider(dayItemProvider) //: DayItemProvider
.monthHeaderItemProvider(monthItemProvider) //: MonthHeaderItemProvider
.dayOfWeekItemProvider(dayOfWeekProvider) //: DayOfWeekItemProvider
.onDaySelection(vm.setDate)
.onAppear {
    calendarViewProxy.scrollToDay(containing: Date(),
                                  scrollPosition: .centered,
                                  animated: false)
}

jl-mobitech avatar Jun 08 '23 13:06 jl-mobitech

@jl-mobitech you might want to use Calendar.current. Just creating a calendar via Calendar(identifier: .gregorian) might not have it configured with the right info.

bryankeller avatar Sep 18 '23 15:09 bryankeller