Go to file
Yoshihiro Kato 8584c70cac Fixes podspec 2018-10-14 03:07:37 +09:00
Elapse.xcodeproj Fixes project.pbxproj 2018-10-14 02:41:46 +09:00
Sources initial commit 2017-06-02 12:29:58 +09:00
Tests initial commit 2017-06-02 12:29:58 +09:00
.gitignore initial commit 2017-06-02 12:29:58 +09:00
.swift-version Updates for xcode10 / swift4.2 2018-10-14 02:05:46 +09:00
.travis.yml Fixes .travis.yml 2018-10-14 02:41:26 +09:00
Elapse.podspec Fixes podspec 2018-10-14 03:07:37 +09:00
LICENSE Renames LICENSE file 2017-06-02 12:35:30 +09:00
Package.swift Updates for xcode10 / swift4.2 2018-10-14 02:05:46 +09:00
README.md Updates for xcode10 / swift4.2 2018-10-14 02:05:46 +09:00

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