Date and time manager for iOS/OSX written in Swift

Related tags

Date & Time Tempo
Overview


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.

How to use it ?

You can build a new Tempo, with severals way:

var birthdayTempo = Tempo { (newTemp) -> () in
    newTemp.years = 2014
    newTemp.months = 12
    newTemp.days = 12
}
var currentTime = Tempo()
var tempoWithDate = Tempo(date: customNSDate)
var tempoWithString = Tempo(stringDate: "12/02/1992")
var tempoCustomFormat = Tempo(stringDate: "12/02/1992", "dd/MM/yyyy")

Convert Tempo to string, with specific format: All the basics format work with Tempo.

Tempo().format()                                // "2014 12 12 00:00:00"
Tempo().format("yyyy MM dd")                    // "2014 12 12"
Tempo().format("dd EE / MMMM / yyyy")           // "12 Fri / December / 2014"

let t1 = Tempo(stringDate: "2014 12 12")

//change the locale date
t1.locale = NSLocale(localeIdentifier: "fr_FR")
t1.format(format: "EEEE")                       // "mercredi"

t1.locale = NSLocale(localeIdentifier: "en_EN")
t1.format(format: "EEEE")                       // "Wednesday"

t1.locale = NSLocale(localeIdentifier: "es_ES")
t1.format(format: "EEEE")                       // "miércoles"

With Tempo you have access to the date components and the date itself: The date components and the date are linked.

let t = Tempo()

t.years! += 1
t.days! += 20

t.date = NSDate()

You can also make simple comparaison between two Tempo or with NSDate:

var newDate = Tempo { (newTemp) -> () in
  newTemp.years = 2014
  newTemp.months = 10
  newTemp.days = 12
  newTemp.minutes = 2
}

println("newDate: \(newDate.formatDate())")             // "2014 10 12 00:02:00"
println("current time : \(Tempo().formatDate())")       // "2014 12 18 15:40:11"

Tempo().isAfter(newDate)                                // "True"
Tempo().isBefore(newDate)                               // "False"
Tempo().isSame(newDate)                                 // "False"
Tempo().isBetween(tempoLeft:newDate, tempoRight:d2)     // "True"

Tempo().isToday(newDate)                                // "False"
Tempo().isThisMonth(newDate)                            // "true"
Tempo().isThisYear(newDate)                             // "true"

Tempo also override operator the simple comparaison :

// same as tempo1.isBefore(tempo2)
if tempo1 < tempo2 {
}

// same as tempo1.isAfter(tempo2)
if tempo1 > tempo2 {
}

// same as tempo1.isSame(tempo2)
if tempo1 == tempo2 {
}

// You can add two tempo together:
let result: Tempo = tempo1 + tempo2
let result: Tempo = tempo1 - tempo2

Know difference between two date component:

var newDate = Tempo { (newTemp) -> () in
  newTemp.years = 2014
  newTemp.months = 10
  newTemp.days = 12
  newTemp.minutes = 2
}

Tempo().diffYear(newDate)                  // "0"
Tempo().diffMonth(newDate)                // "-4"
Tempo().diffWeek(newDate)                // "-18"
Tempo().diffDay(newDate)                // "-130"

Get time ago from date or current time: Return literal string with the difference between two Tempo. Can be usefull in for display in message or feeds. You have three diferent kind of display.

var date = Tempo { (newTemp) -> () in
    newTemp.years = 2014
    newTemp.months = 10
    newTemp.days = 25
}

// Classic display
date.timeAgoNow()                       // "3 months ago"
date.timeAgo(Tempo())

// Short display
date.timeAgoSimpleNow()                 // "3mo"
date.timeAgoSimple(Tempo())

// More readable display
date.dateTimeUntilNow()                 // "This year"
date.dateTimeUntil(Tempo())

License

The MIT License (MIT)
Copyright (c) 2014 rémi ROBERT

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
You might also like...
A customizable date picker for watchOS and SwiftUI.
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"

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.

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

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

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

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

🎗 Super lightweight ISO8601 Date Formatter in Swift
🎗 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

Datify 🕛 Easypeasy date functions.

Datify 🕛 Easypeasy date functions.

A TimeZonePicker UIViewController similar to the iOS Settings app. Search and select from a range of cities and countries to find your most suitable time zone.
A TimeZonePicker UIViewController similar to the iOS Settings app. Search and select from a range of cities and countries to find your most suitable time zone.

TimeZonePicker A TimeZonePicker UIViewController similar to the iOS Settings app. Search and select from a range of cities and countries to find your

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

Comments
  • Generell Question

    Generell Question

    Hey dude,

    first of all compliment. I really like your library. I have just a general questions.

    Why do you not extend NSDate instead of create a own class? I mean then you don't need a function (convertToNSDate) to convert your class to NSDate. Does have that a special reason?

    And could you maybe add cocoapods?

    Cheers,

    Eike

    opened by eikebartels 4
  • Inefficient use of NSDateFormatter

    Inefficient use of NSDateFormatter

    Instantiate NSDateFormatter is expensive operation and you use it exactly that way. You can read this in Apple documentation:

    Creating a date formatter is not a cheap operation. If you are likely to use a formatter frequently, it is typically more efficient to cache a single instance than to create and dispose of multiple instances. One approach is to use a static variable.

    opened by tomassliz 1
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
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
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
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
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
📆 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
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
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
Timekeeper is an easy-to-use time measurement library written in Swift, with support for iOS, tvOS, watchOS and macOS.

Timekeeper is an easy-to-use time measurement library written in Swift, with support for iOS, tvOS, watchOS and macOS. Installation Timekee

Andreas Pfurtscheller 1 Oct 18, 2021