Punctual - Swift dates, more fun. Heavily inspired by ObjectiveSugar

Overview

Punctual

Swift dates, more fun. Heavily inspired by ObjectiveSugar

Installation

Punctual is available through the 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!

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)
// 1

print(4.years.fromNow?.longTimeString)
// Optional("12:11:44 AM EDT")

print(4.years.fromNow?.stringWithFormat("HH:mm"))
// Optional("00:11")
You might also like...
🕰 Type-safe time calculations in Swift

Time This micro-library is made for you if: You have ever written something like this: let interval: TimeInterval = 10 * 60 To represent 10 minutes. U

Intuitive date handling in Swift

Timepiece Intuitive date handling in Swift Features 💡 Intuitive: Timepiece provides a set of helpers to make date handling easier. 🕘 Correct: Using

NTP library for Swift and Objective-C. Get the true time impervious to device clock changes.
NTP library for Swift and Objective-C. Get the true time impervious to device clock changes.

TrueTime for Swift Make sure to check out our counterpart too: TrueTime, an NTP library for Android. NTP client for Swift. Calculate the time "now" im

Elegant NTP date library in Swift
Elegant NTP date library in Swift

Kronos is an NTP client library written in Swift. It supports sub-seconds precision and provides a stable monotonic clock that won't be affected by ch

Building a better date/time library for Swift

Time Time is a Swift package that makes dealing with calendar values a natural and straight-forward process. Working with calendars can be extremely c

A Swift micro library for generating Sunrise and Sunset times.

Solar A Swift helper for generating Sunrise and Sunset times. Solar performs its calculations locally using an algorithm from the United States Naval

Custom Time Picker ViewController with Selection of start and end times in Swift đŸ”ļ
Custom Time Picker ViewController with Selection of start and end times in Swift đŸ”ļ

LFTimePicker Custom Time Picker ViewController with Selection of start and end times in Swift đŸ”ļ . Based on Adey Salyard's design @ Dribbble One to tw

Schedule timing task in Swift using a fluent API. (A friendly alternative to Timer)
Schedule timing task in Swift using a fluent API. (A friendly alternative to Timer)

Schedule(įŽ€äŊ“中文) Schedule is a timing tasks scheduler written in Swift. It allows you run timing tasks with elegant and intuitive syntax. Features Elega

The most perfect Swift Timer you'll ever need.

Timerable ⏰ The most perfect Swift Timer you'll ever need. A protocol-oriented Timer Factory with all the features you'll ever need. I wrote it in bot

Comments
  • Broken code example in readme

    Broken code example in readme

    The last example claims to get tomorrow's date:

    // get tomorrow's date
    sleep(1.day.timeInterval)
    print(NSDate())
    

    This will work in most cases, unless completing the call to 1.day.timeInterval takes longer than the remaining time in the day. The process will then sleep for a day, and print the date of the day after tomorrow.

    This is a critical issue with this code example.

    opened by gambogi 7
  • example subdirectory is not excluded

    example subdirectory is not excluded

    We have no way to exclude it yet, so I'll have to consider what should be done.

    Anyway, currently it gets built and thus fails:

     swift build
    Compiling Swift Module 'example' (2 sources)
    /Users/mxcl/scratch/Punctual.swift/example/Package.swift:1:8: error: no such module 'PackageDescription'
    import PackageDescription
           ^
    /Users/mxcl/scratch/Punctual.swift/example/Package.swift:1:8: error: no such module 'PackageDescription'
    import PackageDescription
           ^
    <unknown>:0: error: build had 1 command failures
    swift-build: exit(1): ["/Library/Developer/Toolchains/swift-2.2-SNAPSHOT-2015-12-01-a.xctoolchain/usr/bin/swift-build-tool", "-f", "/Users/mxcl/scratch/Punctual.swift/.build/debug/Punctual.o/llbuild.yaml"]
    
    opened by mxcl 2
  • Tag 1.0.0 is outdated

    Tag 1.0.0 is outdated

    Could you please tag the latest version so it can be used by swift package manager? (maybe after you have a look at #6) I would suggest 2.0.0 because of the migration to Swift 3. Thanks!

    opened by siemensikkema 1
  • Organize Readme

    Organize Readme

    Hey @harlanhaskins, your library is really interesting.

    The only problem I found was the README.md, which lacks information. I created this iOS Open source Readme Template so you can take a look on how to better organize. If you want, I can help you to do it.

    What are your thoughts?

    opened by lfarah 0
Releases(1.0.1)
Owner
Harlan Haskins
@harlanhaskins on Twitter
Harlan Haskins
DateHelper - A high performant Swift Date Extension for creating, converting, comparing, or modifying dates.

DateHelper A high performant Swift Date Extension for creating, converting, comparing, or modifying dates. Capabilities Creating a Date from a String

Melvin Rivera 1.4k Jan 2, 2023
SwiftDate 🐔 Toolkit to parse, validate, manipulate, compare and display dates, time & timezones in Swift.

Toolkit to parse, validate, manipulate, compare and display dates, time & timezones in Swift. What's This? SwiftDate is the definitive toolchain to ma

Daniele Margutti 7.2k Jan 4, 2023
Dates and times made easy in iOS

DateTools DateTools was written to streamline date and time handling in iOS. Classes and concepts from other languages served as an inspiration for Da

Matthew York 7.2k Dec 30, 2022
A Cocoa NSFormatter subclass to convert dates to and from ISO-8601-formatted strings. Supports calendar, week, and ordinal formats.

ISO 8601: The only date format worth using Obligatory relevant xkcd: How to use this code in your program Add the source files to your project. Parsin

Peter Hosey 601 Sep 4, 2022
🕐 Format your dates/times as emojis.

EmojiTimeFormatter Format your dates/times as emojis ?? ?? ?? Description You can build easy to understand user interfaces with EmojiTimeFormatter or

Thomas Paul Mann 80 Feb 7, 2022
Swifty Date & Time API inspired from Java 8 DateTime API.

AnyDate Swifty Date & Time API inspired from Java 8 DateTime API. Background I think that date & time API should be easy and accurate. Previous dates,

Jungwon An 182 Dec 1, 2022
Swifty Date & Time API inspired from Java 8 DateTime API.

AnyDate Swifty Date & Time API inspired from Java 8 DateTime API. Background I think that date & time API should be easy and accurate. Previous dates,

Jungwon An 182 Dec 1, 2022
Time is a Swift package that makes dealing with calendar values a natural and straight-forward process.

Time Time is a Swift package that makes dealing with calendar values a natural and straight-forward process. Working with calendars can be extremely c

Dave DeLong 2k Dec 31, 2022
📆 Breeze through Date, DateComponents, and TimeInterval with Swift!

Datez ?? Breeze through Date, DateComponents, and TimeInterval Highlights Two Custom Structs Only (value types FTW!): DateView: An Date associated wit

Kitz 263 Dec 7, 2022
SwiftMoment - A time and calendar manipulation library for iOS 9+, macOS 10.11+, tvOS 9+, watchOS 2+ written in Swift 4.

SwiftMoment This framework is inspired by Moment.js. Its objectives are the following: Simplify the manipulation and readability of date and interval

Adrian Kosmaczewski 1.6k Dec 31, 2022