Git Product home page Git Product logo

swiftmoment's Introduction

SwiftMoment

This framework is inspired by Moment.js. Its objectives are the following:

  • Simplify the manipulation and readability of date and interval values.
  • Provide help when parsing dates from various string representations.
  • Simplifying the formatting of date information into strings.
  • Streamlining getting date components (day, month, etc.) from dates and time intervals.

Important: This framework targets iOS 8.3, Xcode 6.3 and Swift 1.2 and later exclusively.

Installation

SwiftMoment is compatible with Carthage and CocoaPods. With CocoaPods, just add this to your Podfile:

pod 'SwiftMoment'

Examples

To use this library, just import SwiftMoment in your application.

To create new moment instances:

let now = moment()
let yesterday = moment("2015-01-19")

By default, moments are initialized with the current date and time. You can create moments for any... moment in the future or the past; you can do that by passing strings in different formats:

let yesterday = moment("2015-01-19")

You can also do it by directly specifying the components manually:

let today = moment([2015, 01, 19, 20, 45, 34])

You can also use a dictionary with the following keys:

let obj = moment(["year": 2015,
                    "second": 34,
                    "month": 01,
                    "minute": 45,
                    "hour": 20,
                    "day": 19
                ])

When using a [String: Int] dictionary, the order of the keys does not matter. Moreover, only the keys above are taken into account, and any other information is ignored.

There is also an extension to the Int type in Swift, used to create Duration values directly from an integer value:

let duration = 5.hours + 56.minutes

Architecture

The two most important components of this library are the Moment and Duration structures. Moment wraps an NSDate instance, while Duration wraps an NSTimeInterval value.

Both Moment and Duration comply with the Comparable protocols, and include all the required operators. In addition, Moment instances can be substracted from one another (which yields a Duration) and Duration instances can be added to Moments to create new moments.

Moments and Durations are made as immutable as possible.

Documentation

The documentation of the code is extracted using Jazzy.

Tests

Swift Moment includes a suite of tests showing how to use the different functions of the framework.

Contributors

Lots of people are actively helping in the development of this library; please check the CONTRIBUTORS file for the full list! Thanks to all :)

License

This project is distributed under a BSD license. See the LICENSE file for details.

swiftmoment's People

Contributors

armstrongnate avatar lbrndnr avatar karupanerura avatar getaaron avatar andersklenke avatar chrissloey avatar vandyshev avatar

Watchers

Steve avatar James Cloos avatar  avatar

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.