Skip to content

Commit

Permalink
Remove problematic calls to calendar.date(from:)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerzer committed Oct 31, 2021
1 parent 4dc414e commit 2a7a6d2
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions Classes/DateTimeParsers.swift
Expand Up @@ -21,8 +21,6 @@ final class GPXDateParser {

// MARK:- Supporting Variables

/// Caching Calendar such that it can be used repeatedly without reinitializing it.
private static var calendarCache = [Int : Calendar]()
/// Components of Date stored together
private static var components = DateComponents()

Expand Down Expand Up @@ -55,15 +53,8 @@ final class GPXDateParser {
components.hour = hour.pointee
components.month = month.pointee
components.second = second.pointee

if let calendar = calendarCache[0] {
return calendar.date(from: components)
}

var calendar = Calendar(identifier: .gregorian)
calendar.timeZone = TimeZone(secondsFromGMT: 0)!
calendarCache[0] = calendar
return calendar.date(from: components)
components.timeZone = TimeZone(secondsFromGMT: 0)!
return components.date
}

/// Parses a year string as native Date type.
Expand All @@ -78,14 +69,7 @@ final class GPXDateParser {
})

components.year = year.pointee

if let calendar = calendarCache[1] {
return calendar.date(from: components)
}

var calendar = Calendar(identifier: .gregorian)
calendar.timeZone = TimeZone(secondsFromGMT: 0)!
calendarCache[1] = calendar
return calendar.date(from: components)
components.timeZone = TimeZone(secondsFromGMT: 0)
return components.date
}
}

0 comments on commit 2a7a6d2

Please sign in to comment.