项目作者: adjoint-io

项目描述 :
Financial datetimes and holiday recurrence rules
高级语言: Haskell
项目地址: git://github.com/adjoint-io/datetime.git
创建时间: 2017-09-01T14:59:20Z
项目社区:https://github.com/adjoint-io/datetime

开源协议:Apache License 2.0

下载




Adjoint Logo

Datetimes

CircleCI

A library for financial datetime manipulations and holiday recurrence rules.

Usage

Example usage:

  1. import Datetime
  2. import Datetime.Types
  3. import Data.Aeason as A
  4. christmas :: Datetime
  5. christmas = Datetime
  6. { year = 2017
  7. , month = 12
  8. , day = 25
  9. , hour = 0
  10. , minute = 0
  11. , second = 0
  12. , zone = 0
  13. , week_day = 1
  14. }
  15. -- Fiscal Quarters 2017
  16. let (q1,q2,q3,q4) = fiscalQuarters 2017
  17. eom :: Datetime
  18. eom = eomonth 2017 March
  19. eos :: Datetime
  20. eos = eomonth 2017 September

Example date time calculation for calendarization, difference calculation and
holiday and market status:

  1. main :: IO ()
  2. main = do
  3. print (isHoliday christmas)
  4. print (isWeekend christmas)
  5. putStrLn (A.encode christmas)
  6. print (isBusiness eom)
  7. print (daysBetween (eomonth 2017 March) (eomonth 2019 March))
  8. print (christmas `within` q4) -- True
  9. print (christmas `within` q2) -- False
  10. print $ (christmas `sub` months 11) `within` q1 2017 -- True
  11. nowDt <- now
  12. print nowDt
  13. print $ nowDt `add` (months 3)
  14. print $ nowDt `add` (months 3 <> days 3)

The holidays for United Kingdom and United States banking days can be generated
programmatically from recurrence rules:

  1. > ukHolidays 2017
  2. [ Fixed (FixedHoliday {recurrenceDay = 25, recurrenceMonth = December, observance = Nearest_workday, timezone = +0500})
  3. , Fixed (FixedHoliday {recurrenceDay = 26, recurrenceMonth = December, observance = Nearest_workday, timezone = +0000})
  4. , Fixed (FixedHoliday {recurrenceDay = 1, recurrenceMonth = January, observance = Next_monday, timezone = +0500})
  5. , Easter (EasterHoliday (Datetime {year = 2017, month = 4, day = 14, hour = 0, minute = 0, second = 0, zone = 0, week_day = 5}))
  6. , Easter (EasterHoliday (Datetime {year = 2017, month = 4, day = 17, hour = 0, minute = 0, second = 0, zone = 0, week_day = 1}))
  7. , Rule (HolidayRule {monthOfYear = May, weekDayPos = First, weekDay = Monday})
  8. , Rule (HolidayRule {monthOfYear = May, weekDayPos = Last, weekDay = Monday})
  9. , Rule (HolidayRule {monthOfYear = August, weekDayPos = Last, weekDay = Monday})
  10. ]

The datetime type also implements a full serialize and deserializer for JSON
encoding and binary wire protocol serialization.

License

Copyright 2017-2020 Adjoint Inc

Released under Apache 2.0.