-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Revert "Add VGSDateTextField." This reverts commit 92c1e50. * Bump SDK version
- Loading branch information
Showing
49 changed files
with
3,842 additions
and
532 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
108 changes: 108 additions & 0 deletions
108
Sources/VGSCollectSDK/Core/TokenizationConfiguration/VGSDateTokenizationConfiguration.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,108 @@ | ||
// | ||
// VGSDateTokenizationConfiguration.swift | ||
// VGSCollectSDK | ||
// | ||
|
||
import Foundation | ||
|
||
/// `VGSDateTokenizationParameters` - parameters required for tokenization API | ||
public struct VGSDateTokenizationParameters: VGSTokenizationParametersProtocol { | ||
|
||
/// Vault storage type. | ||
public var storage: String = VGSVaultStorageType.PERSISTENT.rawValue | ||
|
||
/// Data alies format. | ||
public var format: String = VGSVaultAliasFormat.UUID.rawValue | ||
} | ||
|
||
/// Class responsible for configuration `VGSDateTextField` or `VGSTextField` with `fieldType = .date`. | ||
/// Extends `VGSConfiguration`. Required to work with tokenization API. | ||
public final class VGSDateTokenizationConfiguration: VGSConfiguration, VGSDateConfigurationProtocol, VGSTextFieldTokenizationConfigurationProtocol, VGSFormatSerializableProtocol { | ||
|
||
// MARK: - Properties | ||
/// Start date used to fill out the date picker | ||
private var datePickerStartDate: VGSDate = VGSDateConfiguration.minValidPickerStartDate | ||
|
||
/// End date used to fill out the date picker | ||
private var datePickerEndDate: VGSDate = VGSDateConfiguration.maxValidPickerEndDate | ||
|
||
/// Get the list of years from `datePickerStartDate` to `datePickerEndDate`. | ||
/// In case any of the dates are not set, it will use the default | ||
/// values `minValidStartDate` and `maxValidEndDate` respectively | ||
internal var years: [Int] { | ||
Array(datePickerStartDate.year...datePickerEndDate.year) | ||
} | ||
|
||
// MARK: - Constructor | ||
/// Initialization | ||
/// Date configuration initializer, if no `datePickerStartDate` is provided, | ||
/// a default date will be used adding 100 years to the current date. | ||
/// Similar approach will be used if `datePickerEndDate` is not provided, | ||
/// it will be calculated removing 100 years from current date. | ||
/// | ||
/// - Parameters: | ||
/// - vgs: `VGSCollect` instance. | ||
/// - fieldName: associated `fieldName`. | ||
/// - datePickerStartDate: optional `VGSDate` instance. | ||
/// - datePickerEndDate: optional `VGSDate` instance. | ||
public init(collector vgs: VGSCollect, | ||
fieldName: String, | ||
datePickerStartDate: VGSDate? = nil, | ||
datePickerEndDate: VGSDate? = nil) { | ||
/// Setup custom picker start date | ||
if let startDate = datePickerStartDate { | ||
self.datePickerStartDate = startDate | ||
} | ||
/// Setup custom picker end date | ||
if let endDate = datePickerEndDate { | ||
self.datePickerEndDate = endDate | ||
} | ||
/// Super initializer | ||
super.init(collector: vgs, fieldName: fieldName) | ||
} | ||
|
||
// MARK: - Overridden methods and properties | ||
public override var type: FieldType { | ||
get { return .date } | ||
set {} | ||
} | ||
|
||
// MARK: - VGSDateConfigurationProtocol implementation | ||
public var inputSource: VGSTextFieldInputSource = .datePicker | ||
public var inputDateFormat: VGSDateFormat? | ||
public var outputDateFormat: VGSDateFormat? | ||
|
||
// MARK: - VGSFormatSerializableProtocol implementation | ||
public var serializers: [VGSFormatSerializerProtocol] = [] | ||
func serialize(_ content: String) -> [String: Any] { | ||
return DateFormatConvertor.serialize(content, serializers: serializers, outputFormat: outputDateFormat) | ||
} | ||
internal var shouldSerialize: Bool { | ||
return !serializers.isEmpty | ||
} | ||
|
||
// MARK: - VGSDateTokenizationParameters implementation | ||
public var tokenizationParameters = VGSDateTokenizationParameters() | ||
internal var tokenizationConfiguration: VGSTokenizationParametersProtocol { | ||
return tokenizationParameters | ||
} | ||
} | ||
|
||
// MARK: - `TextFormatConvertable` implementation | ||
extension VGSDateTokenizationConfiguration: VGSTextFormatConvertable { | ||
|
||
/// :nodoc: | ||
var inputFormat: InputConvertableFormat? { | ||
return inputDateFormat | ||
} | ||
|
||
/// :nodoc: | ||
var outputFormat: OutputConvertableFormat? { | ||
return outputDateFormat | ||
} | ||
|
||
/// :nodoc: | ||
var convertor: TextFormatConvertor { | ||
return DateFormatConvertor() | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// | ||
// VGSDate.swift | ||
// VGSCollectSDK | ||
// | ||
|
||
import Foundation | ||
|
||
/// `Struct` that represents a date including `year`, `month` and `day`. It doesn't include `hours`, `minutes` or `seconds`. | ||
public struct VGSDate { | ||
|
||
// MARK: - Properties | ||
public var day: Int | ||
public var month: Int | ||
public var year: Int | ||
|
||
/// Get the day formatted value, for example if the day is `1` it is returned as `01` | ||
public var dayFormatted: String { | ||
return String(format: "%02d", day) | ||
} | ||
|
||
/// Get the month formatted value, for example if the month is `3` it is returned as `03` | ||
public var monthFormatted: String { | ||
return String(format: "%02d", month) | ||
} | ||
|
||
// MARK: - Initialization | ||
/// Create a new instance of a `VGSDate` object, if the date is not valid, it returns `nil` | ||
/// - Parameters: | ||
/// - day: `Int`. Represents the day in the date. | ||
/// - month: `Int`. Represents the month in the date. | ||
/// - year: `Int`. Represents the year in the date. | ||
/// - Returns: `VGSDate`, date reference or nil if the date is invalid. | ||
public init?(day: Int, month: Int, year: Int) { | ||
// Make sure it is a valid date | ||
guard DateComponents( | ||
calendar: Calendar(identifier: .gregorian), | ||
year: year, | ||
month: month, | ||
day: day | ||
).isValidDate else { | ||
let message = "Invalid day, month or year to create date at VGSDate initializer" | ||
let event = VGSLogEvent(level: .warning, text: message, severityLevel: .error) | ||
VGSCollectLogger.shared.forwardLogEvent(event) | ||
return nil | ||
} | ||
// Save date data | ||
self.day = day | ||
self.month = month | ||
self.year = year | ||
} | ||
} | ||
|
||
// MARK: - Equatable and Comparable implementation | ||
extension VGSDate: Comparable { | ||
|
||
/// :nodoc: | ||
public static func == (lhs: Self, rhs: Self) -> Bool { | ||
return lhs.year == rhs.year && | ||
lhs.month == rhs.month && | ||
lhs.day == rhs.day | ||
} | ||
|
||
/// :nodoc: | ||
public static func < (lhs: VGSDate, rhs: VGSDate) -> Bool { | ||
// Check year | ||
if lhs.year < rhs.year { | ||
return true | ||
} | ||
// If the year is equal, check month | ||
else if lhs.year == rhs.year { | ||
// Check month | ||
if lhs.month < rhs.month { | ||
return true | ||
} | ||
// If the month is equal, check day | ||
else if lhs.month == rhs.month { | ||
// Check day | ||
return lhs.day < rhs.day | ||
} | ||
} | ||
// The date at left is not less than date at right | ||
return false | ||
} | ||
} |
Oops, something went wrong.