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

How to display current week for the current day? #735

Closed
vctrchu opened this issue Mar 8, 2018 · 5 comments
Closed

How to display current week for the current day? #735

vctrchu opened this issue Mar 8, 2018 · 5 comments
Assignees

Comments

@vctrchu
Copy link

vctrchu commented Mar 8, 2018

Currently using version 7.1.5.
My problem that is never shows the current week but the previous week.
My calendar currently loads like this:
screen shot 2018-03-07 at 5 57 43 pm

Today's date is March 7 so I would like it to show the week like this:
[ 4 5 6 7 8 9 10]

Here is what my code looks like:

func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {
    
    formatter.dateFormat = "yyyy MM dd"
    formatter.timeZone = Calendar.current.timeZone
    formatter.locale = Calendar.current.locale
    
    var dateComponent = DateComponents()
    dateComponent.year = 1
    let startDate = Date()
    let endDate = Calendar.current.date(byAdding: dateComponent, to: startDate)
    let parameters = ConfigurationParameters(startDate: startDate, endDate: endDate!, numberOfRows: 1, calendar: Calendar.current, generateInDates: .forFirstMonthOnly, generateOutDates: .off, firstDayOfWeek: .sunday, hasStrictBoundaries: false)
    
    return parameters
}

func calendar(_ calendar: JTAppleCalendarView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTAppleCell {
    let cell = calendar.dequeueReusableJTAppleCell(withReuseIdentifier: "CustomCell", for: indexPath) as! CustomCell
    self.calendar(calendar, willDisplay: cell, forItemAt: date, cellState: cellState, indexPath: indexPath)
    cell.dateLabel.text = cellState.text
    return cell
}

func calendar(_ calendar: JTAppleCalendarView, willDisplay cell: JTAppleCell, forItemAt date: Date, cellState: CellState, indexPath: IndexPath) {
}

Thanks!

@patchthecode
Copy link
Owner

did you do this in your viewDidLoad ?

calendarView.scrollToDate( Date() )

Also please implement the willDisplayCell function as shown here -> #553

@vctrchu
Copy link
Author

vctrchu commented Mar 8, 2018

Ok I just implemented both parts you just said and it now looks like this:
screen shot 2018-03-08 at 10 48 33 am

Also here's my code for the extension:

func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {
    formatter.dateFormat = "yyyy MM dd"
    formatter.timeZone = Calendar.current.timeZone
    formatter.locale = Calendar.current.locale
    
    var dateComponent = DateComponents()
    dateComponent.year = 1
    let startDate = Date()
    let endDate = Calendar.current.date(byAdding: dateComponent, to: startDate)
    let parameters = ConfigurationParameters(startDate: startDate, endDate: endDate!, numberOfRows: 1, calendar: Calendar.current, generateInDates: .forFirstMonthOnly, generateOutDates: .off, firstDayOfWeek: .sunday, hasStrictBoundaries: false)
    return parameters
}

func calendar(_ calendar: JTAppleCalendarView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTAppleCell {
    let calendarCell = calendar.dequeueReusableJTAppleCell(withReuseIdentifier: "CalendarCell", for: indexPath) as! CalendarCell
    sharedFunctionToConfigureCell(calendarCell: calendarCell, cellState: cellState, date: date)
    return calendarCell
}

func calendar(_ calendar: JTAppleCalendarView, willDisplay cell: JTAppleCell, forItemAt date: Date, cellState: CellState, indexPath: IndexPath) {
    let calendarCell = cell as! CalendarCell
    sharedFunctionToConfigureCell(calendarCell: calendarCell, cellState: cellState, date: date)
    
}

func sharedFunctionToConfigureCell(calendarCell: CalendarCell, cellState: CellState, date: Date) {
    calendarCell.dateLabel.text = cellState.text
}

Any idea how I would show the week of the date instead of it showing the current date starting from sunday?

So the calendar would be:
SUN MON TUE WED THU FRI SAT
[ 4 5 6 7 8 9 10 ]

and then it would reset next week so:

SUN MON TUE WED THU FRI SAT
[ 11 12 13 14 15 16 17 ]

Thanks so much!

@patchthecode
Copy link
Owner

patchthecode commented Mar 15, 2018

this slipped my mind man. Did you solve it already?

if not, just to clarify, you want to find a way to make your calendar scroll to the next month with a button? I did not understand this last part.

So the calendar would be:
SUN MON TUE WED THU FRI SAT
[ 4  5  6  7  8  9  10  ]

and then it would reset next week so:

SUN MON TUE WED THU FRI SAT
[  11  12  13  14  15  16  17  ]

@patchthecode
Copy link
Owner

Assuming this was resolved.
Closing issue.
If not resolved, then reply and I will re-open.

@egg-rita
Copy link

Thanks!!!

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

3 participants