mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-26 04:07:50 +00:00
not all nanosecond fractions have 3 sig figs, so can't hard code the acceptable string lengths
This commit is contained in:
1 parent
bb59f5e6f7
commit
dad163771f
1 file changed
+9
-6
@@ -19,14 +19,17 @@ class SQLiteDateParser {
|
||||
private static let nanosecond = UnsafeMutablePointer<CChar>.allocate(capacity: 9)
|
||||
|
||||
public static func components(from dateString: String) -> DatabaseDateComponents? {
|
||||
switch dateString.count {
|
||||
case 23, 19, 16, 10:
|
||||
guard dateString.count >= 5 else { return nil }
|
||||
|
||||
if dateString[dateString.index(dateString.startIndex, offsetBy: 4)] == "-" {
|
||||
return datetimeComponents(from: dateString)
|
||||
case 12, 8, 5:
|
||||
return timeComponents(from: dateString)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
||||
if dateString[dateString.index(dateString.startIndex, offsetBy: 2)] == ":" {
|
||||
return timeComponents(from: dateString)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// - YYYY-MM-DD
|
||||
|
||||
Reference in new issue
Block a user