Skip to content

Commit

Permalink
Add new date init.
Browse files Browse the repository at this point in the history
  • Loading branch information
yspreen committed Apr 28, 2021
1 parent bdcff11 commit 6a71b07
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions DGCAVerifier/Extensions/Date.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,28 @@ extension Date {
}
self = date
}
init?(rfc3339DateTimeString str: String) {
let rfc3339DateTimeFormatter = DateFormatter()

rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
if let date = rfc3339DateTimeFormatter.date(from: str) {
self = date
return
}

rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
if let date = rfc3339DateTimeFormatter.date(from: str) {
self = date
return
}

rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd't'HH:mm:ss.SSS'z'"
if let date = rfc3339DateTimeFormatter.date(from: str) {
self = date
return
}
return nil
}

var localDateString: String {
let formatter = DateFormatter()
Expand Down

0 comments on commit 6a71b07

Please sign in to comment.