Intuitive date handling in Swift

Related tags

Date & Time swift date
Overview

Timepiece CocoaPods Compatible Build Status

Intuitive date handling in Swift

Features

  • πŸ’‘ Intuitive: Timepiece provides a set of helpers to make date handling easier.
  • πŸ•˜ Correct: Using Foundation API correctly, Timepiece helps to calculate dates correctly without deep understanding.
  • πŸ“¦ Small: Timepiece has only 4 file. You can read the inside of this easily.

Requirements

  • Swift 3.0+
  • iOS 8.0+ / macOS 10.9+ / tvOS 9.0+ / watchOS 2.0+

Usage

Initialization

Date(era: 235, year: 26, month: 8, day: 14, hour: 20, minute: 25, second: 43, nanosecond: 0, on: Calendar(identifier: .japanese))
Date(year: 2014, month: 8, day: 14, hour: 20, minute: 25, second: 43, nanosecond: 0)
Date(year: 2014, month: 8, day: 14, hour: 20, minute: 25, second: 43)
Date(year: 2014, month: 8, day: 14)

Date.today()
Date.yesterday()
Date.tomorrow()

Calculation

now + 1.year
now - 2.months
now + (3.weeks - 4.days + 5.hours)

1.year.later
1.year.ago

Change

now.changed(year: 2014)
now.changed(weekday: 1)
now.truncated([.minute, .second, .nanosecond])
now.truncated(from: .day)

Formating

now.stringIn(dateStyle: .long, timeStyle: .medium)
now.dateString(in: .medium)
now.timeString(in: .short)

3.days.string(in: .full)

Parsing

"2014/8/14".date(inFormat: "yyyy/MM/dd")
"2014-08-14T20:25:43+0900".dateInISO8601Format()

Installation

CocoaPods

# Podfile
pod "Timepiece"

Carthage

# Cartfile
github "naoty/Timepiece"

Contribution

  1. Fork
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

Timepiece is available under the MIT license. See the LICENSE file for more info.

Author

naoty

