HorizonCalendar
HorizonCalendar copied to clipboard
Selected day not accurate
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
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!
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 you might want to use Calendar.current
. Just creating a calendar via Calendar(identifier: .gregorian)
might not have it configured with the right info.