diff --git a/DateToolsSwift/DateTools/Date+Inits.swift b/DateToolsSwift/DateTools/Date+Inits.swift index e3d6f6db..c3a4d6dc 100644 --- a/DateToolsSwift/DateTools/Date+Inits.swift +++ b/DateToolsSwift/DateTools/Date+Inits.swift @@ -60,14 +60,16 @@ public extension Date { * - parameter dateString: Date in the formatting given by the format parameter * - parameter format: Format style using Apple's date formatting guide * - parameter timeZone: Time zone of date + * - parameter calendar: The calendar to generate the date against. By default it is the current calendar */ - public init(dateString: String, format: String, timeZone: TimeZone) { + public init(dateString: String, format: String, timeZone: TimeZone, calendar: Calendar = Calendar.current) { let dateFormatter = DateFormatter() - dateFormatter.dateStyle = .none; - dateFormatter.timeStyle = .none; - dateFormatter.timeZone = timeZone; - dateFormatter.dateFormat = format; - + dateFormatter.dateStyle = .none + dateFormatter.timeStyle = .none + dateFormatter.timeZone = timeZone + dateFormatter.dateFormat = format + dateFormatter.calendar = calendar + guard let date = dateFormatter.date(from: dateString) else { self = Date() return diff --git a/DateToolsSwift/DateTools/DateTools.bundle/fa.lproj/DateTools.strings b/DateToolsSwift/DateTools/DateTools.bundle/fa.lproj/DateTools.strings new file mode 100644 index 00000000..8dfd1036 Binary files /dev/null and b/DateToolsSwift/DateTools/DateTools.bundle/fa.lproj/DateTools.strings differ diff --git a/DateToolsSwift/Tests/DateToolsTests/DateToolsTestsTests/DateInitsExtensionTests.swift b/DateToolsSwift/Tests/DateToolsTests/DateToolsTestsTests/DateInitsExtensionTests.swift index 3809a53e..c5f8a18e 100644 --- a/DateToolsSwift/Tests/DateToolsTests/DateToolsTestsTests/DateInitsExtensionTests.swift +++ b/DateToolsSwift/Tests/DateToolsTests/DateToolsTestsTests/DateInitsExtensionTests.swift @@ -33,7 +33,14 @@ class DateDateToolsTests: XCTestCase { let testDate = Date(year: 2011, month: 12, day: 25) XCTAssertTrue(testDate.year == controlDate.year && testDate.month == controlDate.month && testDate.day == controlDate.day) } - + + func testInitWithDatestringFormatTimezoneCalendar() { + let testDate = Date(dateString: "2011 12 25 4:30:30.000", format: "yyyy MM dd HH:mm:ss.SSS", timeZone: TimeZone(abbreviation: "CST")!, calendar: Calendar(identifier: .persian)) + self.formatter.timeZone = TimeZone(abbreviation: "CST") + controlDate = self.formatter.date(from: "2633 03 16 4:30:30.000")! + XCTAssertTrue(testDate == controlDate) + } + func testInitWithDatestringFormatTimezone() { let testDate = Date(dateString: "2011 12 25 4:30:30.000", format: "yyyy MM dd HH:mm:ss.SSS", timeZone: TimeZone(abbreviation: "CST")!) self.formatter.timeZone = TimeZone(abbreviation: "CST")