Skip to content

Commit

Permalink
Included version check for picking the right date formatter.
Browse files Browse the repository at this point in the history
  • Loading branch information
melvitax committed Mar 4, 2021
1 parent c18b957 commit 6ec9a28
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
16 changes: 8 additions & 8 deletions DateHelper.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 4.5.1;
MARKETING_VERSION = 4.5.2;
MTL_ENABLE_DEBUG_INFO = YES;
"MTL_ENABLE_DEBUG_INFO[arch=*]" = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.allforces.DateHelper-macOS";
Expand Down Expand Up @@ -401,7 +401,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 4.5.1;
MARKETING_VERSION = 4.5.2;
MTL_ENABLE_DEBUG_INFO = NO;
PRODUCT_BUNDLE_IDENTIFIER = "com.allforces.DateHelper-macOS";
PRODUCT_NAME = DateHelper;
Expand Down Expand Up @@ -547,7 +547,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 4.5.1;
MARKETING_VERSION = 4.5.2;
MTL_ENABLE_DEBUG_INFO = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.allforces.DateHelper-IOS";
PRODUCT_NAME = DateHelper;
Expand Down Expand Up @@ -584,7 +584,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 4.5.1;
MARKETING_VERSION = 4.5.2;
MTL_ENABLE_DEBUG_INFO = NO;
PRODUCT_BUNDLE_IDENTIFIER = "com.allforces.DateHelper-IOS";
PRODUCT_NAME = DateHelper;
Expand Down Expand Up @@ -617,7 +617,7 @@
INFOPLIST_FILE = "$(SRCROOT)/Sources/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 4.5.1;
MARKETING_VERSION = 4.5.2;
MTL_ENABLE_DEBUG_INFO = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.allforces.DateHelper-tvOS";
PRODUCT_NAME = DateHelper;
Expand Down Expand Up @@ -655,7 +655,7 @@
INFOPLIST_FILE = "$(SRCROOT)/Sources/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 4.5.1;
MARKETING_VERSION = 4.5.2;
MTL_ENABLE_DEBUG_INFO = NO;
PRODUCT_BUNDLE_IDENTIFIER = "com.allforces.DateHelper-tvOS";
PRODUCT_NAME = DateHelper;
Expand Down Expand Up @@ -691,7 +691,7 @@
INFOPLIST_FILE = "$(SRCROOT)/Sources/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 4.5.1;
MARKETING_VERSION = 4.5.2;
MTL_ENABLE_DEBUG_INFO = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.allforces.DateHelper-watchOS";
PRODUCT_NAME = DateHelper;
Expand Down Expand Up @@ -728,7 +728,7 @@
INFOPLIST_FILE = "$(SRCROOT)/Sources/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 4.5.1;
MARKETING_VERSION = 4.5.2;
MTL_ENABLE_DEBUG_INFO = NO;
PRODUCT_BUNDLE_IDENTIFIER = "com.allforces.DateHelper-watchOS";
PRODUCT_NAME = DateHelper;
Expand Down
14 changes: 8 additions & 6 deletions Sources/DateHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ public extension Date {
string = string[..<string.index(string.endIndex, offsetBy: -1)].appending("GMT")
}
case .isoDateTimeMilliSec, .isoDateTimeSec, .isoDateTime, .isoYear,. isoDate, .isoYearMonth:
let formatter = Date.cachedDateFormatters.cachedISOFormatter(format, timeZone: timeZone, locale: locale)
guard let date = formatter.date(from: string) else {
return nil
if #available(iOS 10.0, watchOS 4, tvOS 10, macOS 11, *) {
let formatter = Date.cachedDateFormatters.cachedISOFormatter(format, timeZone: timeZone, locale: locale)
guard let date = formatter.date(from: string) else {
return nil
}
self.init(timeInterval: 0, since: date)
return
}
self.init(timeInterval: 0, since: date)
return
default:
break
}
Expand Down Expand Up @@ -128,7 +130,7 @@ public extension Date {
return String(format: format.stringFormat, nowMillis, offset)
case .isoDateTimeMilliSec, .isoDateTimeSec, .isoDateTime,
.isoYear,. isoDate, .isoYearMonth:
if #available(iOS 11.0, watchOS 4, tvOS 10, macOS 13, *) {
if #available(iOS 10.0, watchOS 4, tvOS 10, macOS 11, *) {
let formatter = Date.cachedDateFormatters.cachedISOFormatter(format, timeZone: timeZone, locale: useLocale)
return formatter.string(from: self)
} else {
Expand Down

0 comments on commit 6ec9a28

Please sign in to comment.