Skip to content

Commit

Permalink
Merge branch 'feature/4.1.0' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
malcommac committed Mar 31, 2017
2 parents 1c8cd9e + f93ce57 commit af2eca2
Show file tree
Hide file tree
Showing 23 changed files with 1,495 additions and 279 deletions.
97 changes: 86 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

## CHANGELOG

* Version **[4.0.14](#414)**
* Version **[4.0.13](#413)**
* Version **[4.0.12](#412)**
* Version **[4.0.11](#411)**
* Version **[4.0.10](#410)**
* Version **[4.1.0](#410)**
* Version **[4.0.14](#4014)**
* Version **[4.0.13](#4013)**
* Version **[4.0.12](#4012)**
* Version **[4.0.11](#4011)**
* Version **[4.0.10](#4010)**
* Version **[4.0.9](#409)**
* Version **[4.0.8](#408)**
* Version **[4.0.7](#407)**
Expand All @@ -22,17 +23,91 @@
* Version **[4.0.0](#400)**


<a name="414" />
<a name="410" />

## SwiftDate 4.1.0
---
- **Release Date**: 2017/03/31
- **Zipped Version**: [Download 4.1.0](https://github.com/malcommac/SwiftDate/releases/tag/4.1.0)

#### New Features
- [#402](https://github.com/malcommac/SwiftDate/pull/402) Added Greek localization (thanks to @dimmdesign)
- [#399](https://github.com/malcommac/SwiftDate/pull/399) `colloquialSinceNow` also allows to set `unitsStyle` params to specify the type of values you want to print.
- [#400](https://github.com/malcommac/SwiftDate/pull/400) `DateInRegion` has a class func named `date(formats:fromRegion)` which allows parsing a single string with multiple formats (the first one that succeeds returns the instance of the `DateInRegion`). Also available as `String` extension (with the same name).
- [#223](https://github.com/malcommac/SwiftDate/pull/223) `ISO8601DateTimeFormatter` now recognize the timezone of an ISO string and create a date with the correct value.
- [#407](https://github.com/malcommac/SwiftDate/pull/407) SwiftDate now can parse ISO8601 strings without specifyng the ISO format; it evaluates the best format automatically. Also the parser faster than the previous built one. Since now `.iso8601` parsing format is used only as formatter (from date to string, viceversa any given value is ignored. You are encouraged to use `.iso8601Auto` instead).

The following ISO8601 variants are supported:

```
YYYYMMDD
YYYY-MM-DD
YYYY-MM
YYYY
YY //century
//Implied century: YY is 00-99
YYMMDD
YY-MM-DD
-YYMM
-YY-MM
-YY
//Implied year
--MMDD
--MM-DD
--MM
//Implied year and month
---DD
//Ordinal dates: DDD is the number of the day in the year (1-366)
YYYYDDD
YYYY-DDD
YYDDD
YY-DDD
-DDD
//Week-based dates: ww is the number of the week, and d is the number (1-7) of the day in the week
yyyyWwwd
yyyy-Www-d
yyyyWww
yyyy-Www
yyWwwd
yy-Www-d
yyWww
yy-Www
//Year of the implied decade
-yWwwd
-y-Www-d
-yWww
-y-Www
//Week and day of implied year
-Wwwd
-Www-d
//Week only of implied year
-Www
//Day only of implied week
-W-d
```


#### Fixes
- [#405](https://github.com/malcommac/SwiftDate/pull/405) Fixed some translation issues in Swedish (thanks to @deville)
- [#368](https://github.com/malcommac/SwiftDate/pull/368) Deprecated `at(unitsWithValues dict: [Calendar.Component : Int])` in `Date` and `DateInRegion` and replaced with functional `at(values: [Calendar.Component : Int], keep: Set<Calendar.Component>)`
- [#392](https://github.com/malcommac/SwiftDate/pull/392) Fixed an issue with report negative interval when making operation with dates `a` and `b` where `a - b < 0 iff a < b`.
- [#397](https://github.com/malcommac/SwiftDate/pull/397) Fixed an issue with `colloquial` func which report wrong difference of `1 day` when two dates are distant < 24h but in two different days.





<a name="4014" />

## SwiftDate 4.0.14
---
- **Release Date**: -
- **Release Date**: 2017/03/29
- **Zipped Version**: [Download 4.0.14](https://github.com/malcommac/SwiftDate/releases/tag/4.0.14)

- [#404](https://github.com/malcommac/SwiftDate/pull/404) Compatibility with Swift 3.1


<a name="413" />
<a name="4013" />

## SwiftDate 4.0.13
---
Expand All @@ -43,7 +118,7 @@
- [#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).

<a name="412" />
<a name="4012" />

## SwiftDate 4.0.12
---
Expand All @@ -60,7 +135,7 @@
- [#381](https://github.com/malcommac/SwiftDate/pull/381) Replaced `useImminentInterval` in `DateInRegionFormatter` with a configurable value called `imminentInterval`. With a default value of 5 it fallback to `just now` version. If `nil` fallback is disabled.
- [#380](https://github.com/malcommac/SwiftDate/pull/380) `DateInRegionFormatter` is now able to load custom localization both from `LocaleName` and custom `.strings` files (just set the `formatter.localization = Localization(path: [PATH_TO_YOUR_STRINGS_FILE]`)

<a name="411" />
<a name="4011" />

## SwiftDate 4.0.11
---
Expand All @@ -74,7 +149,7 @@
#### New Features
- [#365](https://github.com/malcommac/SwiftDate/issues/365) Brazilian Portuguese support (thanks to @ipedro)

<a name="410" />
<a name="4010" />

## SwiftDate 4.0.10
---
Expand Down
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Take a look here:

## Documentation
* **On [http://malcommac.github.io/SwiftDate/index.html](http://malcommac.github.io/SwiftDate/index.html) to learn more about all available functions with a comprehensive list of examples**
* The **latest [full class documentation is available here](http://cocoadocs.org/docsets/SwiftDate/4.0.8/)**
* The **latest [full class documentation is available here](http://cocoadocs.org/docsets/SwiftDate/4.1.0/)**

Code is documented for Xcode, so you can use the built-in documentation panel to learn more about the library.

Expand All @@ -59,7 +59,7 @@ You can also generate the latest documentation using [Jazzy](https://github.com/

## Current Release

Latest release is: 4.0.14 [Download here](https://github.com/malcommac/SwiftDate/releases/tag/4.0.14).
Latest release is: 4.1.0 [Download here](https://github.com/malcommac/SwiftDate/releases/tag/4.1.0).

A complete list of changes for each release is available in the [CHANGELOG](CHANGELOG.md) file.

Expand All @@ -86,8 +86,9 @@ Currently SwiftDate supports:
* Japanese (made by [bati668](https://github.com/bati668), since 4.0.9)
* 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)
* Swedish (made by [@traneHead](https://github.com/traneHead) and [@deville](https://github.com/deville), since 4.0.12, updated in 4.1.0)
* Arabic (made by [@abdualrhmanIO](https://github.com/abdualrhmanIO), since 4.0.13)
* Greek (made by [@dimmdesign](https://github.com/dimmdesign), since 4.10)

Make a pull request and add your language!

Expand Down Expand Up @@ -119,6 +120,8 @@ target 'TargetName' do
end
```

(use 4.0.13 for Swift 3.0)

Then, run the following command:

```bash
Expand Down Expand Up @@ -148,7 +151,7 @@ Run `carthage` to build the framework and drag the built `SwiftDate.framework` i

Current version is compatible with:

* Swift 3.0+
* Swift 3.1 (4.0.13 is the latest version compatibile with Swift 3)
* iOS 8 or later
* macOS 10.10 or later
* watchOS 2.0 or later
Expand All @@ -157,8 +160,9 @@ Current version is compatible with:

Are you searching for an old (unsupported) SwiftDate version?
Check out:
* Swift 3.0: The latest version compatible is 4.0.13
* [Swift 2.3 Branch](https://github.com/malcommac/SwiftDate/tree/feature/swift_23)
* Swift 2.2: Use version 3.0.8 in CocoaPods
* Swift 2.2: The latest version compatible is 3.0.8


## Credits & License
Expand Down
5 changes: 4 additions & 1 deletion Sources/SwiftDate/Commons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,17 @@ public enum DateError: Error {
/// - 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)
/// - iso8601: ISO8601 date format (see https://en.wikipedia.org/wiki/ISO_8601).
/// - iso8601Auto: ISO8601 date format. You should use it to parse a date (parsers evaluate automatically the format of
/// the ISO8601 string). Passed as options to transform a date to string it's equal to [.withInternetDateTime] options.
/// - 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 iso8601Auto
case extended
case rss(alt: Bool)
case dotNET
Expand Down
13 changes: 12 additions & 1 deletion Sources/SwiftDate/Date+Components.swift
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,21 @@ public extension Date {
///
/// - parameter dict: a dictionary with `Calendar.Component` and it's value
///
/// - throws: throw a `FailedToSetComponent` exception.
/// - throws: throw a `FailedToCalculate` exception.
///
/// - returns: a new `Date` object calculated at given units values
@available(*, deprecated: 4.1.0, message: "This method has know issues. Use at(values:keep:) instead")
public func at(unitsWithValues dict: [Calendar.Component : Int]) throws -> Date {
return try self.inDateDefaultRegion().at(unitsWithValues: dict).absoluteDate
}

/// Create a new instance of the date by keeping passed calendar components and alter
///
/// - Parameters:
/// - values: values to alter in new instance
/// - keep: values to keep from self instance
/// - Returns: a new instance of `DateInRegion` with passed altered values
public func at(values: [Calendar.Component : Int], keep: Set<Calendar.Component>) -> Date? {
return self.inDateDefaultRegion().at(values: values, keep: keep)?.absoluteDate
}
}
40 changes: 1 addition & 39 deletions Sources/SwiftDate/Date+Formatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public extension Date {
/// - returns: colloquial string representation
public func colloquialSinceNow(in region: Region? = nil, unitStyle: DateComponentsFormatter.UnitsStyle = .short, max: Int? = nil, zero: DateZeroBehaviour? = nil, separator: String? = nil) throws -> (colloquial: String, time: String?) {
let srcRegion = region ?? DateDefaultRegion
return try DateInRegion(absoluteDate: self, in: srcRegion).colloquialSinceNow()
return try DateInRegion(absoluteDate: self, in: srcRegion).colloquialSinceNow(style: unitStyle)
}

/// This method produces a colloquial representation of time elapsed between this `DateInRegion` (`self`) and
Expand All @@ -114,22 +114,6 @@ public extension Date {
return try DateInRegion(absoluteDate: self, in: srcRegion).colloquial(toDate: toDateInRegion)
}

/// This method produces a string by printing the interval between self and current Date and output a string where each
/// calendar component is printed.
///
/// - parameter unitStyle: style of the output string
/// - parameter max: max number of the time components to write (nil means no limit)
/// - parameter zero: the behaviour to use with zero value components
/// - parameter separator: separator string between components (default is ',')
///
/// - throws: throw an exception if time components cannot be evaluated
///
/// - returns: string with each time component
@available(*, deprecated: 4.0.3, message: "Use timeComponentsSinceNow(options:shared:) instead")
public func timeComponentsSinceNow(unitStyle: DateComponentsFormatter.UnitsStyle = .short, max: Int? = nil, zero: DateZeroBehaviour? = nil, separator: String? = nil) throws -> String {
return try self.timeComponents(to: Date(), unitStyle: unitStyle, max: max, zero: zero, separator: separator)
}

/// This method produces a string by printing the interval between self and current Date and output a string where each
/// calendar component is printed.
///
Expand All @@ -145,28 +129,6 @@ public extension Date {
return try self.timeComponents(to: Date(), options: options, shared: shared)
}

/// This method produces a string by printing the interval between self and another date and output a string where each
/// calendar component is printed.
///
/// - parameter to: date to compare
/// - parameter region: region in which both dates will be expressed in
/// - parameter unitStyle: style of the output string
/// - parameter max: max number of the time components to write (nil means no limit)
/// - parameter zero: the behaviour to use with zero value components
/// - parameter separator: separator string between components (default is ',')
///
/// - throws: throw an exception if time components cannot be evaluated
///
/// - returns: string with each time component
@available(*, deprecated: 4.0.3, message: "Use timeComponents(to:options:shared:) instead")
public func timeComponents(to: Date, in region: Region? = nil, unitStyle: DateComponentsFormatter.UnitsStyle = .short, max: Int? = nil, zero: DateZeroBehaviour? = nil, separator: String? = nil) throws -> String {

let srcRegion = region ?? DateDefaultRegion
let fromDateInRegion = DateInRegion(absoluteDate: self, in: srcRegion)
let toDateInRegion = DateInRegion(absoluteDate: to, in: srcRegion)
return try fromDateInRegion.timeComponents(toDate: toDateInRegion, unitStyle: unitStyle, max: max, zero: zero, separator: separator)
}

/// This method produces a string by printing the interval between self and another date and output a string where each
/// calendar component is printed.
///
Expand Down
6 changes: 1 addition & 5 deletions Sources/SwiftDate/DateComponents+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,7 @@ public extension DateComponents {
/// It's the same of `DateInRegion(components:)` init func but it may return nil (instead of throwing an exception)
/// if a valid date cannot be produced.
public var dateInRegion: DateInRegion? {
do {
return try DateInRegion(components: self)
} catch {
return nil
}
return DateInRegion(components: self)
}


Expand Down
23 changes: 22 additions & 1 deletion Sources/SwiftDate/DateInRegion+Components.swift
Original file line number Diff line number Diff line change
Expand Up @@ -514,14 +514,35 @@ extension DateInRegion {
}


/// Create a new instance of the date by keeping passed calendar components and alter
///
/// - Parameters:
/// - values: values to alter in new instance
/// - keep: values to keep from self instance
/// - Returns: a new instance of `DateInRegion` with passed altered values
public func at(values: [Calendar.Component : Int], keep: Set<Calendar.Component>) -> DateInRegion? {
let calendar = self.region.calendar
var newComponents = calendar.dateComponents(keep, from: self.absoluteDate)

values.forEach { newComponents.setValue($0.value, for: $0.key) }

guard let calculatedDate = calendar.date(from: newComponents) else {
return nil
}
return DateInRegion(absoluteDate: calculatedDate, in: self.region)

}

/// Create a new instance calculated by setting a list of components of a given date to given values (components
/// are evaluated serially - in order), while trying to keep lower components the same.
///
/// - parameter dict: a dictionary with `Calendar.Component` and it's value
///
/// - throws: throw a `FailedToSetComponent` exception.
/// - throws: throw a `FailedToCalculate` exception.
///
/// - returns: a new `DateInRegion` object calculated at given units values
@available(*, deprecated: 4.1.0, message: "This method has know issues. Use at(values:keep:) instead")
@discardableResult
public func at(unitsWithValues dict: [Calendar.Component : Int]) throws -> DateInRegion {
var calculatedDate = self.absoluteDate
try DateComponents.allComponents.forEach { component in
Expand Down
Loading

0 comments on commit af2eca2

Please sign in to comment.