Comments
  • Migrated to Swift 3

    Migrated to Swift 3

    Current build did not allow me to run tests for macOS, but tvOS and iOS worked fine so far.

    There were a lot of changes in NSCalendar to Calendar. Please review NSCalendar+Timepiece.swift

    I also added some localization functionality (for me it was a bug, that's why I fixed it), so that a date can be converted into a string in any other language (based on Locale). I also added the ability to convert a string of a date given in another language (based on Locale) into a Date (Commits: https://github.com/naoty/Timepiece/pull/59/commits/b3da1681f0eea87d0d5f6c7d210d8101047c71e1, https://github.com/naoty/Timepiece/pull/59/commits/7fb814ddedc56033672287f7daee11c8d64fa9d1). This is helpful if e.g. a date is given in English, but the device of the user is going to display it in another language.

    Please review and verify.

    opened by skofgar 14
  • Timezones

    Timezones

    First off. I like the progress of this library. It's very elegant. So to my issue....I think this is more a feature request then an issue. I was thinking would be very nice to be able to set / get Timezones. What do you think?

    opened by Prince2k3 14
  • Feature/compare duration

    Feature/compare duration

    • Added support to subtract two dates from each other and obtain the difference as NSTimeInterval.
    • Added ability to compare Duration against NSTimeInterval

    These two additations combined allows the following:

    if date2 - date1 > 5.seconds { ... }
    etc.
    
    opened by mattijsf 13
  • Add watchOS target

    Add watchOS target

    This should add a watchOS target to both the Podfile and to use with Carthage.

    I saw you already tried to add it but this should do the trick.

    BTW the readme still says Swift 2.0 support is in a branch but that is not true anymore ;)

    opened by nickygerritsen 8
  • Added functions for beginning of Week and end of Week

    Added functions for beginning of Week and end of Week

    I further extended the beginningOfMonth / beginningOfDay / endOfMonth / endOfDay functions in NSDate+Timepiece.swift to quickly get the first and last days of the current week.

    opened by irlabs 8
  • NSCalendarUnit's interval property makes some invalid assumptions about dates.

    NSCalendarUnit's interval property makes some invalid assumptions about dates.

    http://infiniteundo.com/post/25326999628/falsehoods-programmers-believe-about-time breaks this down in more detail, but to sum it up:

    • Months don't always have 30 days.
    • Years don't always have the same number of days.

    etc.

    opened by sstigler 8
  • "No such module 'Timepiece'"

    Hi, I'm pretty new to Swift/pods. I added timepiece to my pod file, installed it and can verify it's added to my app. But attempting to import Timepiece at the top of my appDelegate with the rest of my other imports gives me an error "No such module 'Timepiece'"

    Any idea what I'm missing here?

    Thanks!

    opened by pketh 7
  • Swift 2.0, cocoapods 0.39.0 pod issue

    Swift 2.0, cocoapods 0.39.0 pod issue

    Using swift 2.0 with Cocoapods 0.39.0 I'm getting the issue below:

    Pre-downloading: Timepiece from https://github.com/naoty/Timepiece.git, branch swift-2 fatal: No names found, cannot describe anything. [!] Unable to satisfy the following requirements:

    • Timepiece (fromhttps://github.com/naoty/Timepiece.git, branchswift-2)required byPodfile

    Thx

    opened by crarau 7
  • Weekend

    Weekend

    Hello. Very nice lib. it rocks man! Just wandering if there is any quick workaround to take the dates of the next weekend (saturday-sunday) like Date.today()

    enhancement 
    opened by kwstasna 5
  • inFormat is returning wrong weekday

    inFormat is returning wrong weekday

    I just debugged an issue I have with .date(inFormat:), it returns the wrong weekday.

    I pin pointed the issue to this line:

    https://github.com/naoty/Timepiece/blob/master/Sources/String%2BTimepiece.swift#L21

    If you remove it, it works as expected (I think it uses the current calendar by default, maybe this line overwrites it).

    bug 
    opened by allaire 5
  • Invalid Bundle Structure - The binary file 'Timepiece.framework/libswiftRemoteMirror.dylib' is not permitted

    Invalid Bundle Structure - The binary file 'Timepiece.framework/libswiftRemoteMirror.dylib' is not permitted

    I'm using Timeline with Carthage. Now, when I try to upload my app to iTunes I get the following error:

    Invalid Bundle Structure - The binary file 'MyApp.app/Frameworks/Timepiece.framework/libswiftRemoteMirror.dylib' is not permitted. Your app can’t contain standalone executables or libraries, other than the CFBundleExecutable of supported bundles. Refer to the Bundle Programming Guide at https://developer.apple.com/go/?id=bundle-structure for information on the iOS app bundle structure." ERROR ITMS-90206: "Invalid Bundle. The bundle at 'MyApp.app/Frameworks/Timepiece.framework' contains disallowed file 'Frameworks'."

    bug 
    opened by hdoria 5
  • fix typo that prevents cocoapods installation

    fix typo that prevents cocoapods installation

    With Cocoapods version 1.8.3, try to update or install pod was sending this error messages:

    - `Timepiece-library` does not specify a Swift version and none of the targets (`Pods`) integrating it have the `SWIFT_VERSION` attribute set. Please contact the author or set the `SWIFT_VERSION` attribute in at least one of the targets that integrate this pod.
    

    after some investigation, there was a small typo in the podspect. Fixed the typo there is no error anymore

    opened by luicm 0
  • problems installing with CocoaPods

    problems installing with CocoaPods

    Hello, I've recently had to reinstall pods in my project and I am getting this error in CocoaPods:

    Timepiece-library does not specify a Swift version and none of the targets (Pods) integrating it have the SWIFT_VERSION attribute set. Please contact the author or set the SWIFT_VERSION attribute in at least one of the targets that integrate this pod. Is it possible to fix? thank you very much

    opened by luicm 0
  • Can you add more date math examples to readme?

    Can you add more date math examples to readme?

    I'm dim. I'm not 100% sure how to use this library to do something like (I'm shortcutting the syntax)

    let christmas = Date(year: today().year, month:12, day:25) let daysUntilChristmas = christmas - today ????? //give us some examples please

    opened by bbookman 2
Owner
Naoto Kaneko
Naoto Kaneko
Date Formatter Pool - is a small utility that creates and stores your Date Formatter for simpler reuse

Date Formatter Pool Date Formatter Pool - is a small utility that creates and stores your Date Formatter for simpler reuse Installation is available i

Aleksei Artemev 13 Sep 6, 2022
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
πŸ“† 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
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

Mobile Native Foundation 575 Dec 23, 2022
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

Dave DeLong 2k Dec 31, 2022
Swift Date Formatter

Swift Date Formatter Date Formatter - Sample code on how to use Date Formatter in swift language Author: Denow Cleetus For OSSE Assignment 4 Group 24

Denow Cleetus 0 Nov 7, 2021
NasaApod - iOS, Swift, MVVM, Consuming NASA Astronomy Picture of the Day API for any selected date

NasaApod iOS, Swift, MVVM, Unit Tests Consuming NASA Astronomy Picture of the Da

Vishal Singh 1 Jan 10, 2022
πŸŽ— Super lightweight ISO8601 Date Formatter in Swift

ISO8601 ❀️ Support my apps ❀️ Push Hero - pure Swift native macOS application to test push notifications PastePal - Pasteboard, note and shortcut mana

Khoa 19 May 12, 2020
Date and time manager for iOS/OSX written in Swift

Tempo was designed to work both in OSX and in iOS (7.0+). Work with the time or dates can be cumbersome, iOS development. Tempo allows you to deal easly with date and time. Basics manipulations are already implemented in Tempo.

Remi ROBERT 153 Jun 3, 2021
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
Datify πŸ•› Easypeasy date functions.

Datify ?? Easypeasy date functions.

Hemang 44 Dec 6, 2022
NVDate is an extension of NSDate class (Swift4), created to make date and time manipulation easier.

NVDate is an extension of NSDate class (Swift4), created to make date and time manipulation easier. NVDate is testable and robust, we wrote intensive test to make sure everything is safe.

Noval Agung Prayogo 177 Oct 5, 2022
A customizable date picker for watchOS and SwiftUI.

Watch Date Picker A customizable date picker for watchOS and SwiftUI. Installation .package(url: "https://github.com/freyaariel/watch-date-picker.git"

Freya Ariel 30 Dec 4, 2022
A basic countdown app that allows the user to create, edit, and delete events. Each event contains a live countdown timer to a specified date and time.

Event Countdown App (iOS) Created by Lucas Ausberger About This Project Created: January 4, 2021 Last Updated: January 8, 2021 Current Verison: 1.1.1

Lucas Ausberger 1 Jan 8, 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
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
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
πŸ•° 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

Oleg Dreyman 1.1k Dec 21, 2022