Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto committed Feb 9, 2024
1 parent d9f7ed6 commit b2a060d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions PostHog/Utils/DateUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@

import Foundation

// returns 2024-02-09T10:53:53.781Z
public func toISO8601String(_ date: Date) -> String {
private func newDateFormatter() -> DateFormatter {
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
dateFormatter.timeZone = TimeZone(abbreviation: "UTC")

dateFormatter.dateFormat = "yyyy-MM-dd'T'hh:mm:ss.SSS'Z'" // Use 'hh' for 12-hour clock
return dateFormatter
}

// returns 2024-02-09T10:53:53.781Z
public func toISO8601String(_ date: Date) -> String {
let dateFormatter = newDateFormatter()
return dateFormatter.string(from: date)
}

public func toISO8601Date(_ date: String) -> Date? {
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
dateFormatter.timeZone = TimeZone(abbreviation: "UTC")

dateFormatter.dateFormat = "yyyy-MM-dd'T'hh:mm:ss.SSS'Z'" // Use 'hh' for 12-hour clock
let dateFormatter = newDateFormatter()
return dateFormatter.date(from: date)
}

0 comments on commit b2a060d

Please sign in to comment.