Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: codeandtheory/ycalendarpicker-ios
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.0.5
Choose a base ref
...
head repository: codeandtheory/ycalendarpicker-ios
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 3 commits
  • 5 files changed
  • 2 contributors

Commits on Sep 13, 2023

  1. Copy the full SHA
    36efe97 View commit details

Commits on Dec 12, 2023

  1. Git Issue(21): To show the given date month when calendar is presented (

    #22)
    
    * Git Issue(21): To show the given date month when calendar is presented
    
    * Removed extra line space
    devkaranCT authored Dec 12, 2023
    Copy the full SHA
    e7212a4 View commit details
  2. test case updated (#24)

    devkaranCT authored Dec 12, 2023
    Copy the full SHA
    a2b2abc View commit details
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -34,10 +34,11 @@ init(
appearance: Appearance = .default,
minimumDate: Date? = nil,
maximumDate: Date? = nil,
startDate: Date? = nil,
locale: Locale? = nil
)
```
The standard initializer lets you specify the first day of the week, appearance, optional minimum and maximum dates, and the locale, although it provides sensible defaults for all of these.
The standard initializer lets you specify the first day of the week, appearance, optional minimum and maximum dates, start date of the calendar and the locale, although it provides sensible defaults for all of these.

`CalendarPicker` has an additional initializer:

11 changes: 11 additions & 0 deletions Sources/YCalendarPicker/SwiftUI/Views/CalendarView.swift
Original file line number Diff line number Diff line change
@@ -42,6 +42,9 @@ public struct CalendarView {
}
}

/// Start date (if any)
public var startDate: Date?

/// Calendar appearance
public var appearance: CalendarPicker.Appearance {
get {
@@ -91,19 +94,22 @@ public struct CalendarView {
/// - appearance: appearance of calendar view. Default is `Appearance.default`.
/// - minimumDate: minimum date to enable. Default is `nil`.
/// - maximumDate: maximum date to enable. Default is `nil`.
/// - startDate: start date of the calendar. Default is `nil`.
/// - locale: locale for data formatting e.g Date format. Default is `nil`.
public init(
firstWeekday: Int? = nil,
appearance: CalendarPicker.Appearance = .default,
minimumDate: Date? = nil,
maximumDate: Date? = nil,
startDate: Date? = nil,
locale: Locale? = nil
) {
self.firstWeekday = firstWeekday ?? (Locale.current.calendar.firstWeekday - 1)
self.appearance = appearance
self.minimumDate = minimumDate?.dateOnly
self.maximumDate = maximumDate?.dateOnly
self.locale = locale ?? Locale.current
self.startDate = startDate?.startDateOfMonth()
}
}

@@ -120,6 +126,11 @@ extension CalendarView: View {
})
)
.background(Color(self.appearance.backgroundColor))
.onAppear(perform: {
if let getStartDate = self.startDate {
currentDate = getStartDate
}
})
}

@ViewBuilder
2 changes: 1 addition & 1 deletion Sources/YCalendarPicker/SwiftUI/Views/DaysView.swift
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ extension DaysView: View {
var dateItem = allDates[index]
dateItem.isSelected = dateItem.date == selectedDate
var dayAppearance = dateItem.getDayAppearance(from: appearance)
if dateItem.isBooked && !dateItem.date.isSameMonth(as: currentDate) {
if !dateItem.date.isSameMonth(as: currentDate) {
dayAppearance = appearance.grayedDayAppearance
}
let dayView = DayView(
4 changes: 4 additions & 0 deletions Sources/YCalendarPicker/UIKit/CalendarPicker.swift
Original file line number Diff line number Diff line change
@@ -58,19 +58,22 @@ public class CalendarPicker: UIControl {
/// - appearance: appearance for the calendar. Default is `.default`.
/// - minimumDate: minimum selectable date. Default is `nil`.
/// - maximumDate: maximum selectable date. Default is `nil`.
/// - startDate: start date of the calendar. Default is `nil`.
/// - locale: locale for date formatting. Pass `nil` to use current locale. Default is `nil`.
public required init(
firstWeekday: Int? = nil,
appearance: Appearance = .default,
minimumDate: Date? = nil,
maximumDate: Date? = nil,
startDate: Date? = nil,
locale: Locale? = nil
) {
calendarView = CalendarView(
firstWeekday: firstWeekday,
appearance: appearance,
minimumDate: minimumDate,
maximumDate: maximumDate,
startDate: startDate,
locale: locale
)
super.init(frame: .zero)
@@ -83,6 +86,7 @@ public class CalendarPicker: UIControl {
appearance: Appearance(),
minimumDate: nil,
maximumDate: nil,
startDate: nil,
locale: nil
)
super.init(coder: coder)
13 changes: 11 additions & 2 deletions Tests/YCalendarPickerTests/SwiftUI/CalendarViewTests.swift
Original file line number Diff line number Diff line change
@@ -177,6 +177,13 @@ final class CalendarViewTests: XCTestCase {
XCTAssertNil(sut.date)
}

func testOnStartDate() {
let expectedDate = Date().date(byAddingMonth: 4)
let sut = makeSUT(startDate: expectedDate)
XCTAssertNotNil(sut.startDate)
XCTAssertEqual(expectedDate?.startDateOfMonth(), sut.startDate)
}

func testCalendarViewPreviewIsNotNill() {
XCTAssertNotNil(CalendarView_Previews.previews)
}
@@ -190,12 +197,14 @@ private extension CalendarViewTests {
func makeSUT(
firstWeekday: Int? = nil,
minimumDate: Date? = nil,
maximumDate: Date? = nil
maximumDate: Date? = nil,
startDate: Date? = nil
) -> CalendarView {
let sut = CalendarView(
firstWeekday: firstWeekday ?? 0,
minimumDate: minimumDate,
maximumDate: maximumDate
maximumDate: maximumDate,
startDate: startDate
)
XCTAssertNotNil(sut.body)
return sut