time-patterns-0.1.2.0: Patterns for reccurring events.

Stabilityexperimental
Maintainerj.mueller.11@ucl.ac.uk
Safe HaskellNone

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.Thyme.Calendar
 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 = (YearMonthDay 2013 12 01)^.from gregorian
   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' DaySource

A DatePattern describes a sequence of intervals of type Data.Thyme.Day.

day :: DatePatternSource

An event that occurs every day.

mondayWeek :: DatePatternSource

Weeks, starting on Monday

sundayWeek :: DatePatternSource

Weeks, starting on Sunday.

month :: DatePatternSource

An event that occurs every month.

year :: DatePatternSource

Years, starting from Jan. 1

Months

january :: DatePatternSource

Every January.

february :: DatePatternSource

Every February.

march :: DatePatternSource

Every March.

april :: DatePatternSource

Every April.

may :: DatePatternSource

Every May.

june :: DatePatternSource

Every June.

july :: DatePatternSource

Every July.

august :: DatePatternSource

Every August.

september :: DatePatternSource

Every September.

october :: DatePatternSource

Every October.

november :: DatePatternSource

Every November.

december :: DatePatternSource

Every December.

Days

monday :: DatePatternSource

Every Monday.

tuesday :: DatePatternSource

Every Tuesday.

wednesday :: DatePatternSource

Every Wednesday.

thursday :: DatePatternSource

Every Thursday.

friday :: DatePatternSource

Every Friday.

saturday :: DatePatternSource

Every Saturday.

sunday :: DatePatternSource

Every Sunday.

Operations on date patterns

never :: DatePatternSource

An event that never occurs

every :: Int -> DatePattern -> DatePatternSource

Take every nth occurrence

shiftBy :: Days -> DatePattern -> DatePatternSource

Shift all the results by a number of day

inEach :: DatePattern -> DatePattern -> DatePatternSource

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 :: Int -> DatePattern -> DatePatternSource

Stop after n occurrences

skip :: Int -> DatePattern -> DatePatternSource

Skip the first n occurrences

except :: Day -> DatePattern -> DatePatternSource

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 -> DatePatternSource

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 -> DatePatternSource

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

Queries

elementOf :: Day -> DatePattern -> BoolSource

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.