Skip to content

Commit

Permalink
Merge branch 'release/4.1.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
dan committed Jul 6, 2017
2 parents 14b3f30 + 7f94378 commit eb25dc6
Show file tree
Hide file tree
Showing 37 changed files with 1,923 additions and 1,358 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

## CHANGELOG

* Version **[4.1.6](#416)**
* Version **[4.1.2](#412)**
* Version **[4.1.1](#411)**
* Version **[4.1.0](#410)**
Expand All @@ -24,6 +25,19 @@
* Version **[4.0.2](#402)**
* Version **[4.0.0](#400)**

<a name="416" />

## SwiftDate 4.1.6
---
- **Release Date**: 2017-07-06
- **Zipped Version**: [Download 4.1.6](https://github.com/malcommac/SwiftDate/releases/tag/4.1.6)

#### New Features
- [#446](https://github.com/malcommac/SwiftDate/pull/446) Added Hungarian support (thanks to @iKiKi)

#### Fixes
- [#445](https://github.com/malcommac/SwiftDate/pull/445) Fixed an issue which causes wrong results while using algebra operations with time components.

<a name="412" />

## SwiftDate 4.1.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>4.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2016 Daniele Margutti. All rights reserved.</string>
<string>Copyright © 2017 Daniele Margutti. All rights reserved.</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import PackageDescription

let package = Package(
name: "SwiftDate"
name: "SwiftDate"
)
5 changes: 3 additions & 2 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.1.1/)**
* The **latest [full class documentation is available here](http://cocoadocs.org/docsets/SwiftDate/4.1.6/)**

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.1.1 [Download here](https://github.com/malcommac/SwiftDate/releases/tag/4.1.1).
Latest release is: 4.1.6 [Download here](https://github.com/malcommac/SwiftDate/releases/tag/4.1.6).

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

Expand Down Expand Up @@ -89,6 +89,7 @@ Currently SwiftDate supports:
* 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)
* Hungarian (made by [@iKiKi](https://github.com/iKiKi), since 4.16)

Make a pull request and add your language!

Expand Down
7 changes: 7 additions & 0 deletions Sources/SwiftDate/DateComponents+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ public extension DateComponents {
if left != nil && right != nil && left != Int(NSDateComponentUndefined) && right != Int(NSDateComponentUndefined) {
let value = left! + (right! * multipler)
newCmps.setValue(value, for: component)
} else {
if left != nil && left != Int(NSDateComponentUndefined) {
newCmps.setValue(left!, for: component)
}
if right != nil && right != Int(NSDateComponentUndefined) {
newCmps.setValue(right!, for: component)
}
}
}
return newCmps
Expand Down
108 changes: 43 additions & 65 deletions Sources/SwiftDate/DateInRegionFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,76 +189,54 @@ public class DateInRegionFormatter {
let cal = fDate.region.calendar
let cmp = cal.dateComponents(self.allowedComponents, from: fDate.absoluteDate, to: tDate.absoluteDate)
let isFuture = (fDate > tDate)
let diff_in_seconds = abs(fDate.absoluteDate.timeIntervalSince(tDate.absoluteDate))

if cmp.year != nil && (cmp.year != 0 || !hasLowerAllowedComponents(than: .year)) {
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: abs(fDate.year))
return (colloquial_date,colloquial_time)
}

if cmp.month != nil && (cmp.month != 0 || !hasLowerAllowedComponents(than: .month)) {
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: abs(cmp.month!))
return (colloquial_date,colloquial_time)
}
if cmp.year != nil && (cmp.year != 0 || !hasLowerAllowedComponents(than: .year)) {
let colloquial_time = try self.colloquial_time(forUnit: .year, withValue: cmp.year!, date: fDate)
let value = (cmp.year == 1 ? cmp.year! : fDate.year)
let colloquial_date = try self.localized(unit: .year, withValue: value, asFuture: isFuture, args: abs(value))
return (colloquial_date,colloquial_time)
}

// This represent the difference, expressed in hours, between our two dates
let diff_in_hours: Int = Int((diff_in_seconds / 60 / 60))
let diff_days: Int! = abs(cmp.day ?? 0)
if cmp.month != nil && (cmp.month != 0 || !hasLowerAllowedComponents(than: .month)) {
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: abs(cmp.month!))
return (colloquial_date,colloquial_time)
}

if diff_in_hours < 24 && diff_days == 0 {
// Difference between dates is less than 24 hours
// We want to print hour differences in this case
let colloquial_time = try self.colloquial_time(forUnit: .hour, withValue: cmp.hour!, date: fDate)
let colloquial_date = try self.localized(unit: .hour, withValue: diff_in_hours, asFuture: isFuture, args: abs(diff_in_hours))
return (colloquial_date,colloquial_time)

} else if (diff_days > 0 || !hasLowerAllowedComponents(than: .day)) {
// Difference is more than 1 days
if diff_in_hours > 48 {
if diff_days >= DAYS_IN_WEEK {
// More than 7 days, we want to print weeks unit
let colloquial_time = try self.colloquial_time(forUnit: .day, withValue: cmp.day!, date: fDate)
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)
} else {
// Between 2 days and 6 days, we want to print days
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: abs(cmp.day!))
return (colloquial_date,colloquial_time)
}
} else {
// Less than a day, dates may live in two days but the difference maybe few hours
// For example 05/01 23:00 <-> 06/01 01:30 -> differences is 2:30 hours and not one day.
let colloquial_time = try self.colloquial_time(forUnit: .hour, withValue: cmp.hour!, date: fDate)
let colloquial_date = try self.localized(unit: .hour, withValue: diff_in_hours, asFuture: isFuture, args: abs(diff_in_hours))
return (colloquial_date,colloquial_time)
}
}

if cmp.hour != nil && (cmp.hour != 0 || !hasLowerAllowedComponents(than: .hour)) {
if cmp.day != nil && (cmp.day != 0 || !hasLowerAllowedComponents(than: .day)) {
// Week ago
if cmp.day! >= DAYS_IN_WEEK {
let colloquial_time = try self.colloquial_time(forUnit: .day, withValue: cmp.day!, date: fDate)
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)
}
// Day ago
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: abs(cmp.day!))
return (colloquial_date,colloquial_time)
}

if cmp.hour != nil && (cmp.hour != 0 || !hasLowerAllowedComponents(than: .hour)) {
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: abs(cmp.hour!))
return (colloquial_date,colloquial_time)
}
if cmp.minute != nil && (cmp.minute != 0 || !hasLowerAllowedComponents(than: .minute)) {
if let value = self.imminentInterval, (value > 1 && value < 60), (abs(cmp.minute!) < value) {
// A valid `imminentInterval` should be set. Valid interval must be between 1 and 60 minutes (not inclueded)
let colloquial_date = try self.stringLocalized(identifier: "colloquial_now", arguments: [])
return (colloquial_date,nil)
}
// otherwise fallback to difference
let colloquial_date = try self.localized(unit: .minute, withValue: cmp.minute!, asFuture: isFuture, args: abs(cmp.minute!))
return (colloquial_date,nil)
}
if cmp.second != nil && (cmp.second != 0 || cmp.second == 0) { // Seconds difference
let colloquial_date = try self.stringLocalized(identifier: "colloquial_now", arguments: [])
return (colloquial_date,nil)
}
}

if cmp.minute != nil && (cmp.minute != 0 || !hasLowerAllowedComponents(than: .minute)) {
if let value = self.imminentInterval, (value > 1 && value < 60), (abs(cmp.minute!) < value) {
// A valid `imminentInterval` should be set. Valid interval must be between 1 and 60 minutes (not inclueded)
let colloquial_date = try self.stringLocalized(identifier: "colloquial_now", arguments: [])
return (colloquial_date,nil)
}
// otherwise fallback to difference
let colloquial_date = try self.localized(unit: .minute, withValue: cmp.minute!, asFuture: isFuture, args: abs(cmp.minute!))
return (colloquial_date,nil)
}

if cmp.second != nil && (cmp.second != 0 || cmp.second == 0) { // Seconds difference
let colloquial_date = try self.stringLocalized(identifier: "colloquial_now", arguments: [])
return (colloquial_date,nil)
}

throw DateError.FailedToCalculate
}
Expand Down
56 changes: 56 additions & 0 deletions Sources/SwiftDate/SwiftDate.bundle/hu-HU.lproj/SwiftDate.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// COLLOQUIAL STRINGD
"colloquial_f_y" = "következő év"; // year,future,singular: "next year"
"colloquial_f_yy" = "%d-ban"; // year,future,plural: "on 2016"
"colloquial_p_y" = "tavaly"; // year,past,singular: "last year"
"colloquial_p_yy" = "%d"; // year,past,plural: "2015"

"colloquial_f_m" = "következő hónap"; // month,future,singular: "next month"
"colloquial_f_mm" = "%d hónapon belül"; // month,future,plural: "in 3 months"
"colloquial_p_m" = "múlt hónapban"; // month,past,singular: "past month"
"colloquial_p_mm" = "% hónapja"; // month,past,plural: "3 months ago"

"colloquial_f_w" = "jövő héten"; // week,future,singular: "next week"
"colloquial_f_ww" = "%d hét alatt"; // week,future,plural: "in 3 weeks"
"colloquial_p_w" = "múlt héten"; // week,past,singular: "past week"
"colloquial_p_ww" = "%d hete"; // week,past,plural: "in 3 weeks"

"colloquial_f_d" = "holnap"; // day,future,singular: "tomorrow"
"colloquial_f_dd" = "%d napon belül"; // day,future,plural: "in 3 days"
"colloquial_p_d" = "tegnap"; // day,past,singular: "yesterday"
"colloquial_p_dd" = "%d napja"; // day,past,plural: "3 days ago"

"colloquial_f_h" = "egy óra alatt"; // hour,future,singular: "in one hour"
"colloquial_f_hh" = "%d óra alatt"; // hour,future,plural: "in 3 hours"
"colloquial_p_h" = "egy órája"; // hour,past,singular: "one hour ago"
"colloquial_p_hh" = "% órája"; // hour,past,plural: "3 hours ago"

"colloquial_f_M" = "egy perc alatt"; // minute,future,singular: "in one minute"
"colloquial_f_MM" = "%d perc alatt"; // minute,future,plural: "in 3 minutes"
"colloquial_p_M" = "egy perce"; // minute,past,singular: "one minute ago"
"colloquial_p_MM" = "% perce"; // minute,past,plural: "3 minutes ago"

"colloquial_now" = "épp most"; // less than 5 minutes if .allowsNowOnColloquial is set

"colloquial_n_0y" = "idén"; // this year
"colloquial_n_0m" = "ebben a hónapban"; // this month
"colloquial_n_0w" = "ezen a héten"; // this week
"colloquial_n_0d" = "ma"; // this day
"colloquial_n_0h" = "most"; // this hour
"colloquial_n_0M" = "most"; // this minute
"colloquial_n_0s" = "most"; // 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" = "HH:mm 'órakor'"; // for colloquial day (=+-1) adds a time string like this: "(At 13:20)"
"relevanttime_hh" = "HH:mm 'órakor'"; // 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
Loading

0 comments on commit eb25dc6

Please sign in to comment.