Elapse is tiny helper library for manipulating TimeInterval.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Elapse.xcodeproj
Sources
Tests
.gitignore
.swift-version
.travis.yml
Elapse.podspec
LICENSE
Package.swift
README.md

README.md

Elapse

Xcode Swift platforms Travis CI

Elapse is tiny helper library for manipulating TimeInterval.

Usage

Calcurate TimeInterval easily.

let days: TimeInterval = 3.days // 3 * 24 * 60 * 60
let hours: TimeInterval = 3.hours // 3 * 60 * 60
let minutes: TimeInterval = 3.minutes // 3 * 60
let seconds: TimeInterval = 3.seconds // 3.0
let mills: TimeInterval =  3.milliseconds // 0.003

let time: TimeInterval = 3.days + 3.hours + 3.minutes

Separates TimeInterval to each components easily.

let input: TimeInterval = 30.minutes + 30.seconds

let output1 = input.components(of: [.minutes, .seconds])
print("\(output1.minutes):\(output1.seconds)") // "3:30"

let output2 = input.components(of: [.minutes])
print("\(output2.minutes)min") // "30min"

// You can also set the rounding mode. the default value is .floor
let output3 = input.components(of: [.minutes], roundingMode: .ceiling)
print("\(output3.minutes)min") // "31min"

let output4 = input.components(of: [.minutes], roundingMode: .halfAwayFromZero)
print("\(output4.minutes)min") // "31min"

let output5 = (input - 1.seconds).components(of: [.minutes], roundingMode: .halfAwayFromZero)
print("\(output5.minutes)min") // "30min"

let output6 = input.components(of: [.hour], roundingMode: .halfAwayFromZero)
print("\(output6.hours)hour") // "1hour"

Requirements

  • Xcode 10
  • Swift 4.2

Installation

Carthage

To install it, simply add the following line to your Cartfile:

github "yshrkt/Elapse"

CocoaPods

To install it, simply add the following line to your Podfile:

pod "Elapse"

Swift Package Manager

To install it, simply add the proper description to your Package.swift:

import PackageDescription

let package = Package(
    name: "YOUR_PROJECT_NAME",
    targets: [],
    dependencies: [
        .Package(url: "https://github.com/yshrkt/Elapse.git"),
    ]
)

Licence

Elapse is released under the MIT license. See LICENSE for details.

Author

yshrkt