Last active
May 2, 2022 13:47
-
-
Save fitomad/30e40bb75ed764bf5ddef1c78a516a69 to your computer and use it in GitHub Desktop.
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
/** | |
Convierte un String a Date con el formato | |
de fecha indicando en el archivo CSV | |
Por ejemplo: `01/01/2021 0:00` | |
*/ | |
func dateTimeFromFrame(string: String) -> Date? | |
{ | |
let dateFormatter = DateFormatter() | |
dateFormatter.dateFormat = "dd/MM/yyyy HH:mm" | |
return dateFormatter.date(from: string) | |
} | |
/** | |
Convierte un String a Date con el formato | |
de fecha indicando en el archivo CSV | |
Por ejemplo: `01/01/2021` | |
*/ | |
func dateFromFrame(string: String) -> Date? | |
{ | |
let dateFormatter = DateFormatter() | |
dateFormatter.dateFormat = "dd/MM/yyyy" | |
return dateFormatter.date(from: string) | |
} | |
// Establecemos las opciones de lectura del archivo CSV | |
var csvReadOptions = CSVReadingOptions(hasHeaderRow: true, delimiter: ";") | |
// Si indicamos que el tipo de datos es Date entonces | |
// parsearlo mediante nuestro closure | |
csvReadOptions.dateParsers = [ | |
dateTimeFromFrame(string:), | |
dateFromFrame(string:) | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment