{-# LANGUAGE GADTs #-}
{-# LANGUAGE NoRebindableSyntax #-}
{-# LANGUAGE OverloadedStrings #-}
module Duckling.Time.EN.BZ.Rules
( rules
) where
import Data.Maybe
import Prelude
import Duckling.Dimensions.Types
import Duckling.Numeral.Helpers (parseInt)
import Duckling.Regex.Types
import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData (..))
import Duckling.Types
ruleDDMM :: Rule
ruleDDMM = Rule
{ name = "dd/mm"
, pattern =
[ regex "(3[01]|[12]\\d|0?[1-9])\\s?[/-]\\s?(1[0-2]|0?[1-9])"
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (dd:mm:_)):_) -> do
d <- parseInt dd
m <- parseInt mm
tt $ monthDay m d
_ -> Nothing
}
ruleDDMMYYYY :: Rule
ruleDDMMYYYY = Rule
{ name = "dd/mm/yyyy"
, pattern =
[ regex "(3[01]|[12]\\d|0?[1-9])[-/\\s](1[0-2]|0?[1-9])[-/\\s](\\d{2,4})"
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (dd:mm:yy:_)):_) -> do
y <- parseInt yy
d <- parseInt dd
m <- parseInt mm
tt $ yearMonthDay y m d
_ -> Nothing
}
ruleDDMMYYYYDot :: Rule
ruleDDMMYYYYDot = Rule
{ name = "dd.mm.yyyy"
, pattern =
[ regex "(3[01]|[12]\\d|0?[1-9])\\.(1[0-2]|0?[1-9])\\.(\\d{4})"
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (dd:mm:yy:_)):_) -> do
y <- parseInt yy
d <- parseInt dd
m <- parseInt mm
tt $ yearMonthDay y m d
_ -> Nothing
}
rulePeriodicHolidays :: [Rule]
rulePeriodicHolidays = mkRuleHolidays
[ ( "Garifuna Settlement Day", "garifuna settlement day", monthDay 11 19 )
, ( "Labour Day", "labour day", monthDay 5 1 )
, ( "National Heroes and Benefactors Day"
, "national heroes and benefactors day", monthDay 3 9 )
, ( "Pan American Day", "pan american day", monthDay 10 12 )
, ( "St. George's Caye Day", "st\\.? george'?s caye day", monthDay 9 10 )
, ( "Father's Day", "father'?s?'? day", nthDOWOfMonth 3 7 6 )
, ( "Mother's Day", "mother'?s?'? day", nthDOWOfMonth 2 7 5 )
, ( "Thanksgiving Day", "thanks?giving( day)?", nthDOWOfMonth 4 4 11 )
]
rules :: [Rule]
rules =
[ ruleDDMM
, ruleDDMMYYYY
, ruleDDMMYYYYDot
]
++ rulePeriodicHolidays