From 87edcd567fd1b3bcda2df0a92bd3f72c73bfbadf Mon Sep 17 00:00:00 2001 From: Abdualrhman Basim Date: Wed, 8 Feb 2017 15:20:06 +0300 Subject: [PATCH 1/4] add Arabic language --- .../ar-SA.lproj/SwiftDate.strings | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Sources/SwiftDate/SwiftDate.bundle/ar-SA.lproj/SwiftDate.strings diff --git a/Sources/SwiftDate/SwiftDate.bundle/ar-SA.lproj/SwiftDate.strings b/Sources/SwiftDate/SwiftDate.bundle/ar-SA.lproj/SwiftDate.strings new file mode 100644 index 00000000..269bfbd4 --- /dev/null +++ b/Sources/SwiftDate/SwiftDate.bundle/ar-SA.lproj/SwiftDate.strings @@ -0,0 +1,56 @@ +// COLLOQUIAL STRINGD +"colloquial_f_y" = "السنة القادمة"; // year,future,singular: "next year" +"colloquial_f_yy" = "في %d"; // year,future,plural: "on 2016" +"colloquial_p_y" = "السنة الماضية"; // year,past,singular: "last year" +"colloquial_p_yy" = "%d"; // year,past,plural: "2015" + +"colloquial_f_m" = "الشهر القادم"; // month,future,singular: "next month" +"colloquial_f_mm" = "خلال %d أشهر"; // month,future,plural: "in 3 months" +"colloquial_p_m" = "الشهر الماضي"; // month,past,singular: "past month" +"colloquial_p_mm" = "منذ %d أشهر"; // month,past,plural: "3 months ago" + +"colloquial_f_w" = "الأسبوع القادم"; // week,future,singular: "next week" +"colloquial_f_ww" = "خلال %d أسابيع"; // week,future,plural: "in 3 weeks" +"colloquial_p_w" = "الأسبوع الماضي"; // week,past,singular: "past week" +"colloquial_p_ww" = "منذ %d أسابيع"; // week,past,plural: "in 3 weeks" + +"colloquial_f_d" = "غداً"; // day,future,singular: "tomorrow" +"colloquial_f_dd" = "خلال %d أيام"; // day,future,plural: "in 3 days" +"colloquial_p_d" = "الأمس"; // day,past,singular: "yesterday" +"colloquial_p_dd" = "منذ %d أيام"; // day,past,plural: "3 days ago" + +"colloquial_f_h" = "خلال ساعة"; // hour,future,singular: "in one hour" +"colloquial_f_hh" = "خلال %d ساعات"; // hour,future,plural: "in 3 hours" +"colloquial_p_h" = "منذ ساعة"; // hour,past,singular: "one hour ago" +"colloquial_p_hh" = "منذ %d ساعات"; // hour,past,plural: "3 hours ago" + +"colloquial_f_M" = "خلال دقيقة"; // minute,future,singular: "in one minute" +"colloquial_f_MM" = "خلال %d دقائق"; // minute,future,plural: "in 3 minutes" +"colloquial_p_M" = "منذ دقيقة"; // minute,past,singular: "one minute ago" +"colloquial_p_MM" = "منذ %d دقائق"; // minute,past,plural: "3 minutes ago" + +"colloquial_now" = "الأن"; // less than 5 minutes if .allowsNowOnColloquial is set + +"colloquial_n_0y" = "هذه السنة"; // this year +"colloquial_n_0m" = "هذا الشهر"; // this month +"colloquial_n_0w" = "هذا الأسبوع"; // this week +"colloquial_n_0d" = "اليوم"; // this day +"colloquial_n_0h" = "الأن"; // this hour +"colloquial_n_0M" = "الأن"; // this minute +"colloquial_n_0s" = "الأن"; // this second + +// RELEVANT TIME TO PRINT ALONG COLLOQUIAL STRING WHEN .includeRelevantTime = true +"relevanttime_y" = "MMM yyyy"; // for colloquial year (=+-1) adds a time string like this:"(Feb 2016)" +"relevanttime_yy" = "MMM yyyy"; // for colloquial years (>1) adds a time string like this:"(Feb 2016)" +"relevanttime_m" = "MMM, dd yyyy"; // for colloquial month (=+-1) adds a time string like this:"(Feb 17, 2016)" +"relevanttime_mm" = "MMM, dd yyyy"; // for colloquial months (>1) adds a time string like this: "(Feb 17, 2016)" +"relevanttime_w" = "EEE, MMM dd"; // for colloquial months (>1) adds a time string like this: "(Wed Feb 17)" +"relevanttime_ww" = "EEE, MMM dd"; // for colloquial months (>1) adds a time string like this: "(Wed Feb 17)" +"relevanttime_d" = "EEE, MMM dd"; // for colloquial day (=+-1) adds a time string like this: "(Wed Feb 17)" +"relevanttime_dd" = "EEE, MMM dd"; // for colloquial days (>1) adds a time string like this: "(Wed Feb 17)" +"relevanttime_h" = "'at' h:mm a"; // for colloquial day (=+-1) adds a time string like this: "(At 13:20)" +"relevanttime_hh" = "'at' h:mm a"; // for colloquial days (>1) adds a time string like this: "(At 13:20)" +"relevanttime_M" = ""; // for colloquial minute(s) we have not any relevant time to print +"relevanttime_MM" = ""; // for colloquial minute(s) we have not any relevant time to print +"relevanttime_s" = ""; // for colloquial seconds(s) we have not any relevant time to print +"relevanttime_ss" = ""; // for colloquial seconds(s) we have not any relevant time to print From 35308da8057ad62d129645dd5e2655a73b7c9f0b Mon Sep 17 00:00:00 2001 From: Daniele Margutti Date: Wed, 8 Feb 2017 14:39:23 +0100 Subject: [PATCH 2/4] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 89b695e0..f1722b73 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,7 @@ Currently SwiftDate supports: * Brazilian Portuguese (made by [ipedro](https://github.com/ipedro), since 4.0.11) * Hebrew (made by [@ilandbt](https://github.com/ilandbt), since 4.0.12) * Swedish (made by [@traneHead](https://github.com/traneHead), since 4.0.12) +* Arabic (made by [@abdualrhmanIO](https://github.com/abdualrhmanIO), since 4.0.13) Make a pull request and add your language! From 5ede1940500ee3ef89ee5932a369ca569ead9b2e Mon Sep 17 00:00:00 2001 From: daniele margutti Date: Sun, 12 Feb 2017 11:17:25 +0100 Subject: [PATCH 3/4] Added strict formatter Added `strict` formatter for dates. Using `strict` instead of `custom` disable heuristics date guessing of the formatter (ie. 1999-02-31 become an invalid date to parse, while with heuristics enabled 1999-03-03 is returned instead). --- Sources/SwiftDate/Commons.swift | 7 ++++++- Sources/SwiftDate/DateInRegion+Formatter.swift | 2 ++ Sources/SwiftDate/DateInRegion.swift | 8 +++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Sources/SwiftDate/Commons.swift b/Sources/SwiftDate/Commons.swift index 6abc5455..1fe7f0f0 100644 --- a/Sources/SwiftDate/Commons.swift +++ b/Sources/SwiftDate/Commons.swift @@ -88,13 +88,18 @@ public enum DateError: Error { /// Available date formats used to parse strings and format date into string /// -/// - custom: custom format expressed in Unicode tr35-31 (see http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_Patterns and Apple's Date Formatting Guide) +/// - custom: custom format expressed in Unicode tr35-31 (see http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_Patterns and Apple's Date Formatting Guide). Formatter uses heuristics to guess the date if it's invalid. +/// This may end in a wrong parsed date. Use `strict` to disable heuristics parsing. +/// - strict: strict format is like custom but does not apply heuristics to guess at the date which is intended by the string. +/// So, if you pass an invalid date (like 1999-02-31) formatter fails instead of returning guessing date (in our case +/// 1999-03-03). /// - iso8601: iso8601 date format (see https://en.wikipedia.org/wiki/ISO_8601) /// - extended: extended date format ("eee dd-MMM-yyyy GG HH:mm:ss.SSS zzz") /// - rss: RSS and AltRSS date format /// - dotNET: .NET date format public enum DateFormat { case custom(String) + case strict(String) case iso8601(options: ISO8601DateTimeFormatter.Options) case extended case rss(alt: Bool) diff --git a/Sources/SwiftDate/DateInRegion+Formatter.swift b/Sources/SwiftDate/DateInRegion+Formatter.swift index 1406f65d..a2b6ad3b 100644 --- a/Sources/SwiftDate/DateInRegion+Formatter.swift +++ b/Sources/SwiftDate/DateInRegion+Formatter.swift @@ -58,6 +58,8 @@ public extension DateInRegion { switch format { case .custom(let format): return self.formatters.dateFormatter(format: format).string(from: self.absoluteDate) + case .strict(let format): + return self.formatters.dateFormatter(format: format).string(from: self.absoluteDate) case .iso8601(let options): let formatter = self.formatters.isoFormatter(options: options) return formatter.string(from: self.absoluteDate) diff --git a/Sources/SwiftDate/DateInRegion.swift b/Sources/SwiftDate/DateInRegion.swift index 70286a76..5f2789f1 100644 --- a/Sources/SwiftDate/DateInRegion.swift +++ b/Sources/SwiftDate/DateInRegion.swift @@ -106,7 +106,7 @@ public class DateInRegion: CustomStringConvertible { /// - parameter format: if not nil a new `.dateFormat` is also set /// /// - returns: a new instance of the formatter - public func dateFormatter(format: String? = nil) -> DateFormatter { + public func dateFormatter(format: String? = nil, heuristics: Bool = true) -> DateFormatter { var formatter: DateFormatter? = nil if useSharedFormatters == true { let name = "SwiftDate_\(NSStringFromClass(DateFormatter.self))" @@ -125,6 +125,7 @@ public class DateInRegion: CustomStringConvertible { formatter!.timeZone = self.timeZone formatter!.calendar = self.calendar formatter!.locale = self.locale + formatter!.isLenient = heuristics return formatter! } @@ -236,6 +237,11 @@ public class DateInRegion: CustomStringConvertible { throw DateError.FailedToParse } self.absoluteDate = date + case .strict(let format): + guard let date = self.formatters.dateFormatter(format: format, heuristics: false).date(from: string) else { + throw DateError.FailedToParse + } + self.absoluteDate = date case .iso8601(let options): guard let date = self.formatters.isoFormatter(options: options).date(from: string) else { throw DateError.FailedToParse From 8f04d322ea15b8aa611172613cc858b3af596189 Mon Sep 17 00:00:00 2001 From: daniele margutti Date: Sun, 12 Feb 2017 11:29:07 +0100 Subject: [PATCH 4/4] Updated changelog and readme for 4.0.13 --- CHANGELOG.md | 11 +++++++++++ README.md | 2 +- SwiftDate.podspec | 2 +- SwiftDate/SwiftDate.xcodeproj/project.pbxproj | 4 ++-- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9d2b75e..1b0c7d3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ## CHANGELOG +* Version **[4.0.13](#413)** * Version **[4.0.12](#412)** * Version **[4.0.11](#411)** * Version **[4.0.10](#410)** @@ -21,6 +22,16 @@ +## SwiftDate 4.0.13 +--- +- **Release Date**: 2017/02/12 +- **Zipped Version**: [Download 4.0.13](https://github.com/malcommac/SwiftDate/releases/tag/4.0.13) + +#### New Features +- [#384](https://github.com/malcommac/SwiftDate/pull/384) Added Arabic translation (thanks to @abdualrhmanIO) +- [#356](https://github.com/malcommac/SwiftDate/pull/356) Added a new formatter option called `strict`. Using `strict` instead of `custom` disable heuristics date guessing of the formatter (ie. 1999-02-31 become an invalid date to parse, while with heuristics enabled guessing date 1999-03-03 is returned instead). + + ## SwiftDate 4.0.12 --- - **Release Date**: 2017/01/30 diff --git a/README.md b/README.md index f1722b73..55c54664 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ You can also generate the latest documentation using [Jazzy](https://github.com/ ## Current Release -Latest release is: 4.0.12 [Download here](https://github.com/malcommac/SwiftDate/releases/tag/4.0.12). +Latest release is: 4.0.13 [Download here](https://github.com/malcommac/SwiftDate/releases/tag/4.0.13). A complete list of changes for each release is available in the [CHANGELOG](CHANGELOG.md) file. diff --git a/SwiftDate.podspec b/SwiftDate.podspec index 143810a2..1447b216 100644 --- a/SwiftDate.podspec +++ b/SwiftDate.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'SwiftDate' - spec.version = '4.0.12' + spec.version = '4.0.13' spec.summary = 'The best way to deal with Dates & Time Zones in Swift' spec.homepage = 'https://github.com/malcommac/SwiftDate' spec.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/SwiftDate/SwiftDate.xcodeproj/project.pbxproj b/SwiftDate/SwiftDate.xcodeproj/project.pbxproj index b759181e..691d8f2c 100644 --- a/SwiftDate/SwiftDate.xcodeproj/project.pbxproj +++ b/SwiftDate/SwiftDate.xcodeproj/project.pbxproj @@ -1058,7 +1058,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 12; + CURRENT_PROJECT_VERSION = 13; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -1111,7 +1111,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 12; + CURRENT_PROJECT_VERSION = 13; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES;