Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/harlanhaskins/Punctual.swift
Swift dates, more fun.
https://github.com/harlanhaskins/Punctual.swift
Last synced: about 2 months ago
JSON representation
Swift dates, more fun.
- Host: GitHub
- URL: https://github.com/harlanhaskins/Punctual.swift
- Owner: harlanhaskins
- License: mit
- Archived: true
- Created: 2015-04-08T04:14:35.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-11-29T18:36:20.000Z (almost 8 years ago)
- Last Synced: 2024-07-24T01:57:16.040Z (about 2 months ago)
- Language: Swift
- Homepage:
- Size: 55.7 KB
- Stars: 320
- Watchers: 5
- Forks: 11
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-swift-cn - Punctual.swift - Swift date handler. (Libs / Date)
README
# Punctual
Swift dates, more fun. Heavily inspired by [ObjectiveSugar](https://github.com/supermarin/objectivesugar)
# Installation
Punctual is available through the [Swift Package Manager](https://github.com/apple/swift-package-manager)!Just add this as a dependency in your `Package.swift`:
```
.Package(url: "https://github.com/harlanhaskins/Punctual.swift.git", majorVersion: 1)
```# Contents
`Punctual` extends `Int`, `NSDateComponents`, `NSDate`, and `NSCalendarUnit`, and adds features to make them work well together. It uses the robust `NSCalendar` APIs, so you can be sure it's accurate!```swift
print(1.day.ago)
// Optional(2015-04-08 04:49:30 +0000)print(10.days.until(Date()))
// Optional(2015-03-30 04:11:03 +0000)print((1.day + 2.months - 9.years).ago)
// Optional(2024-02-08 18:28:26 +0000)print(Date() - 1.day.ago!)
print(1.year.timeInterval)
// Optional(31622400.0)print((Date() + 30.minutes)!.nearestHour)
// 1print(4.years.fromNow?.longTimeString)
// Optional("12:11:44 AM EDT")print(4.years.fromNow?.stringWithFormat("HH:mm"))
// Optional("00:11")
```