-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DON-715] Add capabilities to
BPKcalendar
required for wholeMonth s…
…election (#2104) * DON-628 / Whole month selection as a separate category in Backpack * DON-628 / Make whole month selection as part of range stage in Backpack calendar * DON-628 / Move the calendar month selection logic to Backpack calendar * Remove CalendarMonth data entity to simplifies * DON-628 / Remove redundant file * Remove extra condition on accessibility traits * Fix lint issues * Remove extra file * Add example in Calendar SwiftUI about whole month selection * Make accessory action based on given date * Fix the example app * Change the order of examples * Improve the comments and file names * Make highlight parameter explicit based on PR feedbacks * Make calendar accessory action as enum. * Fix the linting issue * Fix the tests
- Loading branch information
Showing
16 changed files
with
275 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
Backpack-SwiftUI/Calendar/Classes/Date+GetMonthDateRange.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Backpack - Skyscanner's Design System | ||
* | ||
* Copyright 2018 Skyscanner Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import Foundation | ||
|
||
extension Date { | ||
public func getMonthDateRange(calendar: Calendar) -> ClosedRange<Date>? { | ||
let components = calendar.dateComponents([.year, .month], from: self) | ||
|
||
guard let year = components.year, let month = components.month else { | ||
return nil | ||
} | ||
|
||
// Create DateComponents for the start of the month | ||
var startComponents = DateComponents() | ||
startComponents.year = year | ||
startComponents.month = month | ||
startComponents.day = 1 | ||
|
||
// Get the start date of the month | ||
guard let startDate = calendar.date(from: startComponents) else { | ||
return nil | ||
} | ||
|
||
// Get the range of days in the month | ||
guard let range = calendar.range(of: .day, in: .month, for: startDate) else { | ||
return nil | ||
} | ||
|
||
// Create the end date of the month | ||
let endDay = range.upperBound - 1 | ||
let endComponents = DateComponents(year: year, month: month, day: endDay) | ||
|
||
guard let endDate = calendar.date(from: endComponents) else { | ||
return nil | ||
} | ||
|
||
// Return the range of dates | ||
return startDate...endDate | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.