Skip to content

Commit

Permalink
Merge branch 'release/4.0.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
malcommac committed Oct 17, 2016
2 parents 7f92f99 + 4144bfc commit 140d3df
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

## CHANGELOG

### SwiftDate 4.0.6
Released on: Mon Oct 17, 2016, [Download](https://github.com/malcommac/SwiftDate/releases/tag/4.0.6)
* [#303](https://github.com/malcommac/SwiftDate/issues/303) `Date.defaultRegion()` is now set to `Region.Local()` as specified in doc (not `Region.GMT()`)
* [#302](https://github.com/malcommac/SwiftDate/issues/302) Fixed an issue with colloquial dates and future dates; also fixed an issue when reporting colloquial differences expressed in weeks
* [#301](https://github.com/malcommac/SwiftDate/issues/301) Add `.locale` property in `ISO8601DateTimeFormatter`

### SwiftDate 4.0.5
Released on: Mon Oct 10, 2016, [Download](https://github.com/malcommac/SwiftDate/releases/tag/4.0.5)
* [#284](https://github.com/malcommac/SwiftDate/issues/284) Fixed a crash with .colloquial() function and # weeks evaluation
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDate/Date+Components.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import Foundation

/// This is the default region set. It will be set automatically at each startup as the local device's region
internal var DateDefaultRegion: Region = Region.GMT()
internal var DateDefaultRegion: Region = Region.Local()

// MARK: - Date Extension to work with date components

Expand Down
1 change: 1 addition & 0 deletions Sources/SwiftDate/DateInRegion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public class DateInRegion: CustomStringConvertible {
}
formatter!.formatOptions = options
formatter!.timeZone = self.timeZone
formatter!.locale = self.locale
return formatter!
}

Expand Down
18 changes: 10 additions & 8 deletions Sources/SwiftDate/DateInRegionFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ public class DateInRegionFormatter {
/// Locale to use when print the date. By default is the same locale set by receiver's `DateInRegion`.
/// If not set default device locale is used instead.
public var locale: Locale?

// number of a days in a week
let DAYS_IN_WEEK = 7

public init() {
}
Expand Down Expand Up @@ -215,33 +218,32 @@ public class DateInRegionFormatter {

if cmp.year != 0 {
let colloquial_time = try self.colloquial_time(forUnit: .year, withValue: cmp.year!, date: fDate)
let colloquial_date = try self.localized(unit: .year, withValue: cmp.year!, asFuture: isFuture, args: fDate.year)
let colloquial_date = try self.localized(unit: .year, withValue: cmp.year!, asFuture: isFuture, args: abs(fDate.year))
return (colloquial_date,colloquial_time)
}

if cmp.month != 0 {
let colloquial_time = try self.colloquial_time(forUnit: .month, withValue: cmp.month!, date: fDate)
let colloquial_date = try self.localized(unit: .month, withValue: cmp.month!, asFuture: isFuture, args: cmp.month!)
let colloquial_date = try self.localized(unit: .month, withValue: cmp.month!, asFuture: isFuture, args: abs(cmp.month!))
return (colloquial_date,colloquial_time)
}

let daysInWeek = fDate.region.calendar.range(of: .day, in: .weekOfMonth, for: fDate.absoluteDate)!.count
if cmp.day! >= daysInWeek {
if abs(cmp.day!) >= DAYS_IN_WEEK {
let colloquial_time = try self.colloquial_time(forUnit: .day, withValue: cmp.day!, date: fDate)
let weeksNo = (abs(cmp.day!) / daysInWeek)
let weeksNo = (abs(cmp.day!) / DAYS_IN_WEEK)
let colloquial_date = try self.localized(unit: .weekOfYear, withValue: weeksNo, asFuture: isFuture, args: weeksNo)
return (colloquial_date,colloquial_time)
}

if cmp.day != 0 {
let colloquial_time = try self.colloquial_time(forUnit: .day, withValue: cmp.day!, date: fDate)
let colloquial_date = try self.localized(unit: .day, withValue: cmp.day!, asFuture: isFuture, args: cmp.day!)
let colloquial_date = try self.localized(unit: .day, withValue: cmp.day!, asFuture: isFuture, args: abs(cmp.day!))
return (colloquial_date,colloquial_time)
}

if cmp.hour != 0 {
let colloquial_time = try self.colloquial_time(forUnit: .hour, withValue: cmp.hour!, date: fDate)
let colloquial_date = try self.localized(unit: .hour, withValue: cmp.hour!, asFuture: isFuture, args: cmp.hour!)
let colloquial_date = try self.localized(unit: .hour, withValue: cmp.hour!, asFuture: isFuture, args: abs(cmp.hour!))
return (colloquial_date,colloquial_time)
}

Expand All @@ -250,7 +252,7 @@ public class DateInRegionFormatter {
let colloquial_date = try self.stringLocalized(identifier: "colloquial_now", arguments: [])
return (colloquial_date,nil)
} else {
let colloquial_date = try self.localized(unit: .minute, withValue: cmp.minute!, asFuture: isFuture, args: cmp.minute!)
let colloquial_date = try self.localized(unit: .minute, withValue: cmp.minute!, asFuture: isFuture, args: abs(cmp.minute!))
return (colloquial_date,nil)
}
}
Expand Down
11 changes: 10 additions & 1 deletion Sources/SwiftDate/ISO8601DateTimeFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,18 @@ public class ISO8601DateTimeFormatter {
return self.formatter.timeZone
}
}

public var locale: Locale? {
get {
return self.formatter.locale
}
set {
self.formatter.locale = newValue
}
}

/// formatter instance used for date
private var formatter: DateFormatter = DateFormatter()
private var formatter: DateFormatter = DateFormatter()

public init() {
self.timeZone = TimeZone(secondsFromGMT: 0)!
Expand Down
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.5'
spec.version = '4.0.6'
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

0 comments on commit 140d3df

Please sign in to comment.