Skip to content

Commit

Permalink
<Description> : Adding ISO8601 Date formatted var extension for Date.
Browse files Browse the repository at this point in the history
<Type> : feature/test
  • Loading branch information
Khalian committed Feb 8, 2017
1 parent 3814074 commit c9a2469
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Add subsequent changes that you make in this section.
- `var isFuture` in [[PR]](https://github.com/goktugyil/EZSwiftExtensions/pull/343) by *Khalian*
- `var isPast` in [[PR]](https://github.com/goktugyil/EZSwiftExtensions/pull/343) by *Khalian*
- `var era` in [[PR]](https://github.com/goktugyil/EZSwiftExtensions/pull/374) by *Khalian*
- `var iso8601` in [[PR]](https://github.com/goktugyil/EZSwiftExtensions/pull/375) by *Khalian*

4. **Double**
- `var abs` in [[PR]](https://github.com/goktugyil/EZSwiftExtensions/pull/365) by *Khalian*
Expand Down
5 changes: 5 additions & 0 deletions EZSwiftExtensionsTests/DateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,9 @@ class DateTests: XCTestCase {
let today = Date()
XCTAssert(today.nanosecond == Calendar.current.component(.nanosecond, from: today))
}

func testISO8601() {
let customDate = Date(fromString: "09-01-2015 05:45:12", format: self.format)
XCTAssertEqual(customDate?.iso8601, "2015-01-09T05:45:12Z")
}
}
8 changes: 8 additions & 0 deletions Sources/DateExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,12 @@ extension Date {
public var nanosecond: Int {
return Calendar.current.component(.nanosecond, from: self)
}

/// EZSE : Gets the international standard(ISO8601) representation of date
@available(iOS 10.0, *)
@available(tvOS 10.0, *)
public var iso8601: String {
let formatter = ISO8601DateFormatter()
return formatter.string(from: self)
}
}

0 comments on commit c9a2469

Please sign in to comment.