Giter VIP home page Giter VIP logo

elapse's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.