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

Add Locale option to UIDatePicker #2167

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Example/Example/Controllers/RowsExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 20,7 @@ class RowsExampleViewController: FormViewController {
LabelRow.defaultCellUpdate = { cell, row in cell.detailTextLabel?.textColor = .systemOrange }
CheckRow.defaultCellSetup = { cell, row in cell.tintColor = .systemOrange }
DateRow.defaultRowInitializer = { row in row.minimumDate = Date() }
DateTimeRow.defaultRowInitializer = { row in row.minimumDate = Date() }

form

Expand All @@ -35,6 36,13 @@ class RowsExampleViewController: FormViewController {
}

<<< DateRow() { $0.value = Date(); $0.title = "DateRow" }

<<< DateTimeRow() {
$0.value = Date()
$0.title = "DateTimeRow"
//Force 24 time input
$0.locale = Locale(identifier: "en_GB")
}

<<< CountDownInlineRow() { $0.value = Date(); $0.title = "CountDownInlineRow" }

Expand Down
6 changes: 6 additions & 0 deletions Source/Rows/Common/DateFieldRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 29,7 @@ public protocol DatePickerRowProtocol: AnyObject {
var minimumDate: Date? { get set }
var maximumDate: Date? { get set }
var minuteInterval: Int? { get set }
var locale:Locale? { get set }
}

open class DateCell: Cell<Date>, CellType {
Expand Down Expand Up @@ -69,6 70,7 @@ open class DateCell: Cell<Date>, CellType {
datePicker.setDate(row.value ?? Date(), animated: row is CountDownPickerRow)
datePicker.minimumDate = (row as? DatePickerRowProtocol)?.minimumDate
datePicker.maximumDate = (row as? DatePickerRowProtocol)?.maximumDate
datePicker.locale = (row as? DatePickerRowProtocol)?.locale
if let minuteIntervalValue = (row as? DatePickerRowProtocol)?.minuteInterval {
datePicker.minuteInterval = minuteIntervalValue
}
Expand Down Expand Up @@ -119,6 121,7 @@ open class DateCell: Cell<Date>, CellType {
}

open class _DateFieldRow: Row<DateCell>, DatePickerRowProtocol, NoValueDisplayTextConformance {


/// The minimum value for this row's UIDatePicker
open var minimumDate: Date?
Expand All @@ -131,6 134,9 @@ open class _DateFieldRow: Row<DateCell>, DatePickerRowProtocol, NoValueDisplayTe

/// The formatter for the date picked by the user
open var dateFormatter: DateFormatter?

/// The locale for this row's UIDatePicker
open var locale: Locale?

open var noValueDisplayText: String? = nil

Expand Down
3 changes: 3 additions & 0 deletions Source/Rows/Common/DateInlineFieldRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 66,9 @@ open class _DateInlineFieldRow: Row<DateInlineCell>, DatePickerRowProtocol, NoVa
/// The formatter for the date picked by the user
open var dateFormatter: DateFormatter?

/// The locale for this row's UIDatePicker
open var locale: Locale?

open var noValueDisplayText: String?

required public init(tag: String?) {
Expand Down
3 changes: 2 additions & 1 deletion Source/Rows/DatePickerRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 120,8 @@ open class _DatePickerRow: Row<DatePickerCell>, DatePickerRowProtocol {
open var minimumDate: Date?
open var maximumDate: Date?
open var minuteInterval: Int?

open var locale: Locale?

required public init(tag: String?) {
super.init(tag: tag)
displayValueFor = nil
Expand Down