Code Monkey home page Code Monkey logo

swiftdate's Introduction

SwiftDate

SwiftDate is a powerful Date/Calendar framework written completely in Swift. It is partially based on QuantLib, the popular quantitative finance library, and is designed to be very friendly to financial applications. Even if you are not building financial apps, you may still find its date shifting and business calendar capabilities useful.

Getting Started

Date

The Date class allows you to work with calendar days efficiently.

Creating a date is simple:

var d1 = Date(year : 2014, month : 5, day : 15)
var d2 = Date(string : "2014-05-15")

Simple date math works as expected:

d1 = d1 + 1
if (d2 > d1) {
    ...
}

But there are more sophisticated date shifting functions:

var d = Date(string : "2014-04-30")    
d.addMonths(1)                                  // returns "2014-05-30"
d.addMonths(1, rollDay : RollDay.ThirtyOne)     // returns "2014-05-31"
d + "1M"                                        // returns "2014-05-30"

Calendar

The Swift Calendar class allows you to check work with different calendars, such as the NYSE calendar. Try this:

var cal = USNYSECalendar()
var d1 = Date(string : "2014-07-03")
var nbd = cal.nextBizDay(d1)   // returns "2014-07-07" - skipped over 4th of July!

Day Counter

The DayCounter class lets you compute the year fraction (day count fraction) between two dates using the Actual/Actual, Actual/360, Actual/365, NL/365, and 30/360 conventions. It works like this:

var dc = Actual360()
dc.dayCountFraction(Date(string : "2014-01-31"), date2: Date(string : "2014-02-28"))

Copyright and license

Code and documentation copyright 2014 stockfuse.com. Code is released under the MIT license.

swiftdate's People

Contributors

haginile avatar julasamer avatar oyachai avatar

Watchers

James Cloos avatar ApkDemo 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.