Skip to content

Commit

Permalink
Merge branch 'release/4.0.13'
Browse files Browse the repository at this point in the history
  • Loading branch information
malcommac committed Feb 12, 2017
2 parents 5264e48 + edcbfd2 commit 96a2346
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 6 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)**
Expand All @@ -21,6 +22,16 @@

<a name="412" />

## 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
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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!

Expand Down
7 changes: 6 additions & 1 deletion Sources/SwiftDate/Commons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions Sources/SwiftDate/DateInRegion+Formatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion Sources/SwiftDate/DateInRegion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))"
Expand All @@ -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!
}

Expand Down Expand Up @@ -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
Expand Down
56 changes: 56 additions & 0 deletions Sources/SwiftDate/SwiftDate.bundle/ar-SA.lproj/SwiftDate.strings
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion SwiftDate.podspec
Original file line number Diff line number Diff line change
@@ -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' }
Expand Down
4 changes: 2 additions & 2 deletions SwiftDate/SwiftDate.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 96a2346

Please sign in to comment.