time-patterns-0.1.4.3: Patterns for recurring events

Copyright(C) 2013-2017 Jann Müller
LicenseBSD3 (see the file LICENSE)
Maintainerj.mueller.11@ucl.ac.uk
Stabilityexperimental
Safe HaskellSafe
LanguageHaskell2010

Data.Time.Patterns

Contents

Description

Patterns for recurring events. Use the DatePattern type to build up a pattern, and the functions elementOf, instancesFrom and intervalsFrom to evaluate it. Simple example:

import Control.Lens
import Data.Time.Calendar (fromGregorian)
import Data.Time.Patterns
import qualified Prelude as P
Module Main where

main = do
  -- get the 6th of April for the next ten years
  let april6 = (take 1 $ skip 5 day) `inEach` april
  let today =  fromGregorian 2013 12 01
  print $ P.take 10 $ instancesFrom today april6

DatePatterns can be combined using union, intersect with their obvious meanings and inEach which repeats one pattern inside another one. For example,

((take 1 day) `inEach` august) `intersect` sunday

will give the 1st of August in years when it falls on a Sunday.

Synopsis

Date Patterns

type DatePattern = IntervalSequence' Day Source #

A DatePattern describes a sequence of intervals of type Day.

day :: DatePattern Source #

An event that occurs every day.

mondayWeek :: DatePattern Source #

Weeks, starting on Monday

sundayWeek :: DatePattern Source #

Weeks, starting on Sunday.

month :: DatePattern Source #

An event that occurs every month.

year :: DatePattern Source #

Years, starting from Jan. 1

Months

january :: DatePattern Source #

Every January.

february :: DatePattern Source #

Every February.

march :: DatePattern Source #

Every March.

april :: DatePattern Source #

Every April.

may :: DatePattern Source #

Every May.

june :: DatePattern Source #

Every June.

july :: DatePattern Source #

Every July.

august :: DatePattern Source #

Every August.

september :: DatePattern Source #

Every September.

october :: DatePattern Source #

Every October.

november :: DatePattern Source #

Every November.

december :: DatePattern Source #

Every December.

Days

monday :: DatePattern Source #

Every Monday.

tuesday :: DatePattern Source #

Every Tuesday.

wednesday :: DatePattern Source #

Every Wednesday.

thursday :: DatePattern Source #

Every Thursday.

friday :: DatePattern Source #

Every Friday.

saturday :: DatePattern Source #

Every Saturday.

sunday :: DatePattern Source #

Every Sunday.

Operations on date patterns

never :: DatePattern Source #

An event that never occurs

every :: (Num i, Ord i) => i -> DatePattern -> DatePattern Source #

Take every nth occurrence

shiftBy :: Integer -> DatePattern -> DatePattern Source #

Shift all the results by a number of day

inEach :: DatePattern -> DatePattern -> DatePattern Source #

The first pattern repeated for each interval of the second pattern. E.g.:

(take 3 $ every 4 monday) `inEach` year

will give the fourth, eighth and twelveth Monday in each year

take :: (Num i, Ord i) => i -> DatePattern -> DatePattern Source #

Stop after n occurrences

skip :: (Num i, Ord i) => i -> DatePattern -> DatePattern Source #

Skip the first n occurrences

except :: Day -> DatePattern -> DatePattern Source #

Skip over all occurrences of a day. If the pattern describes a period longer than a day, the entire period will be skipped.

intersect :: DatePattern -> DatePattern -> DatePattern Source #

Return only occurrences that are present in both patterns

let myBirthday = (take 1 day) `inEach` august
let s = intersect myBirthday sunday

Will return August 1 in years when it falls on a Sunday

union :: DatePattern -> DatePattern -> DatePattern Source #

Occurrences of both patterns.

union april june

Will return the months April and June in each year

let fifteenth = (take 1 $ skip 14 day) `inEach` month
let third = (take 1 $ skip 2 day) `inEach` month
union fifteenth third

Will return the 3rd and the 15th of each month

until :: DatePattern -> Day -> DatePattern Source #

Only include date intervals that end before the given date.

>> let third = (take 1 $ skip 2 day) `inEach` month
>> let pattern = third `until` (fromGregorian 2020 12 01)
>> instancesFrom (fromGregorian 2017 01 01) pattern
[2017-01-03,2017-02-03 ... 2020-10-03,2020-11-03]

Queries

elementOf :: Day -> DatePattern -> Bool Source #

Check if a date is covered by a DatePattern

instancesFrom :: Day -> DatePattern -> [Day] Source #

Get occurrences of an event starting with a given day

intervalsFrom :: Day -> DatePattern -> [Interval Day] Source #

Get the date intervals described by the pattern, starting from the specified date.

The intervals range from the first day included by the pattern to the first day after it, so a single day d would be described as (d ... succ d) and the interval for a month will go from the 1st of the month to the 1st of the next month.