Skip to content

Commit

Permalink
Use ISO8601DateFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksloan committed Apr 5, 2024
1 parent 5d37662 commit a16196f
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions Sources/Soto/Extensions/S3/S3+presignedPost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -231,20 +231,31 @@ extension S3 {
}

private func shortDateFormat(date: Date) -> String {
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
dateFormatter.dateFormat = "yyyyMMdd"
dateFormatter.timeZone = TimeZone(secondsFromGMT: 0)
let formatter = ISO8601DateFormatter()
formatter.formatOptions.insert(.withYear)
formatter.formatOptions.insert(.withMonth)
formatter.formatOptions.insert(.withDay)
formatter.formatOptions.remove(.withTime)
formatter.formatOptions.remove(.withTimeZone)
formatter.formatOptions.remove(.withDashSeparatorInDate)

return dateFormatter.string(from: date)
let formattedDate = formatter.string(from: date)

return formattedDate
}

private func longDateFormat(date: Date) -> String {
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
dateFormatter.dateFormat = "yyyyMMdd'T'HHmmss'Z'"
dateFormatter.timeZone = TimeZone(secondsFromGMT: 0)

return dateFormatter.string(from: date)
let formatter = ISO8601DateFormatter()
formatter.formatOptions.insert(.withYear)
formatter.formatOptions.insert(.withMonth)
formatter.formatOptions.insert(.withDay)
formatter.formatOptions.insert(.withTime)
formatter.formatOptions.insert(.withTimeZone)
formatter.formatOptions.remove(.withDashSeparatorInDate)
formatter.formatOptions.remove(.withColonSeparatorInTime)

let formattedDate = formatter.string(from: date)

return formattedDate
}
}

0 comments on commit a16196f

Please sign in to comment.