Skip to content

Commit

Permalink
Merge branch 'release/6.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
malcommac committed Nov 15, 2020
2 parents a25913b + 643c8b8 commit 2ef0b18
Show file tree
Hide file tree
Showing 23 changed files with 117 additions and 120 deletions.
4 changes: 2 additions & 2 deletions Documentation/10.Upgrading_SwiftDate4.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ SwiftDate 5.x is a complete rewrite of the library. While it introduces several
**If you miss a features or you are interested in a new one create a new Issue.**

### Important Note about Default Region
In SwiftDate 4.x the default region is automatically set to local region, where all attributes are set automatically to the current's device's locale, timezone and calendar.
In SwiftDate 4.x the default region is automatically set to local region, where all attributes are set automatically to the current device's locale, timezone and calendar.

**Since SwiftDate 5, in order to be more comply with `Date`'s default behaviour, the default region's timezone is set to GMT+0 (UTC)**.

Expand All @@ -39,7 +39,7 @@ func application(_ application: UIApplication, didFinishLaunchingWithOptions lau
- `Date/DateInRegion`: `isAfter()` was renamed to `isAfterDate()`
- `Date/DateInRegion`: `isBefore()` was renamed to `isBeforeDate()`
- `String` extension methods `date(format:fromRegion)` and `date(formats:fromRegion)` are now replaced by `toDate(_:region)` (while similar shortcuts methods are added to parse common formats: `toISODate()`, `toDotNETDate()`, `toRSSDate()` and `toSQLDate()`.
- Removed `Int` extension `second,minute,hour,day,week,month,year` due to inconsistence (use plurar versions `seconds,minutes` etc.
- Removed `Int` extension `second,minute,hour,day,week,month,year` due to inconsistencies (use plural versions `seconds,minutes` etc.
- Related dates generation is now grouped under the `dateAt()` function as enum list. Therefore `nextWeekend`, `previo
- `DateInRegion`: `roundedAt()` is now replaced by `dateRoundedAt()` which now compacts paramters in a single enum.
- `DateInRegion`: `startOf()` and `endOf()` are now replaced by `dateAtStartOf()` and `dateAtEndOf()`and include support for both single and multiple units.
Expand Down
8 changes: 4 additions & 4 deletions Documentation/12.Timer_Periods.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

Dates are important, but the real world is a little less discrete than that. Life is made up of spans of time, like an afternoon appointment or a weeklong vacation. In DateTools, time periods are represented by the TimePeriod class and come with a suite of initializaiton, manipulation, and comparison methods to make working with them a breeze.

Time peroids consist of an Date start date and end date.
Time periods consist of a Date start date and end date.

```swift
let toDate = DateInRegion().dateAtStartOf(.day) // now at 00:00
Expand Down Expand Up @@ -90,7 +90,7 @@ You can also check for the official relationship (like those shown in the chart)
let relationship = periodA.relation(to: periodB)
```

This function return the right value from `TimePeriodRelation` enum.
This function returns the right value from `TimePeriodRelation` enum.

## Time Period Groups

Expand Down Expand Up @@ -122,7 +122,7 @@ collection.append([firstPeriod,secondPeriod])
```

Sorting Sorting time periods in a collection is easy, just call one of the sort methods.
Sorting can take in place (by modifing the original collection) or can return a derivated collection.
Sorting can take in place (by modifying the original collection) or can return a derivated collection.
You can therefore use:

- `sorted(by type: SortType)`: to return a collection with sorted items
Expand All @@ -146,7 +146,7 @@ For instance, if you would like to see all the time periods that intersect with
Time period chains serve as a tightly coupled set of time periods.
They are always organized by start and end date, and have their own characteristics like a `start` and `end` that are extrapolated from the time periods within.
Time period chains do not allow overlaps within their set of time periods.
This type of group is ideal for modeling schedules like sequential meetings or appointments.
This type of group is ideal for modelling schedules like sequential meetings or appointments.

![](TimePeriodChain.png)

Expand Down
14 changes: 7 additions & 7 deletions Documentation/3.Manipulate_Date.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
- [3.2 - Get Interval Between Dates](3.Manipulate_Date.md#interval)
- [3.3 - Convert Date's Region (Locale/TimeZone/Calendar)](3.Manipulate_Date.md#convert)
- [3.4 - Rounding Date](3.Manipulate_Date.md#roundingdate)
- [3.5 - Trouncating Date](3.Manipulate_Date.md#trouncatingdate)
- [3.5 - Truncating Date](3.Manipulate_Date.md#truncatingdate)
- [3.6 - Set Time in Date](3.Manipulate_Date.md#altertimedate)
- [3.7 - Set DateTime Components](3.Manipulate_Date.md#altercomponents)
- [3.8 - Generate Related Dates (`nextYear, nextWeeekday, startOfMonth, startOfWeek, prevMonth`...)](3.Manipulate_Date.md#relateddates)
Expand All @@ -35,7 +35,7 @@ Dates can be manipulated as you need by using classic math operators and readabl

## 3.0 - Add & Subtract Time Units from Date

SwiftDate allows to use numbers to work with time components in dates. By extending the `Int` type it defines a list of time units:
SwiftDate allows you to use numbers to work with time components in dates. By extending the `Int` type it defines a list of time units:

- `nanoseconds`
- `seconds`
Expand Down Expand Up @@ -156,7 +156,7 @@ let days = dateA.getInterval(toDate: dateB, component: .day) // 1 day
<a name="convert"/>

## 3.3 - Convert Date's Region (Locale/TimeZone/Calendar)
`DateInRegion` can be converted easily to anothe region just using `.convertTo(region:)` or `.convertTo(calendar: timezone:locale:)` functions.
`DateInRegion` can be converted easily to another region just using `.convertTo(region:)` or `.convertTo(calendar: timezone:locale:)` functions.

- `convertTo(region:)` convert the receiver date to another region. Region may include a different time zone for example, or a locale.
- `convertTo(calendar:timezone:locale:)` allows to convert the receiver date instance to a specific calendar/timezone/locale. All parameters are optional and only non-nil parameters alter the final region. For a nil param the current receiver's region attribute is kept.
Expand Down Expand Up @@ -209,9 +209,9 @@ let r30min = "2015-01-24 15:07:20".toDate(format: format, region: rome).dateRoun

[^ Top](#index)

<a name="trouncatingdate"/>
<a name="truncatingdate"/>

## 3.5 - Trouncating Date
## 3.5 - Truncating Date
Sometimes you may need to truncate a date by zeroing all values below certain time unit. `.dateTruncated(from:) and .dateTruncated(to:)` functions can be used for this scope.

#### Truncating From
Expand Down Expand Up @@ -265,7 +265,7 @@ let alteredDate = date.dateBySet(hour: 20, min: 13, secs: 15) // 2010-01-01 20:1
<a name="altercomponents"/>

## 3.7 - Set DateTime Components
SwiftDate allows you to return new date representing the date calculated by setting a specific components of a given date to given values, while trying to keep lower components the same (altering more components at the same time may result in different-than-expected results, this because lower components maybe need to be recalculated).
SwiftDate allows you to return a new date representing the date calculated by setting specific components of a given date to given values, while trying to keep lower components the same (altering more components at the same time may result in different-than-expected results, this is because lower components maybe need to be recalculated).

`dateBySet(_ components: [Calendar.Component: Int]) -> DateInRegion?`

Expand All @@ -292,7 +292,7 @@ SwiftDate includes 20+ different "interesting" dates you can obtain by calling `

`func dateAt(_ type: DateRelatedType) -> DateInRegion`

takes just an argument which define the type of date you want to obtain starting from the receiver date.
takes just an argument which defines the type of date you want to obtain starting from the receiver date.
`DateRelatedType` is an enum which has the following options:

- `startOfDay`
Expand Down
6 changes: 3 additions & 3 deletions Documentation/4.Compare_Dates.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- [**Next Chapter**: Date Formatting](#5.Date_Formatting.md)

## Compare Dates
Date comparison is available both via simple math operators (`<,>,<=,>=`) or throught several other functions which allows a more fined control of the comparison.
Date comparison is available both via simple math operators (`<,>,<=,>=`) or throught several other functions which allows a more fined grained control of the comparison.

- [4.0 - Compare Dates](4.Compare_Dates.md#standard)
- [4.1 - Extended Comparison with Presets (`isToday, isTomorrow, isSameWeek, isNextYear` etc.)](4.Compare_Dates.md#extended)
Expand Down Expand Up @@ -102,7 +102,7 @@ let _ = DateInRegion().dateAt(.startOfWeek) - 1.days).compare(.isLastWeek)
<a name="granularity"/>

## 4.2 - Comparison with Granularity
A more fined control for dates comparison can be obtained using the `.compare(toDate:granularity:)` function which offer to returns a `ComparisonResult` value that indicates the ordering of two given dates based on their components down to a given unit granularity.
A more fined grained control for dates comparison can be obtained using the `.compare(toDate:granularity:)` function which offers to return a `ComparisonResult` value that indicates the ordering of two given dates based on their components down to a given unit granularity.

`func compare(toDate refDate: DateInRegion, granularity: Calendar.Component) -> ComparisonResult`

Expand All @@ -122,7 +122,7 @@ Example:
<a name="close"/>

## 4.3 - Check if Date is Close to Another
Decides whether a Date is "close by" another one passed in parameter, where "Being close" is measured using a precision argument which is initialized a 300 seconds (5 minutes) or a specified interval.
Decides whether a Date is "close by" another one passed in parameter, where "Being close" is measured using a precision argument which is initialized with a 300 second interval (5 minute) or a specified interval.

The function is called `.compareCloseTo(_:precision:)` and takes two arguments:

Expand Down
24 changes: 19 additions & 5 deletions Documentation/5.Date_Formatting.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
- [**Next Chapter**: Time Interval Formatting](#6.TimeInterval_Formatting.md)

## Date Formatting
Formatting dates and trasform to string representation is really easy with SwiftDate. All the major formats are supported and are really easy to configure.
Formatting dates and transforms to string representation is really easy with SwiftDate. All the major formats are supported and are really easy to configure.

- [5.0 - Format Custom Style](5.Date_Formatting.md#customformatted)
- [5.1 - ISO8601 Formatted String](5.Date_Formatting.md#isoformatted)
- [5.2 - .NET Formatted String](5.Date_Formatting.md#dotnet)
- [5.3 - RSS/AltRSS Formatted String](5.Date_Formatting.md#rss)
- [5.4 - SQL Formatted String](5.Date_Formatting.md#sql)
- [5.5 - Relative/Colloquial Formatted String](5.Date_Formatting.md#colloquial)
- [5.6 - Mixed Date/Time Style](5.Date_Formatting.md#mixeddatetime)

<a name="customformatted"/>

Expand All @@ -34,7 +35,7 @@ Example:
let rome = Region(calendar: Calendars.gregorian, zone: Zones.europeRome, locale: Locales.italian)
let date = DateInRegion(year: 2015, month: 1, day: 15, hour: 20, minute: 00, second: 5, nanosecond: 0, region: rome)

// Even if date's locale is set to `italin` we can still
// Even if date's locale is set to `italian` we can still
// print in a different language by passing a non nil locale
// to the function.
let formattedString = date.toFormat("MMM dd yyyy", locale: Locales.english) // "Jan 15 2015"
Expand All @@ -44,7 +45,7 @@ let formattedString = date.toFormat("MMM dd yyyy", locale: Locales.english) // "
<a name="isoformatted"/>

## 5.1 - ISO8601 Formatted String
SwiftDate allows to print date instances using a configurable ISO8601 formatter which is also compatible with older version of iOS where the Apple's own class is not available.
SwiftDate allows you to print date instances using a configurable ISO8601 formatter which is also compatible with older versions of iOS where Apple's own class is not available.

To use the ISO formatter call `.toISO()` function

Expand Down Expand Up @@ -124,7 +125,7 @@ let altRSSString = date.toRSS(alt: true) // "20 Jun 2017 14:49:19 +0200"
<a name="sql"/>

## 5.4 - SQL Formatted String
To print SQL formatted string from a date instance you need to use the `.toSQL()` function.
To print a SQL formatted string from a date instance you need to use the `.toSQL()` function.

`func toSQL() -> String`

Expand All @@ -140,7 +141,7 @@ let sqlString = date.toSQL() // "2015-11-19T22:20:40.000+01"
<a name="colloquial"/>

## 5.5 - Relative/Colloquial Formatted String
Colloquial format allows you to produce human friendly string as result of the difference between a date and a a reference date (typically now).
Colloquial format allows you to produce a human friendly string as result of the difference between a date and a a reference date (typically now).
Examples of colloquial formatted strings are `3 mins ago`, `2 days ago` or `just now`.

SwiftDate supports over 140+ languages to produce colloquial formatted strings; the entire engine behind the library is fully customizable so, if you need, you can override default strings and produce your own variants.
Expand Down Expand Up @@ -173,4 +174,17 @@ See the guide ["Customize Colloquial Formatter"](Customize_ColloquialFormatter.m

[^ Top](#index)

<a name="mixeddatetime"/>

## 5.6 - Mixed Date/Time Style

If you to format date with different date/time styles you can use the `. dateTimeMixed` formatter option where you can choose a format both for date and time (`DateFormatter.Style`).

```swify
// Just print full date with no time
let formatted = date.toString(.dateTimeMixed(dateStyle: .full, timeStyle: .none))
```

[^ Top](#index)

[**Next Chapter**: Time Interval Formatting](#6.TimeInterval_Formatting.md)
2 changes: 1 addition & 1 deletion Documentation/6.TimeInterval_Formatting.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The following methods are part of the `TimeInterval` extension provided by Swift
<a name="format"/>

## 6.0 - Format Interval as String
Formatting a time interval as string is pretty simple, you just need to call the `.toString()` function of the `TimeInterval`.
Formatting a time interval as a string is pretty simple, you just need to call the `.toString()` function of the `TimeInterval`.
It allows you to pick the right formatting options to represent the interval as a valid string.

`func toString(options callback: ((inout ComponentsFormatterOptions) -> Void)? = nil) -> String`
Expand Down
5 changes: 3 additions & 2 deletions Documentation/Index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
## Documentation

- Reference Version: **6.1.0**
- Last Update: **Sept 2019**
- Last Update: **Sept 2020

The following documentation explore all the major features of the library. If you are interested in a detailed, method by method documentation you can refeer to the Jazzy documentation generated by CocoaPods (you can also install in Dash).
The following documentation explores all the major features of the library. If you are interested in a detailed, method by method documentation you can refeer to the Jazzy documentation generated by CocoaPods (you can also install in Dash).

### Table Of Contents

Expand Down Expand Up @@ -74,6 +74,7 @@ The following documentation explore all the major features of the library. If yo
- [5.3 - RSS/AltRSS Formatted String](5.Date_Formatting.md#rss)
- [5.4 - SQL Formatted String](5.Date_Formatting.md#sql)
- [5.5 - Relative/Colloquial Formatted String](5.Date_Formatting.md#colloquial)
- [5.6 - Mixed Date/Time Style](5.Date_Formatting.md#mixeddatetime)

### [6 - Time Intervals Formatting](6.TimeInterval_Formatting.md)

Expand Down
Binary file removed Documentation/SwiftDateArt.png
Binary file not shown.
Binary file removed Documentation/SwiftDateLogo.sketch
Binary file not shown.
9 changes: 5 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import PackageDescription
let package = Package(
name: "SwiftDate",
platforms: [
.macOS(.v10_10), .iOS(.v8), .watchOS(.v2), .tvOS(.v9)
.macOS(.v10_10), .iOS(.v9), .watchOS(.v2), .tvOS(.v9)
],
products: [
.library(
name: "SwiftDate",
targets: ["SwiftDate"])
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(name: "SwiftDate", targets: ["SwiftDate"]),
.library(name: "SwiftDateStatic", type: .static, targets: ["SwiftDate"]),
.library(name: "SwiftDateDynamic", type: .dynamic, targets: ["SwiftDate"])
],
dependencies: [],
targets: [
Expand Down
19 changes: 4 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
<p align="center" >
<img src="Documentation/SwiftDateArt.png" width=476px alt="SwiftDate" title="SwiftDate">
<img src="banner.png" width=476px alt="SwiftDate" title="SwiftDate">
</p>

![](https://img.shields.io/cocoapods/v/SwiftDate.svg)
![](https://img.shields.io/cocoapods/p/SwiftDate.svg)
![](https://img.shields.io/badge/coverage-90%25-green.svg)
![](https://img.shields.io/badge/carthage-compatible-brightgreen.svg)
[](https://img.shields.io/travis/malcommac/SwiftDate.svg)
[![Build Status](https://travis-ci.org/malcommac/SwiftDate.svg?branch=master)](https://travis-ci.org/malcommac/SwiftDate)
## What's This?

<p align="center" >★★ <b>Star me to follow the project! </b> ★★<br>
Created and maintained by <b>Daniele Margutti</b> - <a href="http://www.danielemargutti.com">www.danielemargutti.com</a>
</p>

SwiftDate is the **definitive toolchain to manipulate and display dates and time zones** on all Apple platform and even on Linux and Swift Server Side frameworks like Vapor or Kitura.

Over [3M of downloads](https://cocoapods.org/pods/SwiftDate) on CocoaPods
SwiftDate is the **definitive toolchain to manipulate and display dates and time zones** on all Apple platform and even on Linux and Swift Server Side frameworks like Vapor or Kitura.
**Over 3 million of downloads on [CocoaPods](https://cocoapods.org/pods/SwiftDate).**

### Features Highlights
From simple date manipulation to complex business logic SwiftDate maybe the right choice for your next project.

- [x] **Easy Date Parsing** (custom formats, iso8601, rss & many more)
Expand Down
6 changes: 6 additions & 0 deletions Sources/SwiftDate/Formatters/Formatter+Protocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public enum DateToStringStyles {
case date(_: DateFormatter.Style)
case time(_: DateFormatter.Style)
case dateTime(_: DateFormatter.Style)
case dateTimeMixed(dateStyle: DateFormatter.Style, timeStyle: DateFormatter.Style)
case custom(_: String)
case standard
case relative(style: RelativeFormatter.Style?)
Expand Down Expand Up @@ -76,6 +77,11 @@ public enum DateToStringStyles {
$0.dateStyle = style
$0.timeStyle = style
}).string(from: date.date)
case .dateTimeMixed(let dateStyle, let timeStyle):
return date.formatterForRegion(format: nil, configuration: {
$0.dateStyle = dateStyle
$0.timeStyle = timeStyle
}).string(from: date.date)
case .relative(let style):
return RelativeFormatter.format(date, options: style)
}
Expand Down
5 changes: 4 additions & 1 deletion Sources/SwiftDate/Foundation+Extras/String+Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,8 @@ extension String: DateParsable {
public func toSQLDate(region: Region = Region.ISO) -> DateInRegion? {
return StringToDateStyles.sql.toDate(self, region: region)
}


public func asLocale() -> Locale {
Locale(identifier: self)
}
}
9 changes: 4 additions & 5 deletions Sources/SwiftDate/Supports/Commons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,11 @@ public extension DateFormatter {
/// - Returns: number formatter instance
@available(iOS 9.0, macOS 10.11, *)
static func sharedOrdinalNumberFormatter(locale: LocaleConvertible) -> NumberFormatter {
var formatter: NumberFormatter?
let name = "SwiftDate_\(NSStringFromClass(NumberFormatter.self))"
formatter = threadSharedObject(key: name, create: { return NumberFormatter() })
formatter!.numberStyle = .ordinal
formatter!.locale = locale.toLocale()
return formatter!
let formatter = threadSharedObject(key: name, create: { return NumberFormatter() })
formatter.numberStyle = .ordinal
formatter.locale = locale.toLocale()
return formatter
}

}
Expand Down
4 changes: 2 additions & 2 deletions SwiftDate.podspec
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Pod::Spec.new do |s|
s.name = "SwiftDate"
s.version = "6.2.0"
s.version = "6.3.0"
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" }
s.author = { "Daniele Margutti" => "[email protected]" }
s.social_media_url = "https://twitter.com/danielemargutti"
s.ios.deployment_target = "8.0"
s.ios.deployment_target = "9.0"
s.osx.deployment_target = "10.10"
s.watchos.deployment_target = "2.0"
s.tvos.deployment_target = "9.0"
Expand Down
Loading

0 comments on commit 2ef0b18

Please sign in to comment.