Skip to content

Commit

Permalink
Merge branch 'release/6.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
malcommac committed Apr 16, 2019
2 parents 8da3c1c + aa7977b commit a462ce3
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Documentation/0.Informations.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ $ brew install carthage
To integrate SwiftDate into your Xcode project using Carthage, specify it in your `Cartfile`:

```ogdl
github "malcommac/SwiftDate" ~> 5.0
github "malcommac/SwiftDate" ~> 6.0
```

Run `carthage update` to build the framework and drag the built `SwiftDate.framework` into your Xcode project.
Expand Down
2 changes: 1 addition & 1 deletion Documentation/1.Introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ However this is a special region called **Default Region** and - by default - it

- **Time Zone** = GMT - this allows to keep a coerent behaviour with the default Date managment unless you change it.
- **Calendar** = current's device calendar (auto updating)
- **Locale** = current's device lcoale (auto updating)
- **Locale** = current's device locale (auto updating)

While it's a good choice to always uses `DateInRegion` you can also work with `Date` by changing the default region as follow:

Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftDate/Formatters/Formatter+Protocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public protocol StringToDateTransformable {
/// - rss: The RSS formatted date "EEE, d MMM yyyy HH:mm:ss ZZZ" i.e. "Fri, 09 Sep 2011 15:26:08 +0200"
/// - altRSS: The Alternative RSS formatted date "d MMM yyyy HH:mm:ss ZZZ" i.e. "09 Sep 2011 15:26:08 +0200"
/// - dotNet: The dotNet formatted date "/Date(%d%d)/" i.e. "/Date(1268123281843)/"
/// - httpHeader: The http header formatted date "EEE, dd MM yyyy HH:mm:ss zzz" i.e. "Tue, 15 Nov 1994 12:45:26 GMT"
/// - httpHeader: The http header formatted date "EEE, dd MMM yyyy HH:mm:ss zzz" i.e. "Tue, 15 Nov 1994 12:45:26 GMT"
/// - custom: custom string format
/// - standard: A generic standard format date i.e. "EEE MMM dd HH:mm:ss Z yyyy"
/// - date: Date only format (short = "2/27/17", medium = "Feb 27, 2017", long = "February 27, 2017", full = "Monday, February 27, 2017"
Expand Down Expand Up @@ -88,7 +88,7 @@ public enum DateToStringStyles {
/// - rss: The RSS formatted date "EEE, d MMM yyyy HH:mm:ss ZZZ" i.e. "Fri, 09 Sep 2011 15:26:08 +0200"
/// - altRSS: The Alternative RSS formatted date "d MMM yyyy HH:mm:ss ZZZ" i.e. "09 Sep 2011 15:26:08 +0200"
/// - dotNet: The dotNet formatted date "/Date(%d%d)/" i.e. "/Date(1268123281843)/"
/// - httpHeader: The http header formatted date "EEE, dd MM yyyy HH:mm:ss zzz" i.e. "Tue, 15 Nov 1994 12:45:26 GMT"
/// - httpHeader: The http header formatted date "EEE, dd MMM yyyy HH:mm:ss zzz" i.e. "Tue, 15 Nov 1994 12:45:26 GMT"
/// - strict: custom string format with lenient options active
/// - custom: custom string format
/// - standard: A generic standard format date i.e. "EEE MMM dd HH:mm:ss Z yyyy"
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDate/Formatters/ISOFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class ISOFormatter: DateToStringTrasformable {

/// Evaluate formatting string
public var dateFormat: String {
if contains(.withInternetDateTimeExtended) {
if contains(.withInternetDateTimeExtended) || contains(.withoutTZSeparators) {
if contains(.withoutTZSeparators) {
return "yyyy-MM-dd'T'HH:mm:ss.SSSZZZ"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

import Foundation

#if os(Linux)
import Glibc
#else
import Darwin
#endif

/// Languages table.
/// In order to be fully compatible with Linux environment we need to
/// handle directly with .swift files instead of plain text files.
Expand Down Expand Up @@ -151,10 +157,10 @@ public extension RelativeFormatter {
case flooring
case custom((Double) -> Double)

func round(_ value: Double) -> Double {
func roundValue(_ value: Double) -> Double {

switch self {
case .regularRound: return Darwin.round(value)
case .regularRound: return round(value)
case .ceiling: return ceil(value)
case .flooring: return floor(value)
case .custom(let roundingFunction): return roundingFunction(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,25 @@ public class RelativeFormatter: DateToStringTrasformable {
///
/// - Parameter locale: locale to load
/// - Returns: language table
private func language(forLocale locale: Locale) -> RelativeFormatterLang {
let localeId = (locale.collatorIdentifier ?? Locales.english.toLocale().collatorIdentifier!)
guard let table = languagesCache[localeId] else {
var tableType = languagesMap[localeId]
if tableType == nil {
tableType = languagesMap[localeId.components(separatedBy: "-").first!]
if tableType == nil {
return language(forLocale: Locales.english.toLocale())
}
}
let instanceOfTable = tableType!.init()
languagesCache[localeId] = instanceOfTable
return instanceOfTable
}
return table
}
private func language(forLocale locale: Locale) -> RelativeFormatterLang {
let localeId = (locale.collatorIdentifier ?? Locales.english.toLocale().collatorIdentifier!)
guard let table = languagesCache[localeId] else {
var tableType = languagesMap[localeId]
if tableType == nil {
tableType = languagesMap[localeId.components(separatedBy: "_").first!]
if tableType == nil {
tableType = languagesMap[localeId.components(separatedBy: "-").first!]
}
if tableType == nil {
return language(forLocale: Locales.english.toLocale())
}
}
let instanceOfTable = tableType!.init()
languagesCache[localeId] = instanceOfTable
return instanceOfTable
}
return table
}

/// Implementation of the protocol for DateToStringTransformable.
public static func format(_ date: DateRepresentable, options: Any?) -> String {
Expand Down Expand Up @@ -238,7 +241,7 @@ public class RelativeFormatter: DateToStringTrasformable {
amount = round(amount / granularity) * granularity
}

let value: Double = -1.0 * Double(elapsed.sign) * suitableRule.roundingStrategy.round(amount)
let value: Double = -1.0 * Double(elapsed.sign) * suitableRule.roundingStrategy.roundValue(amount)
let formatString = relativeFormat(locale: locale, flavour: flavour, value: value, unit: suitableRule.unit)
return formatString.replacingOccurrences(of: "{0}", with: String(Int(abs(value))))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public extension TimeInterval {
formatter.calendar = calendar
}

init() {}
public init() {}
}

/// Return the local thread shared formatter for date components
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftDate/Supports/Commons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ public struct DateFormats {
/// The RSS formatted date "EEE, d MMM yyyy HH:mm:ss ZZZ" i.e. "Fri, 09 Sep 2011 15:26:08 +0200"
public static let rss: String = "EEE, d MMM yyyy HH:mm:ss ZZZ"

/// The http header formatted date "EEE, dd MM yyyy HH:mm:ss zzz" i.e. "Tue, 15 Nov 1994 12:45:26 GMT"
public static let httpHeader: String = "EEE, dd MM yyyy HH:mm:ss zzz"
/// The http header formatted date "EEE, dd MMM yyyy HH:mm:ss zzz" i.e. "Tue, 15 Nov 1994 12:45:26 GMT"
public static let httpHeader: String = "EEE, dd MMM yyyy HH:mm:ss zzz"

/// A generic standard format date i.e. "EEE MMM dd HH:mm:ss Z yyyy"
public static let standard: String = "EEE MMM dd HH:mm:ss Z yyyy"
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 |s|
s.name = "SwiftDate"
s.version = "6.0.1"
s.version = "6.0.2"
s.summary = "The best way to deal with Dates & Time Zones in Swift"
s.homepage = "https://github.com/malcommac/SwiftDate.git"
s.license = { :type => "MIT", :file => "LICENSE" }
Expand Down

0 comments on commit a462ce3

Please sign in to comment.