Copyright | (C) 2013 Jann Mueller |
---|---|
License | BSD3 (see the file LICENSE) |
Maintainer | j.mueller.11@ucl.ac.uk |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
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
DatePattern
s 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.
- type DatePattern = IntervalSequence' Day
- day :: DatePattern
- mondayWeek :: DatePattern
- sundayWeek :: DatePattern
- month :: DatePattern
- year :: DatePattern
- january :: DatePattern
- february :: DatePattern
- march :: DatePattern
- april :: DatePattern
- may :: DatePattern
- june :: DatePattern
- july :: DatePattern
- august :: DatePattern
- september :: DatePattern
- october :: DatePattern
- november :: DatePattern
- december :: DatePattern
- monday :: DatePattern
- tuesday :: DatePattern
- wednesday :: DatePattern
- thursday :: DatePattern
- friday :: DatePattern
- saturday :: DatePattern
- sunday :: DatePattern
- never :: DatePattern
- every :: (Num i, Ord i) => i -> DatePattern -> DatePattern
- shiftBy :: Days -> DatePattern -> DatePattern
- inEach :: DatePattern -> DatePattern -> DatePattern
- take :: (Num i, Ord i) => i -> DatePattern -> DatePattern
- skip :: (Num i, Ord i) => i -> DatePattern -> DatePattern
- except :: Day -> DatePattern -> DatePattern
- intersect :: DatePattern -> DatePattern -> DatePattern
- union :: DatePattern -> DatePattern -> DatePattern
- elementOf :: Day -> DatePattern -> Bool
- instancesFrom :: Day -> DatePattern -> [Day]
- intervalsFrom :: Day -> DatePattern -> [Interval Day]
Date Patterns
type DatePattern = IntervalSequence' Day Source
A DatePattern describes a sequence of intervals of type Data.Thyme.Day.
day :: DatePattern Source
An event that occurs every day.
mondayWeek :: DatePattern Source
Weeks, starting on Monday
sundayWeek :: DatePattern Source
Weeks, starting on Sunday.
An event that occurs every month.
Years, starting from Jan. 1
Months
Every January.
february :: DatePattern Source
Every February.
Every March.
Every April.
may :: DatePattern Source
Every May.
Every June.
Every July.
Every August.
september :: DatePattern Source
Every September.
Every October.
november :: DatePattern Source
Every November.
december :: DatePattern Source
Every December.
Days
Every Monday.
Every Tuesday.
wednesday :: DatePattern Source
Every Wednesday.
thursday :: DatePattern Source
Every Thursday.
Every Friday.
saturday :: DatePattern Source
Every Saturday.
Every Sunday.
Operations on date patterns
An event that never occurs
every :: (Num i, Ord i) => i -> DatePattern -> DatePattern Source
Take every nth occurrence
shiftBy :: Days -> 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
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.