Closed dbmrq closed 7 years ago
Ok can you do one thing? (assuming you are using master branch)
func calendar(_ calendar: JTAppleCalendarView,
willDisplayCell cell: JTAppleDayCellView, date: Date, cellState: CellState) {
print(date, cellState.text)
}
are they both the same date?
If they are both the same date, then configure your calendar as this:
var calendar = Calendar.current
calendar.timeZone = TimeZone(secondsFromGMT: 0)!
Then provide it to your configure method
What you specified in configure calendar was not a calendar
You gave it an identifier.
Calendar identifiers are of type .gregorian
or .persian
etc etc etc
Once you supply the type of calendar you want to use, I then generate one internally.
The generated internal calendar is this set calendar.timeZone = TimeZone(secondsFromGMT: 0)!
I did this because different users from different time zones were getting either an off-by-one-day error. So to solve this, i set all calendars to start from 0 from GMT. If you are formatting dates to display using a calendar instance, then your calendar() instance should also start from gmt 0.
I am still debating whether or not i should let the user supply the actual configured calendar()
instance instead of the identifier. Because either way, you will still have to set the calendar to
calendar.timeZone = TimeZone(secondsFromGMT: 0)!
which was something i was trying to not make the user have to do.
Of course, this explanation is assuming I have understood your problem correctly?
Thanks for the answer!
Providing it to the configure method doesn't make a difference, but changing the timeZone of the Calendar
I use to call component(.day, from: date)
does, like so:
func calendar(_ calendar: JTAppleCalendarView,
willDisplayCell cell: JTAppleDayCellView, date: Date, cellState: CellState) {
var calendar = Calendar.current
calendar.timeZone = TimeZone(secondsFromGMT: 0) ?? calendar.timeZone
print(calendar.component(.day, from: date), cellState.text)
}
So I think the problem is cellState.text
always uses the same time zone… now I realized I don't even set the calendar itself in configureCalendar
, just the identifier
. So I can work around that by always setting the timezone like that before doing any calculations, but that seems very messy and error prone. Shouldn't cellState.text
use whatever calendar I want with its own time zone and all?
Also many people (me included) use Date
extensions, like this one, which has a day property:
public var day: Int { return Date.sharedCalendar.component(.day, from: self) }
And sharedCalendar
there is Calendar.autoupdatingCurrent
. It's really convenient, you can just do date.day
and get the day.
But now I can't use that, because it gets the current time zone as well (like it should), and JTAppleCalendar
doesn't. So every time I work with JTAppleCalendar
I'll have to set a new calendar and specify the time zone and all that, it's pretty annoying.
I could try and help change this if you want, but I'm not sure if there's more to it than I'm seeing. Is there a reason why you made it this way?
hmm... this is too long to talk out. haha. I will do so in a bit. But if youre available now, we can text chat here https://gitter.im/patchthecode/JTAppleCalendar
because texting here is very slow
I need to debug with someone who is experiencing the wrong text. From my end, and many others, the dates are correct. But the issue seems to be with time zones. So if youre available to debug, then let me know.
Hey, I'm sorry, I was busy before. But sure, I can help you debug. :)
OK. in 15 mins? wil be here https://gitter.im/patchthecode/JTAppleCalendar
I'm there.
So, can I close this issue now?
Yes, thanks :)
cool.
I'm having the same problem as in #147, but I don't think I should need to use a different
Calendar
.Here's an example:
In the
configureCalendar
function I specifyCalendar.current
as the calendar that should be used. Then inwillDisplayCell
I useCalendar.current
again to print the day, and I printcellState.text
too. But I get different results:So what
Calendar
iscellState.text
using? Shouldn't it be the one I specified inconfigureCalendar
?