-- Copyright (c) 2016-present, Facebook, Inc.
-- All rights reserved.
--
-- This source code is licensed under the BSD-style license found in the
-- LICENSE file in the root directory of this source tree.


{-# LANGUAGE GADTs #-}
{-# LANGUAGE NoRebindableSyntax #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE LambdaCase #-}

module Duckling.Time.ES.Rules
  ( rules
  ) where

import Prelude
import qualified Data.Text as Text

import Duckling.Dimensions.Types
import Duckling.Duration.Helpers (isGrain)
import Duckling.Numeral.Helpers (parseInt)
import Duckling.Ordinal.Types (OrdinalData(..))
import Duckling.Regex.Types
import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData(..))
import Duckling.Types
import qualified Duckling.Ordinal.Types as TOrdinal
import qualified Duckling.Time.Types as TTime
import qualified Duckling.TimeGrain.Types as TG

ruleTheDayAfterTomorrow :: Rule
ruleTheDayAfterTomorrow :: Rule
ruleTheDayAfterTomorrow = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"the day after tomorrow"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"pasado\\s?ma(n|ñ)ana"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> Int -> TimeData
cycleNth Grain
TG.Day Int
2
  }

ruleHaceDuration :: Rule
ruleHaceDuration :: Rule
ruleHaceDuration = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"hace <duration>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"hace"
    , Dimension DurationData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DurationData
Duration
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Duration a
dd:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ DurationData -> TimeData
durationAgo a
DurationData
dd
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleCeTime :: Rule
ruleCeTime :: Rule
ruleCeTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"ce <time>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"este"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Bool -> TimeData -> TimeData
predNth Int
0 Bool
False a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleDaysOfWeek :: [Rule]
ruleDaysOfWeek :: [Rule]
ruleDaysOfWeek = [(Text, String)] -> [Rule]
mkRuleDaysOfWeek
  [ ( Text
"Lunes"     , String
"lunes|lun?\\.?"                        )
  , ( Text
"Martes"    , String
"martes|mar?\\.?"                       )
  , ( Text
"Miercoles" , String
"mi(e|é)\\.?(rcoles)?|mx|mier?\\." )
  , ( Text
"Jueves"    , String
"jueves|jue|jue\\."                     )
  , ( Text
"Viernes"   , String
"viernes|vie|vie\\."                    )
  , ( Text
"Sabado"    , String
"s(á|a)bado|s(á|a)b\\.?"      )
  , ( Text
"Domingo"   , String
"domingo|dom\\.?"                       )
  ]

ruleMonths :: [Rule]
ruleMonths :: [Rule]
ruleMonths = [(Text, String)] -> [Rule]
mkRuleMonths
  [ ( Text
"Enero"     , String
"enero|ene\\.?")
  , ( Text
"Febrero"   , String
"febrero|feb\\.?")
  , ( Text
"Marzo"     , String
"marzo|mar\\.?")
  , ( Text
"Abril"     , String
"abril|abr\\.?")
  , ( Text
"Mayo"      , String
"mayo?\\.?")
  , ( Text
"Junio"     , String
"junio|jun\\.?")
  , ( Text
"Julio"     , String
"julio|jul\\.?")
  , ( Text
"Agosto"    , String
"agosto|ago\\.?")
  , ( Text
"Septiembre", String
"septiembre|sept?\\.?")
  , ( Text
"Octubre"   , String
"octubre|oct\\.?")
  , ( Text
"Noviembre" , String
"noviembre|nov\\.?")
  , ( Text
"Diciembre" , String
"diciembre|dic\\.?")
  ]

ruleThisDayofweek :: Rule
ruleThisDayofweek :: Rule
ruleThisDayofweek = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"this <day-of-week>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"este"
    , Predicate -> PatternItem
Predicate Predicate
isADayOfWeek
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Bool -> TimeData -> TimeData
predNth Int
0 Bool
True a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleDatetimeDatetimeInterval :: Rule
ruleDatetimeDatetimeInterval :: Rule
ruleDatetimeDatetimeInterval = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<datetime> - <datetime> (interval)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isNotLatent
    , String -> PatternItem
regex String
"\\-|al?"
    , Predicate -> PatternItem
Predicate Predicate
isNotLatent
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td1:Token
_:Token Dimension a
Time a
td2:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleEvening :: Rule
ruleEvening :: Rule
ruleEvening = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"evening"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"noche"
    ]
  , prod :: Production
prod = \[Token]
_ ->
      let from :: TimeData
from = Bool -> Int -> TimeData
hour Bool
False Int
18
          to :: TimeData
to = Bool -> Int -> TimeData
hour Bool
False Int
0
      in Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> (TimeData -> TimeData) -> TimeData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkLatent (TimeData -> TimeData)
-> (TimeData -> TimeData) -> TimeData -> TimeData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
partOfDay (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
           TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
from TimeData
to
  }

ruleDayOfMonthSt :: Rule
ruleDayOfMonthSt :: Rule
ruleDayOfMonthSt = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"day of month (1st)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"primero|uno|prem\\.?|1o"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> TimeData
dayOfMonth Int
1
  }

ruleEnDuration :: Rule
ruleEnDuration :: Rule
ruleEnDuration = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"en <duration>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"en"
    , Dimension DurationData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DurationData
Duration
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Duration a
dd:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ DurationData -> TimeData
inDuration a
DurationData
dd
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleNow :: Rule
ruleNow :: Rule
ruleNow = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"now"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(hoy)|(en este momento)"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt TimeData
today
  }

ruleUltimoDayofweekDeTime :: Rule
ruleUltimoDayofweekDeTime :: Rule
ruleUltimoDayofweekDeTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"ultimo <day-of-week> de <time>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(ú|u)ltimo"
    , Predicate -> PatternItem
Predicate Predicate
isADayOfWeek
    , String -> PatternItem
regex String
"de|en"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td1:Token
_:Token Dimension a
Time a
td2:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ TimeData -> TimeData -> TimeData
predLastOf a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleEntreDatetimeEtDatetimeInterval :: Rule
ruleEntreDatetimeEtDatetimeInterval :: Rule
ruleEntreDatetimeEtDatetimeInterval = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"entre <datetime> et <datetime> (interval)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"entre"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    , String -> PatternItem
regex String
"y"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td1:Token
_:Token Dimension a
Time a
td2:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleHhhmmTimeofday :: Rule
ruleHhhmmTimeofday :: Rule
ruleHhhmmTimeofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"hh(:|.|h)mm (time-of-day)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"((?:[01]?\\d)|(?:2[0-3]))[:h\\.]([0-5]\\d)"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
RegexMatch (GroupMatch (m1:m2:_)):[Token]
_) -> do
        Int
h <- Text -> Maybe Int
parseInt Text
m1
        Int
m <- Text -> Maybe Int
parseInt Text
m2
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
True Int
h Int
m
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleElDayofmonthDeNamedmonth :: Rule
ruleElDayofmonthDeNamedmonth :: Rule
ruleElDayofmonthDeNamedmonth = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"el <day-of-month> de <named-month>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"el"
    , Predicate -> PatternItem
Predicate Predicate
isDOMInteger
    , String -> PatternItem
regex String
"de"
    , Predicate -> PatternItem
Predicate Predicate
isAMonth
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token
token:Token
_:Token Dimension a
Time a
td:[Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> Token -> Maybe TimeData
intersectDOM a
TimeData
td Token
token
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleNPasadosCycle :: Rule
ruleNPasadosCycle :: Rule
ruleNPasadosCycle = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"n pasados <cycle>"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
2 Int
9999
    , String -> PatternItem
regex String
"pasad(a|o)s?"
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
token:Token
_:Token Dimension a
TimeGrain a
grain:[Token]
_) -> do
        Int
v <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData
cycleN Bool
True a
Grain
grain (- Int
v)
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleElProximoCycle :: Rule
ruleElProximoCycle :: Rule
ruleElProximoCycle = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"el proximo <cycle> "
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(el|los|la|las) ?"
    , String -> PatternItem
regex String
"pr(ó|o)xim(o|a)s?|siguientes?"
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token
_:Token Dimension a
TimeGrain a
grain:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> Int -> TimeData
cycleNth a
Grain
grain Int
1
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

rulePasadosNCycle :: Rule
rulePasadosNCycle :: Rule
rulePasadosNCycle = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"pasados n <cycle>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"pasad(a|o)s?"
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
2 Int
9999
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token
token:Token Dimension a
TimeGrain a
grain:[Token]
_) -> do
        Int
v <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData
cycleN Bool
True a
Grain
grain (- Int
v)
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleElDayofmonthNonOrdinal :: Rule
ruleElDayofmonthNonOrdinal :: Rule
ruleElDayofmonthNonOrdinal = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"el <day-of-month> (non ordinal)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"el"
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
1 Int
31
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token
token:[Token]
_) -> do
        Int
v <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> TimeData
dayOfMonth Int
v
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleNoon :: Rule
ruleNoon :: Rule
ruleNoon = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"noon"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"medio(\\s*)d(í|i)a"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> TimeData
hour Bool
False Int
12
  }

ruleProximasNCycle :: Rule
ruleProximasNCycle :: Rule
ruleProximasNCycle = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"proximas n <cycle>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"pr(ó|o)xim(o|a)s?"
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
2 Int
9999
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token
token:Token Dimension a
TimeGrain a
grain:[Token]
_) -> do
        Int
v <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData
cycleN Bool
True a
Grain
grain Int
v
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleNochevieja :: Rule
ruleNochevieja :: Rule
ruleNochevieja = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"Nochevieja"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"nochevieja"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Int -> TimeData
monthDay Int
12 Int
31
  }

ruleTheDayBeforeYesterday :: Rule
ruleTheDayBeforeYesterday :: Rule
ruleTheDayBeforeYesterday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"the day before yesterday"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"anteayer|antes de (ayer|anoche)|antier"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (Int -> TimeData) -> Int -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Grain -> Int -> TimeData
cycleNth Grain
TG.Day (Int -> Maybe Token) -> Int -> Maybe Token
forall a b. (a -> b) -> a -> b
$ - Int
2
  }

ruleHourofdayMinusIntegerAsRelativeMinutes :: Rule
ruleHourofdayMinusIntegerAsRelativeMinutes :: Rule
ruleHourofdayMinusIntegerAsRelativeMinutes = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<hour-of-day> minus <integer> (as relative minutes)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    , String -> PatternItem
regex String
"menos\\s?"
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
1 Int
59
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:Token
_:Token
token:[Token]
_) -> do
        Int
n <- Token -> Maybe Int
getIntValue Token
token
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> TimeData -> Maybe TimeData
minutesBefore Int
n a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleHourofdayMinusIntegerAsRelativeMinutes2 :: Rule
ruleHourofdayMinusIntegerAsRelativeMinutes2 :: Rule
ruleHourofdayMinusIntegerAsRelativeMinutes2 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<hour-of-day> minus <integer> (as relative minutes) minutes"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    , String -> PatternItem
regex String
"menos\\s?"
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
1 Int
59
    , String -> PatternItem
regex String
"min\\.?(uto)?s?"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:Token
_:Token
token:[Token]
_) -> do
        Int
n <- Token -> Maybe Int
getIntValue Token
token
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> TimeData -> Maybe TimeData
minutesBefore Int
n a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleHourofdayMinusQuarter :: Rule
ruleHourofdayMinusQuarter :: Rule
ruleHourofdayMinusQuarter = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<hour-of-day> minus quarter (as relative minutes)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    , String -> PatternItem
regex String
"menos\\s? cuarto"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:[Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> TimeData -> Maybe TimeData
minutesBefore Int
15 a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleHourofdayMinusHalf :: Rule
ruleHourofdayMinusHalf :: Rule
ruleHourofdayMinusHalf = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<hour-of-day> minus half (as relative minutes)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    , String -> PatternItem
regex String
"menos\\s? media"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:[Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> TimeData -> Maybe TimeData
minutesBefore Int
30 a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleHourofdayMinusThreeQuarter :: Rule
ruleHourofdayMinusThreeQuarter :: Rule
ruleHourofdayMinusThreeQuarter = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<hour-of-day> minus three quarter (as relative minutes)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    , String -> PatternItem
regex String
"menos\\s? (3|tres) cuartos?"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:[Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> TimeData -> Maybe TimeData
minutesBefore Int
45 a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleHourofdayIntegerAsRelativeMinutes :: Rule
ruleHourofdayIntegerAsRelativeMinutes :: Rule
ruleHourofdayIntegerAsRelativeMinutes = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<hour-of-day> <integer> (as relative minutes)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
and ([Bool] -> Bool) -> (Token -> [Bool]) -> Predicate
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Predicate] -> Token -> [Bool]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [Predicate
isAnHourOfDay]
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
1 Int
59
    ]
  , prod :: Production
prod = \case
      (Token Dimension a
Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)}:
       Token
minutes:
       [Token]
_) -> do
        Int
n <- Token -> Maybe Int
getIntValue Token
minutes
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
is12H Int
hours Int
n
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleHourofdayIntegerAsRelativeMinutes2 :: Rule
ruleHourofdayIntegerAsRelativeMinutes2 :: Rule
ruleHourofdayIntegerAsRelativeMinutes2 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<hour-of-day> <integer> (as relative minutes) minutes"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
1 Int
59
    , String -> PatternItem
regex String
"min\\.?(uto)?s?"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)}:
       Token
token:
       [Token]
_) -> do
        Int
n <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
is12H Int
hours Int
n
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleHourofdayQuarter :: Rule
ruleHourofdayQuarter :: Rule
ruleHourofdayQuarter = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<hour-of-day> quarter (as relative minutes)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    , String -> PatternItem
regex String
"cuarto"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)}:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
is12H Int
hours Int
15
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleHourofdayHalf :: Rule
ruleHourofdayHalf :: Rule
ruleHourofdayHalf = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<hour-of-day> half (as relative minutes)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    , String -> PatternItem
regex String
"media"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)}:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
is12H Int
hours Int
30
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleHourofdayThreeQuarter :: Rule
ruleHourofdayThreeQuarter :: Rule
ruleHourofdayThreeQuarter = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<hour-of-day> three quarters (as relative minutes)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    , String -> PatternItem
regex String
"(3|tres) cuartos?"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)}:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
is12H Int
hours Int
45
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleHourofdayAndRelativeMinutes :: Rule
ruleHourofdayAndRelativeMinutes :: Rule
ruleHourofdayAndRelativeMinutes = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<hour-of-day> and <relative minutes>"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    , String -> PatternItem
regex String
"y"
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
1 Int
59
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)}:
       Token
_:
       Token
token:
       [Token]
_) -> do
        Int
n <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
is12H Int
hours Int
n
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleHourofdayAndRelativeMinutes2 :: Rule
ruleHourofdayAndRelativeMinutes2 :: Rule
ruleHourofdayAndRelativeMinutes2 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<hour-of-day> and <relative minutes> minutes"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    , String -> PatternItem
regex String
"y"
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
1 Int
59
    , String -> PatternItem
regex String
"min\\.?(uto)?s?"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)}:
       Token
_:
       Token
token:
       [Token]
_) -> do
        Int
n <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
is12H Int
hours Int
n
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleHourofdayAndQuarter :: Rule
ruleHourofdayAndQuarter :: Rule
ruleHourofdayAndQuarter = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<hour-of-day> and quarter"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    , String -> PatternItem
regex String
"y cuarto"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)}:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
is12H Int
hours Int
15
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleHourofdayAndHalf :: Rule
ruleHourofdayAndHalf :: Rule
ruleHourofdayAndHalf = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<hour-of-day> and half"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    , String -> PatternItem
regex String
"y media"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)}:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
is12H Int
hours Int
30
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleHourofdayAndThreeQuarter :: Rule
ruleHourofdayAndThreeQuarter :: Rule
ruleHourofdayAndThreeQuarter = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<hour-of-day> and 3 quarters"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    , String -> PatternItem
regex String
"y (3|tres) cuartos?"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)}:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
is12H Int
hours Int
45
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleInThePartofday :: Rule
ruleInThePartofday :: Rule
ruleInThePartofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"in the <part-of-day>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(a|en|de|por) la"
    , Predicate -> PatternItem
Predicate Predicate
isAPartOfDay
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ TimeData -> TimeData
notLatent a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleDelYear :: Rule
ruleDelYear :: Rule
ruleDelYear = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"del <year>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"del( a(ñ|n)o)?"
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
1000 Int
2100
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token
token:[Token]
_) -> do
        Int
v <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> TimeData
year Int
v
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleDdmm :: Rule
ruleDdmm :: Rule
ruleDdmm = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"dd[/-]mm"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(3[01]|[12]\\d|0?[1-9])[/-](0?[1-9]|1[0-2])"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
RegexMatch (GroupMatch (m1:m2:_)):[Token]
_) -> do
        Int
d <- Text -> Maybe Int
parseInt Text
m1
        Int
m <- Text -> Maybe Int
parseInt Text
m2
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Int -> TimeData
monthDay Int
m Int
d
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleAfternoon :: Rule
ruleAfternoon :: Rule
ruleAfternoon = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"afternoon"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"tarde"
    ]
  , prod :: Production
prod = \[Token]
_ ->
      let from :: TimeData
from = Bool -> Int -> TimeData
hour Bool
False Int
12
          to :: TimeData
to = Bool -> Int -> TimeData
hour Bool
False Int
19
      in Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> (TimeData -> TimeData) -> TimeData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkLatent (TimeData -> TimeData)
-> (TimeData -> TimeData) -> TimeData -> TimeData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
partOfDay (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
           TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
from TimeData
to
  }

ruleMidnight :: Rule
ruleMidnight :: Rule
ruleMidnight = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"midnight"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"medianoche"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> TimeData
hour Bool
False Int
0
  }

ruleAnoNuevo :: Rule
ruleAnoNuevo :: Rule
ruleAnoNuevo = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"ano nuevo"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"a(n|ñ)o nuevo"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Int -> TimeData
monthDay Int
1 Int
1
  }

ruleDdddMonthinterval :: Rule
ruleDdddMonthinterval :: Rule
ruleDdddMonthinterval = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"dd-dd <month>(interval)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(3[01]|[12]\\d|0?[1-9])"
    , String -> PatternItem
regex String
"\\-|al?"
    , String -> PatternItem
regex String
"(3[01]|[12]\\d|0?[1-9])"
    , String -> PatternItem
regex String
"de"
    , Predicate -> PatternItem
Predicate Predicate
isAMonth
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
RegexMatch (GroupMatch (m1:_)):
       Token
_:
       Token Dimension a
RegexMatch (GroupMatch (m2:_)):
       Token
_:
       Token Dimension a
Time a
td:
       [Token]
_) -> do
        Int
d1 <- Text -> Maybe Int
parseInt Text
m1
        Int
d2 <- Text -> Maybe Int
parseInt Text
m2
        TimeData
from <- TimeData -> TimeData -> Maybe TimeData
intersect (Int -> TimeData
dayOfMonth Int
d1) a
TimeData
td
        TimeData
to <- TimeData -> TimeData -> Maybe TimeData
intersect (Int -> TimeData
dayOfMonth Int
d2) a
TimeData
td
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Closed TimeData
from TimeData
to
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTimeofdayLatent :: Rule
ruleTimeofdayLatent :: Rule
ruleTimeofdayLatent = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"time-of-day (latent)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
0 Int
23
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
token:[Token]
_) -> do
        Int
v <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (TimeData -> TimeData) -> TimeData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkLatent (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> TimeData
hour (Int
v Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
13) Int
v
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleNamedmonthnameddayPast :: Rule
ruleNamedmonthnameddayPast :: Rule
ruleNamedmonthnameddayPast = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<named-month|named-day> past"
  , pattern :: Pattern
pattern =
    [ Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    , String -> PatternItem
regex String
"pasad(o|a)"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Bool -> TimeData -> TimeData
predNth (-Int
1) Bool
False a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleSeasons :: [Rule]
ruleSeasons :: [Rule]
ruleSeasons = [(Text, String, TimeData, TimeData)] -> [Rule]
mkRuleSeasons
  [ ( Text
"verano"   , String
"verano"   , Int -> Int -> TimeData
monthDay  Int
6 Int
21, Int -> Int -> TimeData
monthDay  Int
9 Int
23 )
  , ( Text
"otoño"    , String
"oto(ñ|n)o", Int -> Int -> TimeData
monthDay  Int
9 Int
23, Int -> Int -> TimeData
monthDay Int
12 Int
21 )
  , ( Text
"invierno" , String
"invierno" , Int -> Int -> TimeData
monthDay Int
12 Int
21, Int -> Int -> TimeData
monthDay  Int
3 Int
20 )
  , ( Text
"primavera", String
"primavera", Int -> Int -> TimeData
monthDay  Int
3 Int
20, Int -> Int -> TimeData
monthDay  Int
6 Int
21 )
  ]

ruleRightNow :: Rule
ruleRightNow :: Rule
ruleRightNow = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"right now"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"ahor(it)?a|ya|en\\s?seguida|cuanto antes"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt TimeData
now
  }

ruleDimTimeDeLaTarde :: Rule
ruleDimTimeDeLaTarde :: Rule
ruleDimTimeDeLaTarde = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<dim time> de la tarde"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
    , String -> PatternItem
regex String
"(a|en|de) la tarde"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:[Token]
_) -> do
        TimeData
tarde <- TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open (Bool -> Int -> TimeData
hour Bool
False Int
12) (Bool -> Int -> TimeData
hour Bool
False Int
21)
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect a
TimeData
td (TimeData -> TimeData
mkLatent (TimeData -> TimeData) -> TimeData -> TimeData
forall a b. (a -> b) -> a -> b
$ TimeData -> TimeData
partOfDay TimeData
tarde)
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleDimTimeDeLaTarde2 :: Rule
ruleDimTimeDeLaTarde2 :: Rule
ruleDimTimeDeLaTarde2 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<time-of-day> de la tarde"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
1 Int
59
    , String -> PatternItem
regex String
"(a|en|de) la tarde"
    ]
  , prod :: Production
prod = \case
      (Token Dimension a
Time TimeData {
          TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)
        }:
        Token
minutesToken:
       Token
_:
       [Token]
_) -> do
         Int
minutes <- Token -> Maybe Int
getIntValue Token
minutesToken
         let td :: TimeData
td = Bool -> Int -> Int -> TimeData
hourMinute Bool
is12H Int
hours Int
minutes
         TimeData
tarde <- TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open (Bool -> Int -> TimeData
hour Bool
False Int
12) (Bool -> Int -> TimeData
hour Bool
False Int
21)
         Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect TimeData
td (TimeData -> TimeData
mkLatent (TimeData -> TimeData) -> TimeData -> TimeData
forall a b. (a -> b) -> a -> b
$ TimeData -> TimeData
partOfDay TimeData
tarde)
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleIntegerInThePartofday :: Rule
ruleIntegerInThePartofday :: Rule
ruleIntegerInThePartofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<integer> in the <part-of-day>"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAPartOfDay
    , String -> PatternItem
regex String
"(a|en|de|por) la"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td1:Token
_:Token Dimension a
Time a
td2:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleNCycleProximoqueViene :: Rule
ruleNCycleProximoqueViene :: Rule
ruleNCycleProximoqueViene = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"n <cycle> (proximo|que viene)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
2 Int
9999
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    , String -> PatternItem
regex String
"(pr(ó|o)xim(o|a)s?|que vienen?|siguientes?)"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
token:Token Dimension a
TimeGrain a
grain:[Token]
_) -> do
        Int
v <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData
cycleN Bool
True a
Grain
grain Int
v
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleNamedmonthnameddayNext :: Rule
ruleNamedmonthnameddayNext :: Rule
ruleNamedmonthnameddayNext = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<named-month|named-day> next"
  , pattern :: Pattern
pattern =
    [ Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    , String -> PatternItem
regex String
"que vienen?"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Bool -> TimeData -> TimeData
predNth Int
1 Bool
False a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleIntersect :: Rule
ruleIntersect :: Rule
ruleIntersect = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"intersect"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isNotLatent
    , Predicate -> PatternItem
Predicate Predicate
isNotLatent
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td1:Token Dimension a
Time a
td2:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTimeofdayPartofday :: Rule
ruleTimeofdayPartofday :: Rule
ruleTimeofdayPartofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<time-of-day> <part-of-day>"
  , pattern :: Pattern
pattern =
    [ Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    , Predicate -> PatternItem
Predicate Predicate
isAPartOfDay
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td1:Token Dimension a
Time a
td2:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleDimTimeDeLaManana :: Rule
ruleDimTimeDeLaManana :: Rule
ruleDimTimeDeLaManana = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<dim time> de la manana"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
    , String -> PatternItem
regex String
"(a|en|de) la ma(ñ|n)ana"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:[Token]
_) -> do
        TimeData
manana <- TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open (Bool -> Int -> TimeData
hour Bool
False Int
0) (Bool -> Int -> TimeData
hour Bool
False Int
12)
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect a
TimeData
td (TimeData -> TimeData
mkLatent (TimeData -> TimeData) -> TimeData -> TimeData
forall a b. (a -> b) -> a -> b
$ TimeData -> TimeData
partOfDay TimeData
manana)
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleDeDatetimeDatetimeInterval :: Rule
ruleDeDatetimeDatetimeInterval :: Rule
ruleDeDatetimeDatetimeInterval = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"de <datetime> - <datetime> (interval)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"del?"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    , String -> PatternItem
regex String
"\\-|al?"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td1:Token
_:Token Dimension a
Time a
td2:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleNthTimeDeTime2 :: Rule
ruleNthTimeDeTime2 :: Rule
ruleNthTimeDeTime2 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"nth <time> de <time>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"the"
    , Dimension OrdinalData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension OrdinalData
Ordinal
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    , String -> PatternItem
regex String
"de|en"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:
       Token Dimension a
Ordinal OrdinalData{TOrdinal.value = v}:
       Token Dimension a
Time a
td1:
       Token
_:
       Token Dimension a
Time a
td2:
       [Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> (TimeData -> TimeData) -> TimeData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Bool -> TimeData -> TimeData
predNth (Int
v Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Bool
False (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect a
TimeData
td2 a
TimeData
td1
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleDentroDeDuration :: Rule
ruleDentroDeDuration :: Rule
ruleDentroDeDuration = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"dentro de <duration>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"dentro de"
    , Dimension DurationData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DurationData
Duration
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Duration a
dd:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
now (DurationData -> TimeData
inDuration a
DurationData
dd)
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleWeekend :: Rule
ruleWeekend :: Rule
ruleWeekend = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"week-end"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"week[ -]?end|fin de semana"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt TimeData
weekend
  }

ruleOrdinalQuarterYear :: Rule
ruleOrdinalQuarterYear :: Rule
ruleOrdinalQuarterYear = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<ordinal> quarter <year>"
  , pattern :: Pattern
pattern =
    [ Dimension OrdinalData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension OrdinalData
Ordinal
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Grain -> Predicate
isGrain Grain
TG.Quarter
    , String -> PatternItem
regex String
"del? ?"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Ordinal OrdinalData{TOrdinal.value = v}:Token
_:Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Quarter (Int
v Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleYyyymmdd :: Rule
ruleYyyymmdd :: Rule
ruleYyyymmdd = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"yyyy-mm-dd"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(\\d{2,4})-(0?[1-9]|1[0-2])-(3[01]|[12]\\d|0?[1-9])"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
RegexMatch (GroupMatch (m1:m2:m3:_)):[Token]
_) -> do
        Int
y <- Text -> Maybe Int
parseInt Text
m1
        Int
m <- Text -> Maybe Int
parseInt Text
m2
        Int
d <- Text -> Maybe Int
parseInt Text
m3
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Int -> TimeData
yearMonthDay Int
y Int
m Int
d
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTimeofdayHoras :: Rule
ruleTimeofdayHoras :: Rule
ruleTimeofdayHoras = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<time-of-day> horas"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
    , String -> PatternItem
regex String
"h\\.?(ora)?s?"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ TimeData -> TimeData
mkLatent a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleNavidad :: Rule
ruleNavidad :: Rule
ruleNavidad = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"Navidad"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(la )?navidad"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Int -> TimeData
monthDay Int
12 Int
25
  }

ruleElCycleAntesTime :: Rule
ruleElCycleAntesTime :: Rule
ruleElCycleAntesTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"el <cycle> antes <time>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"l[ea']? ?"
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    , String -> PatternItem
regex String
"antes de"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
TimeGrain a
grain:Token
_:Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False a
Grain
grain (-Int
1) a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTwoTimeTokensSeparatedBy :: Rule
ruleTwoTimeTokensSeparatedBy :: Rule
ruleTwoTimeTokensSeparatedBy = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"two time tokens separated by \",\""
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isNotLatent
    , String -> PatternItem
regex String
","
    , Predicate -> PatternItem
Predicate Predicate
isNotLatent
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td1:Token
_:Token Dimension a
Time a
td2:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleMorning :: Rule
ruleMorning :: Rule
ruleMorning = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"morning"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"ma(ñ|n)ana"
    ]
  , prod :: Production
prod = \[Token]
_ ->
      let from :: TimeData
from = Bool -> Int -> TimeData
hour Bool
False Int
4
          to :: TimeData
to = Bool -> Int -> TimeData
hour Bool
False Int
12
      in Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> (TimeData -> TimeData) -> TimeData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkLatent (TimeData -> TimeData)
-> (TimeData -> TimeData) -> TimeData -> TimeData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
partOfDay (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
           TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
from TimeData
to
  }

ruleALasHourmintimeofday :: Rule
ruleALasHourmintimeofday :: Rule
ruleALasHourmintimeofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"a las <hour-min>(time-of-day)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"((al?)( las?)?|las?)"
    , Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
    , String -> PatternItem
regex String
"horas?"
    ]
  , prod :: Production
prod = \case
      ( Token
_:
        Token
x:
        [Token]
_) -> Token -> Maybe Token
forall a. a -> Maybe a
Just Token
x
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleThisPartofday :: Rule
ruleThisPartofday :: Rule
ruleThisPartofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"this <part-of-day>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"est(e|a)"
    , Predicate -> PatternItem
Predicate Predicate
isAPartOfDay
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> (TimeData -> TimeData) -> TimeData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
partOfDay (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect TimeData
today a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleLaCyclePasado :: Rule
ruleLaCyclePasado :: Rule
ruleLaCyclePasado = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"la <cycle> pasado"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(el|los|la|las) ?"
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    , String -> PatternItem
regex String
"pasad(a|o)s?|(u|ú)ltim[ao]s?"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
TimeGrain a
grain:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (Int -> TimeData) -> Int -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Grain -> Int -> TimeData
cycleNth a
Grain
grain (Int -> Maybe Token) -> Int -> Maybe Token
forall a b. (a -> b) -> a -> b
$ - Int
1
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleYearLatent :: Rule
ruleYearLatent :: Rule
ruleYearLatent = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"year (latent)"
  , pattern :: Pattern
pattern =
      [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$
        [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
or ([Bool] -> Bool) -> (Token -> [Bool]) -> Predicate
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Predicate] -> Token -> [Bool]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [Int -> Int -> Predicate
isIntegerBetween (- Int
10000) Int
0, Int -> Int -> Predicate
isIntegerBetween Int
25 Int
10000]
      ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
token:[Token]
_) -> do
        Int
n <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (TimeData -> TimeData) -> TimeData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkLatent (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> TimeData
year Int
n
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleYesterday :: Rule
ruleYesterday :: Rule
ruleYesterday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"yesterday"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"ayer"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (Int -> TimeData) -> Int -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Grain -> Int -> TimeData
cycleNth Grain
TG.Day (Int -> Maybe Token) -> Int -> Maybe Token
forall a b. (a -> b) -> a -> b
$ - Int
1
  }

ruleDayofweekDayofmonth :: Rule
ruleDayofweekDayofmonth :: Rule
ruleDayofweekDayofmonth = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<day-of-week> <day-of-month>"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isADayOfWeek
    , Predicate -> PatternItem
Predicate Predicate
isDOMInteger
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:Token
token:[Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> Token -> Maybe TimeData
intersectDOM a
TimeData
td Token
token
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTimeofdayAmpm :: Rule
ruleTimeofdayAmpm :: Rule
ruleTimeofdayAmpm = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<time-of-day> am|pm"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
    , String -> PatternItem
regex String
"([ap])\\.?m?\\.?"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:Token Dimension a
RegexMatch (GroupMatch (ap:_)):[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> TimeData -> TimeData
timeOfDayAMPM (Text -> Text
Text.toLower Text
ap Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"a") a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleDayofmonthDeNamedmonth :: Rule
ruleDayofmonthDeNamedmonth :: Rule
ruleDayofmonthDeNamedmonth = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<day-of-month> de <named-month>"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isDOMInteger
    , String -> PatternItem
regex String
"de"
    , Predicate -> PatternItem
Predicate Predicate
isAMonth
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
token:Token
_:Token Dimension a
Time a
td:[Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> Token -> Maybe TimeData
intersectDOM a
TimeData
td Token
token
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleEntreDdEtDdMonthinterval :: Rule
ruleEntreDdEtDdMonthinterval :: Rule
ruleEntreDdEtDdMonthinterval = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"entre dd et dd <month>(interval)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"entre( el)?"
    , String -> PatternItem
regex String
"(0?[1-9]|[12]\\d|3[01])"
    , String -> PatternItem
regex String
"y( el)?"
    , String -> PatternItem
regex String
"(0?[1-9]|[12]\\d|3[01])"
    , String -> PatternItem
regex String
"de"
    , Predicate -> PatternItem
Predicate Predicate
isAMonth
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:
       Token Dimension a
RegexMatch (GroupMatch (m1:_)):
       Token
_:
       Token Dimension a
RegexMatch (GroupMatch (m2:_)):
       Token
_:
       Token Dimension a
Time a
td:
       [Token]
_) -> do
        Int
v1 <- Text -> Maybe Int
parseInt Text
m1
        Int
v2 <- Text -> Maybe Int
parseInt Text
m2
        TimeData
from <- TimeData -> TimeData -> Maybe TimeData
intersect (Int -> TimeData
dayOfMonth Int
v1) a
TimeData
td
        TimeData
to <- TimeData -> TimeData -> Maybe TimeData
intersect (Int -> TimeData
dayOfMonth Int
v2) a
TimeData
td
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Closed TimeData
from TimeData
to
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleNamedmonthDayofmonth :: Rule
ruleNamedmonthDayofmonth :: Rule
ruleNamedmonthDayofmonth = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<named-month> <day-of-month>"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAMonth
    , Predicate -> PatternItem
Predicate Predicate
isDOMInteger
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:Token
token:[Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> Token -> Maybe TimeData
intersectDOM a
TimeData
td Token
token
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleElTime :: Rule
ruleElTime :: Rule
ruleElTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"el <time>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"d?el"
    , Predicate -> PatternItem
Predicate Predicate
isNotLatent
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token
x:[Token]
_) -> Token -> Maybe Token
forall a. a -> Maybe a
Just Token
x
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleYear :: Rule
ruleYear :: Rule
ruleYear = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"year"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
1000 Int
2100
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
token:[Token]
_) -> do
        Int
v <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> TimeData
year Int
v
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleEsteenUnCycle :: Rule
ruleEsteenUnCycle :: Rule
ruleEsteenUnCycle = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"este|en un <cycle>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(est(e|a|os)|en (el|los|la|las) ?)"
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
TimeGrain a
grain:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> Int -> TimeData
cycleNth a
Grain
grain Int
0
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleNProximasCycle :: Rule
ruleNProximasCycle :: Rule
ruleNProximasCycle = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"n proximas <cycle>"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
2 Int
9999
    , String -> PatternItem
regex String
"pr(ó|o)xim(o|a)s?"
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
token:Token
_:Token Dimension a
TimeGrain a
grain:[Token]
_) -> do
        Int
v <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData
cycleN Bool
True a
Grain
grain Int
v
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleLaPasadoCycle :: Rule
ruleLaPasadoCycle :: Rule
ruleLaPasadoCycle = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"la pasado <cycle>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(el|los|la|las) ?"
    , String -> PatternItem
regex String
"pasad(a|o)s?|(u|ú)ltim[ao]s?"
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token
_:Token Dimension a
TimeGrain a
grain:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (Int -> TimeData) -> Int -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Grain -> Int -> TimeData
cycleNth a
Grain
grain (Int -> Maybe Token) -> Int -> Maybe Token
forall a b. (a -> b) -> a -> b
$ - Int
1
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleALasTimeofday :: Rule
ruleALasTimeofday :: Rule
ruleALasTimeofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"a las <time-of-day>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"((para)|(al?))( las?)?|las?"
    , Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ TimeData -> TimeData
notLatent a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleDdmmyyyy :: Rule
ruleDdmmyyyy :: Rule
ruleDdmmyyyy = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"dd[/-.]mm[/-.]yyyy"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(3[01]|[12]\\d|0?[1-9])[\\./-](0?[1-9]|1[0-2])[\\./-](\\d{2,4})"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
RegexMatch (GroupMatch (m1:m2:m3:_)):[Token]
_) -> do
        Int
d <- Text -> Maybe Int
parseInt Text
m1
        Int
m <- Text -> Maybe Int
parseInt Text
m2
        Int
y <- Text -> Maybe Int
parseInt Text
m3
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Int -> TimeData
yearMonthDay Int
y Int
m Int
d
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleOrdinalQuarter :: Rule
ruleOrdinalQuarter :: Rule
ruleOrdinalQuarter = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<ordinal> quarter"
  , pattern :: Pattern
pattern =
    [ Dimension OrdinalData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension OrdinalData
Ordinal
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Grain -> Predicate
isGrain Grain
TG.Quarter
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Ordinal OrdinalData{TOrdinal.value = v}:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (TimeData -> TimeData) -> TimeData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Quarter (Int
v Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
          (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> Int -> TimeData
cycleNth Grain
TG.Year Int
0
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleElCycleProximoqueViene :: Rule
ruleElCycleProximoqueViene :: Rule
ruleElCycleProximoqueViene = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"el <cycle> (proximo|que viene)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(el|los|la|las) ?"
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    , String -> PatternItem
regex String
"(pr(ó|o)xim(o|a)s?|que vienen?|siguientes?)"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
TimeGrain a
grain:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> Int -> TimeData
cycleNth a
Grain
grain Int
1
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleElCycleProximoqueVieneTime :: Rule
ruleElCycleProximoqueVieneTime :: Rule
ruleElCycleProximoqueVieneTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"el <cycle> proximo|que viene <time>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(el|los|la|las)"
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    , String -> PatternItem
regex String
"(pr(ó|o)xim(o|a)s?|que vienen?|siguientes?)"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
TimeGrain a
grain:Token
_:Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False a
Grain
grain Int
1 a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleDelMedioda :: Rule
ruleDelMedioda :: Rule
ruleDelMedioda = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"del mediodía"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"del mediod(i|í)a"
    ]
  , prod :: Production
prod = \[Token]
_ ->
      let from :: TimeData
from = Bool -> Int -> TimeData
hour Bool
False Int
12
          to :: TimeData
to = Bool -> Int -> TimeData
hour Bool
False Int
17
      in Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> (TimeData -> TimeData) -> TimeData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkLatent (TimeData -> TimeData)
-> (TimeData -> TimeData) -> TimeData -> TimeData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
partOfDay (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
           TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
from TimeData
to
  }

ruleIntersectByDe :: Rule
ruleIntersectByDe :: Rule
ruleIntersectByDe = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"intersect by `de`"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isNotLatent
    , String -> PatternItem
regex String
"de"
    , Predicate -> PatternItem
Predicate Predicate
isNotLatent
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td1:Token
_:Token Dimension a
Time a
td2:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTomorrow :: Rule
ruleTomorrow :: Rule
ruleTomorrow = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"tomorrow"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"ma(n|ñ)ana"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> Int -> TimeData
cycleNth Grain
TG.Day Int
1
  }

ruleNthTimeDeTime :: Rule
ruleNthTimeDeTime :: Rule
ruleNthTimeDeTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"nth <time> de <time>"
  , pattern :: Pattern
pattern =
    [ Dimension OrdinalData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension OrdinalData
Ordinal
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    , String -> PatternItem
regex String
"de|en"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Ordinal OrdinalData{TOrdinal.value = v}:
       Token Dimension a
Time a
td1:
       Token
_:
       Token Dimension a
Time a
td2:
       [Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> (TimeData -> TimeData) -> TimeData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Bool -> TimeData -> TimeData
predNth (Int
v Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Bool
False (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect a
TimeData
td2 a
TimeData
td1
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTimezone :: Rule
ruleTimezone :: Rule
ruleTimezone = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<time> timezone"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
and ([Bool] -> Bool) -> (Token -> [Bool]) -> Predicate
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Predicate] -> Token -> [Bool]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [Predicate
isATimeOfDay, Predicate
isNotLatent]
    , String -> PatternItem
regex String
"\\b(YEKT|YEKST|YAKT|YAKST|WITA|WIT|WIB|WGT|WGST|WFT|WET|WEST|WAT|WAST|VUT|VLAT|VLAST|VET|UZT|UYT|UYST|UTC|ULAT|TVT|TMT|TLT|TKT|TJT|TFT|TAHT|SST|SRT|SGT|SCT|SBT|SAST|SAMT|RET|PYT|PYST|PWT|PST|PONT|PMST|PMDT|PKT|PHT|PHOT|PGT|PETT|PETST|PET|PDT|OMST|OMSST|NZST|NZDT|NUT|NST|NPT|NOVT|NOVST|NFT|NDT|NCT|MYT|MVT|MUT|MST|MSK|MSD|MMT|MHT|MDT|MAWT|MART|MAGT|MAGST|LINT|LHST|LHDT|KUYT|KST|KRAT|KRAST|KGT|JST|IST|IRST|IRKT|IRKST|IRDT|IOT|IDT|ICT|HOVT|HKT|GYT|GST|GMT|GILT|GFT|GET|GAMT|GALT|FNT|FKT|FKST|FJT|FJST|EST|EGT|EGST|EET|EEST|EDT|ECT|EAT|EAST|EASST|DAVT|ChST|CXT|CVT|CST|COT|CLT|CLST|CKT|CHAST|CHADT|CET|CEST|CDT|CCT|CAT|CAST|BTT|BST|BRT|BRST|BOT|BNT|AZT|AZST|AZOT|AZOST|AWST|AWDT|AST|ART|AQTT|ANAT|ANAST|AMT|AMST|ALMT|AKST|AKDT|AFT|AEST|AEDT|ADT|ACST|ACDT)\\b"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:
       Token Dimension a
RegexMatch (GroupMatch (tz:_)):
       [Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> TimeData -> Maybe TimeData
inTimezone (Text -> Text
Text.toUpper Text
tz) a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleNextWeek :: Rule
ruleNextWeek :: Rule
ruleNextWeek = Rule :: Text -> Pattern -> Production -> Rule
Rule
  {
    name :: Text
name = Text
"next week"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Grain -> Predicate
isGrain Grain
TG.Week
    , String -> PatternItem
regex String
"que viene"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> Int -> TimeData
cycleNth Grain
TG.Week Int
1
  }

rulePeriodicHolidays :: [Rule]
rulePeriodicHolidays :: [Rule]
rulePeriodicHolidays = [(Text, String, TimeData)] -> [Rule]
mkRuleHolidays
  -- Fixed dates, year over year
  [ ( Text
"Día de África", String
"d(í|i)a de (la (libertad|liberacion) )?(á|a)frica(na)?", Int -> Int -> TimeData
monthDay Int
5 Int
25 )
  , ( Text
"Día de la Industrialización de África", String
"d(í|i)a de (la )?industrializaci(ó|o)n de (á|a)frica(na)?", Int -> Int -> TimeData
monthDay Int
11 Int
20 )
  , ( Text
"Día de Todos los Santos", String
"d(í|i)a de todos los santos", Int -> Int -> TimeData
monthDay Int
11 Int
1 )
  , ( Text
"Día de las Almas", String
"d(í|i)a de las almas", Int -> Int -> TimeData
monthDay Int
11 Int
2 )
  , ( Text
"Día de los Inocentes de Abril", String
"d(í|i)a de (los inocentes|las bromas)( de abril)?", Int -> Int -> TimeData
monthDay Int
4 Int
1 )
  , ( Text
"Día Mundial de la Lengua Árabe", String
"d(í|i)a mundial de la lengua (á|a)rabe", Int -> Int -> TimeData
monthDay Int
12 Int
18 )
  , ( Text
"Asunción de María", String
"asunci(ó|o)n de mar(í|i)a", Int -> Int -> TimeData
monthDay Int
8 Int
15 )
  , ( Text
"Día del Boxeo", String
"(el )?d(í|i)a del (boxeo|boxeador)", Int -> Int -> TimeData
monthDay Int
12 Int
26 )
  , ( Text
"Día de Lengua China", String
"d(í|i)a de lengua china", Int -> Int -> TimeData
monthDay Int
4 Int
20 )
  , ( Text
"Nochebuena", String
"(la (cena de )?)?(nochebuena|noche buena)", Int -> Int -> TimeData
monthDay Int
12 Int
24 )
  , ( Text
"Día de Conmemoración de las Víctimas de la Guerra Química", String
"d(í|i)a (de )?(conmemorativo|conmemoraci(ó|o)n) (en recuerdo )?de las v(í|i)ctimas de la guerra qu(í|i)mica", Int -> Int -> TimeData
monthDay Int
4 Int
29 )
  , ( Text
"Día de Conmemoración de las Víctimas del Genocidio de Ruanda", String
"d(í|i)a (de )?(conmemorativo|conmemoraci(ó|o)n) (en recuerdo )?de las v(í|i)ctimas del genocidio de ruanda", Int -> Int -> TimeData
monthDay Int
4 Int
7 )
  , ( Text
"Día de la Marina", String
"d(í|i)a (de la|del) marin(a|o)", Int -> Int -> TimeData
monthDay Int
6 Int
25 )
  , ( Text
"Día de la Tierra", String
"d(í|i)a (internacional )?de la (madre )?tierra", Int -> Int -> TimeData
monthDay Int
4 Int
22 )
  , ( Text
"Día de la Lengua Inglesa", String
"d(í|i)a de la lengua inglesa", Int -> Int -> TimeData
monthDay Int
4 Int
23 )
  , ( Text
"Epifanía", String
"Epifan(í|i)a", Int -> Int -> TimeData
monthDay Int
1 Int
6 )
  , ( Text
"Las Fiestas de San Francisco de Asís", String
"(las )?fiestas de san (francisco de as(í|i)s|pacho)", Int -> Int -> TimeData
monthDay Int
10 Int
4 )
  , ( Text
"Fiesta de la Inmaculada Concepción", String
"(d(í|i)a|fiesta) de la inmaculada concepci(ó|o)n( de (la virgen )?mar(í|i)a)?", Int -> Int -> TimeData
monthDay Int
12 Int
8 )
  , ( Text
"Día Mundial de las Madres y de los Padres", String
"d(í|i)a mundial de las madres y de los padres", Int -> Int -> TimeData
monthDay Int
6 Int
1 )
  , ( Text
"Día de Todos los Santos", String
"(d(í|i)a|festividad) de todos los santos", Int -> Int -> TimeData
monthDay Int
10 Int
31 )
  , ( Text
"Día de los Derechos Humanos", String
"d(í|i)a de los derechos humanos", Int -> Int -> TimeData
monthDay Int
12 Int
10 )
  , ( Text
"Día Internacional de Sensibilización sobre el Albinismo", String
"d(í|i)a internacional de sensibilizaci(ó|o)n sobre el albinismo", Int -> Int -> TimeData
monthDay Int
6 Int
13 )
  , ( Text
"Día Internacional contra la Corrupción", String
"d(í|i)a internacional contra la corrupci(ó|o)n", Int -> Int -> TimeData
monthDay Int
12 Int
9 )
  , ( Text
"Día Internacional de los Asteroides", String
"d(í|i)a internacional de los asteroides", Int -> Int -> TimeData
monthDay Int
6 Int
30 )
  , ( Text
"Celebra el Día Internacional de la Bisexualidad", String
"celebra el d(í|i)a internacional de la bisexualidad", Int -> Int -> TimeData
monthDay Int
9 Int
23 )
  , ( Text
"Día Internacional de Recordación de Desastres de Chernóbil", String
"d(í|i)a internacional de recordaci(ó|o)n de desastres de chern(ó|o)bil ", Int -> Int -> TimeData
monthDay Int
4 Int
26 )
  , ( Text
"Día Internacional de la Aviacion Civil", String
"d(í|i)a internacional de la aviacion civil", Int -> Int -> TimeData
monthDay Int
12 Int
7 )
  , ( Text
"Día Internacional de la Aduana", String
"d(í|i)a internacional de la(s)? aduana(s)?", Int -> Int -> TimeData
monthDay Int
1 Int
26 )
  , ( Text
"Día Internacional de la Lucha contra el Uso Indebido y el Tráfico Ilícito de Drogas", String
"d(í|i)a internacional de la lucha contra el uso indebido y el tr(á|a)fico il(í|i)cito de drogas", Int -> Int -> TimeData
monthDay Int
6 Int
26 )
  , ( Text
"Día Internacional contra los Ensayos Nucleares", String
"d(í|i)a internacional contra los ensayos nucleares", Int -> Int -> TimeData
monthDay Int
8 Int
29 )
  , ( Text
"Día Internacional de la Diversidad Biológica", String
"d(í|i)a internacional de la diversidad biol(ó|o)gica", Int -> Int -> TimeData
monthDay Int
5 Int
22 )
  , ( Text
"Día Internacional de los Monumentos y Sitios", String
"d(í|i)a internacional de los monumentos y sitios", Int -> Int -> TimeData
monthDay Int
4 Int
18 )
  , ( Text
"Día Internacional para la Prevención de la Explotación del medio ambiente en la Guerra y los Conflictos Armados", String
"d(í|i)a internacional para la prevenci(ó|o)n de la explotaci(ó|o)n del medio ambiente en la guerra y los conflictos armados", Int -> Int -> TimeData
monthDay Int
11 Int
6 )
  , ( Text
"Día de las Naciones Unidas para la Cooperación Sur-Sur", String
"d(í|i)a de las naciones unidas para la cooperaci(ó|o)n sur(\\-|\\s)sur", Int -> Int -> TimeData
monthDay Int
9 Int
12 )
  , ( Text
"Día Internacional para la Tolerancia", String
"d(í|i)a internacional (de|para) la tolerancia", Int -> Int -> TimeData
monthDay Int
11 Int
16 )
  , ( Text
"Día Internacional para la Abolición de la Esclavitud", String
"d(í|i)a internacional para la abolici(ó|o)n de la esclavitud", Int -> Int -> TimeData
monthDay Int
12 Int
2 )
  , ( Text
"Día Internacional de la Eliminación de la Discriminación Racial", String
"d(í|i)a internacional de la eliminaci(ó|o)n de la discriminaci(ó|o)n racial", Int -> Int -> TimeData
monthDay Int
3 Int
21 )
  , ( Text
"Día Internacional de la Eliminación de la Violencia Sexual en los Conflictos", String
"d(í|i)a internacional de la eliminaci(ó|o)n de la violencia sexual en los conflictos", Int -> Int -> TimeData
monthDay Int
6 Int
19 )
  , ( Text
"Día Internacional de la Eliminación de la Violencia contra la Mujer", String
"d(í|i)a internacional de la eliminaci(ó|o)n de la violencia contra la mujer.", Int -> Int -> TimeData
monthDay Int
11 Int
25 )
  , ( Text
"Día Internacional para la Erradicación de la Pobreza", String
"d(í|i)a internacional para la erradicaci(ó|o)n de la pobreza", Int -> Int -> TimeData
monthDay Int
10 Int
17 )
  , ( Text
"Día Internacional de la Preservación de la Capa de Ozono", String
"d(í|i)a internacional de la preservaci(ó|o)n de la capa de ozono", Int -> Int -> TimeData
monthDay Int
9 Int
16 )
  , ( Text
"Día Internacional del Recuerdo de la Trata de Esclavos y de su Abolición", String
"d(í|i)a internacional del recuerdo de la trata de esclavos y de su abolici(ó|o)n", Int -> Int -> TimeData
monthDay Int
8 Int
23 )
  , ( Text
"Día Internacional del Derecho a la Verdad en relación con Violaciones Graves de los Derechos Humanos y de la Dignidad de las Víctimas de las Naciones Unidas", String
"d(í|i)a internacional del derecho a la verdad en relaci(ó|o)n con violaciones graves de los derechos humanos y de la dignidad de las v(í|i)ctimas de las naciones unidas", Int -> Int -> TimeData
monthDay Int
3 Int
24 )
  , ( Text
"Día Internacional para la Eliminación Total de las Armas Nucleares", String
"d(í|i)a internacional para la eliminaci(ó|o)n total de las armas nucleares", Int -> Int -> TimeData
monthDay Int
9 Int
26 )
  , ( Text
"Día Internacional de las Naciones Unidas en Apoyo de las Víctimas de la Tortura", String
"d(í|i)a internacional de las naciones unidas en apoyo de las v(í|i)ctimas de la tortura", Int -> Int -> TimeData
monthDay Int
6 Int
26 )
  , ( Text
"Día Internacional de la Beneficencia", String
"d(í|i)a internacional de la beneficencia", Int -> Int -> TimeData
monthDay Int
9 Int
5 )
  , ( Text
"Día Internacional de Conmemoración anual en memoria de las Víctimas del Holocausto", String
"d(í|i)a internacional de conmemoraci(ó|o)n anual en memoria de las v(í|i)ctimas del holocausto", Int -> Int -> TimeData
monthDay Int
1 Int
27 )
  , ( Text
"Día Internacional de la Democracia", String
"d(í|i)a (internacional )?de la democracia", Int -> Int -> TimeData
monthDay Int
9 Int
15 )
  , ( Text
"Día Internacional de las Personas con Discapacidad", String
"d(í|i)a internacional de las personas con discapacidad", Int -> Int -> TimeData
monthDay Int
12 Int
3 )
  , ( Text
"Día Internacional de la Familia", String
"d(í|i)a internacional de la(s)? familia(s)?", Int -> Int -> TimeData
monthDay Int
5 Int
15 )
  , ( Text
"Día Internacional de las Remesas Familiares", String
"d(í|i)a internacional de las remesas familiares", Int -> Int -> TimeData
monthDay Int
6 Int
16 )
  , ( Text
"Día Internacional de los Bosques", String
"d(í|i)a internacional de los bosques", Int -> Int -> TimeData
monthDay Int
3 Int
21 )
  , ( Text
"Día Internacional de la Amistad", String
"d(í|i)a internacional de la amistad", Int -> Int -> TimeData
monthDay Int
7 Int
30 )
  , ( Text
"Día Internacional de la Felicidad", String
"d(í|i)a (internacional|mundial) de la felicidad", Int -> Int -> TimeData
monthDay Int
3 Int
20 )
  , ( Text
"Día Internacional de los Vuelos Espaciales", String
"d(í|i)a internacional (de los|del) vuelos espaciales", Int -> Int -> TimeData
monthDay Int
4 Int
12 )
  , ( Text
"Día Internacional de los Niños Víctimas Inocentes de Agresión", String
"d(í|i)a internacional de los ni(ñ|n)os v(í|i)ctimas inocentes de agresi(ó|o)n", Int -> Int -> TimeData
monthDay Int
6 Int
4 )
  , ( Text
"Día Internacional de la no Violencia", String
"d(í|i)a internacional de la no violencia", Int -> Int -> TimeData
monthDay Int
10 Int
2 )
  , ( Text
"Día Internacional del Nowruz", String
"d(í|i)a internacional del nowruz", Int -> Int -> TimeData
monthDay Int
3 Int
21 )
  , ( Text
"Día Internacional de las Personas Mayores", String
"d(í|i)a internacional de las personas mayores", Int -> Int -> TimeData
monthDay Int
10 Int
1 )
  , ( Text
"Dia Internacional de la Paz", String
"d(í|i)a internacional de la paz", Int -> Int -> TimeData
monthDay Int
9 Int
21 )
  , ( Text
"Día Internacional de las Personas con Discapacidad", String
"d(í|i)a internacional de las personas con discapacidad", Int -> Int -> TimeData
monthDay Int
12 Int
3 )
  , ( Text
"Día Internacional de Recuerdo de las Víctimas de la Esclavitud y la Trata Transatlántica de Esclavos", String
"d(í|i)a internacional de recuerdo de las v(í|i)ctimas de la esclavitud y la trata transatl(á|a)ntica de esclavos", Int -> Int -> TimeData
monthDay Int
3 Int
25 )
  , ( Text
"Día Internacional de las Mujeres Rurales", String
"d(í|i)a internacional de las mujeres rurales", Int -> Int -> TimeData
monthDay Int
10 Int
15 )
  , ( Text
"Día Internacional de Solidaridad con los miembros del Personal Detenidos o Desaparecidos", String
"d(í|i)a internacional de solidaridad con los miembros del personal detenidos o desaparecidos", Int -> Int -> TimeData
monthDay Int
3 Int
25 )
  , ( Text
"Día Internacional de Solidaridad con el Pueblo Palestino", String
"d(í|i)a internacional de solidaridad con el pueblo palestino", Int -> Int -> TimeData
monthDay Int
11 Int
29 )
  , ( Text
"Día Internacional del Deporte para el Desarrollo y la Paz", String
"d(í|i)a internacional del deporte para el desarrollo y la paz", Int -> Int -> TimeData
monthDay Int
4 Int
6 )
  , ( Text
"Día Internacional del Personal de Paz de las Naciones Unidas", String
"d(í|i)a internacional del personal de paz de las naciones unidas", Int -> Int -> TimeData
monthDay Int
5 Int
29 )
  , ( Text
"Día Internacional de la Mujer y la Niña en la Ciencia", String
"d(í|i)a internacional de la mujer y la ni(ñ|n)a en la ciencia", Int -> Int -> TimeData
monthDay Int
2 Int
11 )
  , ( Text
"Día Internacional del Yoga", String
"d(í|i)a Internacional del Yoga", Int -> Int -> TimeData
monthDay Int
6 Int
21 )
  , ( Text
"Día Internacional de Tolerancia Cero con la Mutilación Genital Femenina", String
"d(í|i)a internacional de tolerancia cero con la mutilaci(ó|o)n genital femenina", Int -> Int -> TimeData
monthDay Int
2 Int
6 )
  , ( Text
"Día Internacional de la Niña", String
"d(í|i)a internacional de la ni(ñ|n)a", Int -> Int -> TimeData
monthDay Int
10 Int
11 )
  , ( Text
"Día Internacional de las Víctimas de Desapariciones Forzadas", String
"d(í|i)a internacional de las v(í|i)ctimas de desapariciones forzadas", Int -> Int -> TimeData
monthDay Int
8 Int
30 )
  , ( Text
"Día Internacional de los Pueblos Indígenas del Mundo", String
"d(í|i)a internacional de los pueblos ind(í|i)genas del mundo", Int -> Int -> TimeData
monthDay Int
8 Int
9 )
  , ( Text
"Día Internacional para poner fin a la Impunidad de los Crímenes contra Periodistas", String
"d(í|i)a internacional para poner fin a la impunidad de los cr(í|i)menes contra periodistas", Int -> Int -> TimeData
monthDay Int
11 Int
2 )
  , ( Text
"Día Internacional para la Erradicación de la Fístula Obstétrica", String
"d(í|i)a internacional para la erradicaci(ó|o)n de la f(í|i)stula obst(é|e)trica", Int -> Int -> TimeData
monthDay Int
5 Int
23 )
  , ( Text
"Día Internacional para la Reducción de los Desastres Naturales", String
"d(í|i)a internacional para la reducci(ó|o)n de los desastres (naturales)?", Int -> Int -> TimeData
monthDay Int
10 Int
13 )
  , ( Text
"Día Internacional de la Solidaridad Humana", String
"d(í|i)a internacional de la solidaridad humana", Int -> Int -> TimeData
monthDay Int
12 Int
20 )
  , ( Text
"Día Internacional del Jazz", String
"d(í|i)a internacional del jazz", Int -> Int -> TimeData
monthDay Int
4 Int
30 )
  , ( Text
"Día Internacional de la Alfabetización", String
"d(í|i)a internacional de la alfabetizaci(ó|o)n", Int -> Int -> TimeData
monthDay Int
9 Int
8 )
  , ( Text
"Día Internacional del Hombre", String
"d(í|i)a internacional de(l)? los hombre(s)?", Int -> Int -> TimeData
monthDay Int
11 Int
19 )
  , ( Text
"Día Internacional del Migrante", String
"d(í|i)a internacional del migrante", Int -> Int -> TimeData
monthDay Int
12 Int
18 )
  , ( Text
"Día Internacional de la Lengua Materna", String
"d(í|i)a (internacional|mundial) de la lengua materna", Int -> Int -> TimeData
monthDay Int
2 Int
21 )
  , ( Text
"Día Internacional de las Montañas", String
"d(í|i)a internacional de las monta(ñ|n)as", Int -> Int -> TimeData
monthDay Int
12 Int
11 )
  , ( Text
"Día Internacional de las Enfermeras", String
"d(í|i)a internacional de las enfermeras", Int -> Int -> TimeData
monthDay Int
5 Int
12 )
  , ( Text
"Día de la Conciencia Internacional sobre la Sobredosis", String
"ioad|d(í|i)a de (la )?conciencia internacional (de|sobre) la sobredosis", Int -> Int -> TimeData
monthDay Int
8 Int
31 )
  , ( Text
"Día Internacional del Voluntariado para el Desarrollo Económico y Social", String
"d(í|i)a internacional del voluntariado para el desarrollo econ(ó|o)mico y social", Int -> Int -> TimeData
monthDay Int
12 Int
5 )
  , ( Text
"Día Internacional de las Viudas", String
"d(í|i)a internacional de las viudas", Int -> Int -> TimeData
monthDay Int
6 Int
23 )
  , ( Text
"Día Internacional de la Mujer", String
"d(í|i)a internacional de la mujer", Int -> Int -> TimeData
monthDay Int
3 Int
8 )
  , ( Text
"Día Internacional de la Juventud", String
"d(í|i)a internacional de la juventud", Int -> Int -> TimeData
monthDay Int
8 Int
12 )
  , ( Text
"El Primero de Mayo", String
"(el )?primero de mayo", Int -> Int -> TimeData
monthDay Int
5 Int
1 )
  , ( Text
"Día Internacional de Nelson Mandela", String
"d(í|i)a (internacional )?de nelson mandela", Int -> Int -> TimeData
monthDay Int
7 Int
18 )
  , ( Text
"La Navidad Ortodoxa", String
"(la )?navidad ortodoxa", Int -> Int -> TimeData
monthDay Int
1 Int
7 )
  , ( Text
"Año Nuevo Ortodoxo", String
"(el )?(a(ñ|n)o nuevo viejo|a(ñ|n)o viejo ortodoxo|a(ñ|n)o nuevo ortodoxo|a(ñ|n)o nuevo juliano)", Int -> Int -> TimeData
monthDay Int
1 Int
14 )
  , ( Text
"Día Mundial de los Servicios Públicos", String
"d(í|i)a (mundial|nacional) de(l)? (los )?(servicios|servidor) p(ú|u)blico(s)?", Int -> Int -> TimeData
monthDay Int
6 Int
23 )
  , ( Text
"Día de San Jorge", String
"d(í|i)a de san jorge|fiesta de san jorge", Int -> Int -> TimeData
monthDay Int
4 Int
23 )
  , ( Text
"Día de San Patricio", String
"d(í|i)a de san patricio", Int -> Int -> TimeData
monthDay Int
3 Int
17 )
  , ( Text
"Dia de San Esteban", String
"d(í|i)a de san esteban", Int -> Int -> TimeData
monthDay Int
12 Int
26 )
  , ( Text
"Día Internacional del Tiempo del Recuerdo y la Reconciliación para Quienes Perdieron la Vida durante la Segunda Guerra Mundial", String
"d(í|i)a internacional del tiempo del recuerdo y la reconciliaci(ó|o)n para quienes perdieron la vida durante la segunda guerra mundial", Int -> Int -> TimeData
monthDay Int
5 Int
8 )
  , ( Text
"Día de las Naciones Unidas", String
"d(í|i)a de las naciones unidas", Int -> Int -> TimeData
monthDay Int
10 Int
24 )
  , ( Text
"Día Internacional de Información sobre el Peligro de las Minas y de Asistencia para las Actividades Relativas a las Minas", String
"d(í|i)a internacional de informaci(ó|o)n sobre el peligro de las minas y de asistencia para las actividades relativas a las minas", Int -> Int -> TimeData
monthDay Int
4 Int
4 )
  , ( Text
"Día Mundial de la Salud", String
"d(í|i)a mundial de la salud( de las naciones unidas)?", Int -> Int -> TimeData
monthDay Int
4 Int
7 )
  , ( Text
"Día Universal del Niño", String
"d(í|i)a universal del ni(ñ|n)o", Int -> Int -> TimeData
monthDay Int
11 Int
20 )
  , ( Text
"Día de San Valentín", String
"(el )?d(í|i)a de san valent(í|i)n", Int -> Int -> TimeData
monthDay Int
2 Int
14 )
  , ( Text
"Día Mundial de la lucha contra el SIDA", String
"d(í|i)a mundial de(l)? (la lucha contra el )?SIDA", Int -> Int -> TimeData
monthDay Int
12 Int
1 )
  , ( Text
"Día Mundial de Concienciación sobre el Autismo", String
"d(í|i)a mundial de(l)? (concienciaci(ó|o)n sobre el )?autismo", Int -> Int -> TimeData
monthDay Int
4 Int
2 )
  , ( Text
"Día Mundial de la Artritis Reumatoide", String
"d(í|i)a mundial de la artritis( reumatoide)?", Int -> Int -> TimeData
monthDay Int
5 Int
20 )
  , ( Text
"Día Mundial del Donante de Sangre", String
"d(í|i)a mundial del donante de sangre", Int -> Int -> TimeData
monthDay Int
6 Int
14 )
  , ( Text
"Día Internacional del Libro y del Derecho de Autor", String
"d(í|i)a internacional del libro y de(l)? (los )?derecho(s)? de autor", Int -> Int -> TimeData
monthDay Int
4 Int
23 )
  , ( Text
"Día Mundial del Braille", String
"d(í|i)a mundial del braille", Int -> Int -> TimeData
monthDay Int
1 Int
4 )
  , ( Text
"Día Mundial contra el Cáncer", String
"d(í|i)a mundial contra el c(á|a)ncer", Int -> Int -> TimeData
monthDay Int
2 Int
4 )
  , ( Text
"Día Mundial de las Ciudades", String
"d(í|i)a mundial de las ciudades", Int -> Int -> TimeData
monthDay Int
10 Int
31 )
  , ( Text
"Día Mundial de la PC", String
"d(í|i)a mundial (de la|del) (PC|Paralisia Cerebral)", Int -> Int -> TimeData
monthDay Int
10 Int
6 )
  , ( Text
"Día Mundial contra el Trabajo Infantil", String
"d(í|i)a mundial contra el trabajo infantil", Int -> Int -> TimeData
monthDay Int
6 Int
12 )
  , ( Text
"Día Mundial contra la Trata de Personas", String
"d(í|i)a mundial contra la trata de personas", Int -> Int -> TimeData
monthDay Int
7 Int
30 )
  , ( Text
"Día Mundial del Patrimonio Audiovisual", String
"d(í|i)a mundial (del|sobre el) patrimonio audiovisual", Int -> Int -> TimeData
monthDay Int
10 Int
27 )
  , ( Text
"Día Mundial de la Diversidad Cultural para el Diálogo y el Desarrollo", String
"d(í|i)a mundial de la diversidad cultural para el diálogo y el desarrollo", Int -> Int -> TimeData
monthDay Int
5 Int
21 )
  , ( Text
"Día Mundial de la Seguridad y la Salud en el Trabajo", String
"d(í|i)a mundial de la seguridad y la salud en el trabajo", Int -> Int -> TimeData
monthDay Int
4 Int
28 )
  , ( Text
"Día Mundial por la Abolición de la Esclavitud", String
"d(í|i)a (internacional|mundial) (para|por) la abolici(ó|o)n de la esclavitud", Int -> Int -> TimeData
monthDay Int
12 Int
2 )
  , ( Text
"Día Mundial de la Justicia Social", String
"d(í|i)a mundial de la justicia social", Int -> Int -> TimeData
monthDay Int
2 Int
20 )
  , ( Text
"Día Mundial del Enfermo", String
"d(í|i)a mundial (del|de los) enfermos", Int -> Int -> TimeData
monthDay Int
2 Int
11 )
  , ( Text
"Día Mundial de Lucha contra la Desertificación y la Sequía", String
"d(í|i)a mundial (de lucha contra|para combatir) la desertificaci(ó|o)n y la sequ(í|i)a", Int -> Int -> TimeData
monthDay Int
6 Int
17 )
  , ( Text
"Día Mundial de Información sobre el Desarrollo", String
"d(í|i)a mundial de informaci(ó|o)n sobre el desarrollo", Int -> Int -> TimeData
monthDay Int
10 Int
24 )
  , ( Text
"Día Mundial de la Diabetes", String
"d(í|i)a mundial de la diabetes", Int -> Int -> TimeData
monthDay Int
11 Int
14 )
  , ( Text
"Día Mundial del Síndrome de Down", String
"d(í|i)a mundial del s(í|i)ndrome de down", Int -> Int -> TimeData
monthDay Int
3 Int
21 )
  , ( Text
"Día Mundial de Toma de Conciencia del Abuso y Maltrato en la Vejez", String
"d(í|i)a mundial de toma de conciencia del abuso y maltrato en la vejez", Int -> Int -> TimeData
monthDay Int
6 Int
15 )
  , ( Text
"Día Mundial del Medio Ambiente", String
"d(í|i)a mundial del medio ambiente", Int -> Int -> TimeData
monthDay Int
6 Int
5 )
  , ( Text
"Día Mundial de la Alimentación", String
"d(í|i)a mundial de la alimentaci(ó|o)n", Int -> Int -> TimeData
monthDay Int
10 Int
16 )
  , ( Text
"Día para la Conmemoración y Dignificación de las Víctimas del Crimen de Genocidio y para su Prevención", String
"d(í|i)a para la conmemoraci(ó|o)n y dignificaci(ó|o)n de las v(í|i)ctimas del crimen de genocidio y para su prevenci(ó|o)n", Int -> Int -> TimeData
monthDay Int
12 Int
9 )
  , ( Text
"Día Mundial del Corazón", String
"d(í|i)a mundial del coraz(ó|o)n", Int -> Int -> TimeData
monthDay Int
9 Int
29 )
  , ( Text
"Día Mundial de la Hepatitis", String
"d(í|i)a mundial (contra|de) la hepatitis", Int -> Int -> TimeData
monthDay Int
7 Int
28 )
  , ( Text
"Día Mundial de la Asistencia Humanitaria", String
"d(í|i)a mundial de la asistencia humanitaria", Int -> Int -> TimeData
monthDay Int
8 Int
19 )
  , ( Text
"Día Internacional de la Sociedad de la Información", String
"d(í|i)a (internacional|mundial) de (las telecomunicaciones y )?la sociedad de la informaci(ó|o)n", Int -> Int -> TimeData
monthDay Int
5 Int
17 )
  , ( Text
"Día Mundial de la Propiedad Intelectual", String
"d(í|i)a mundial de la propiedad intelectual", Int -> Int -> TimeData
monthDay Int
4 Int
26 )
  , ( Text
"Día Mundial de la Malaria", String
"d(í|i)a mundial (de la|del) (malaria|paludismo)", Int -> Int -> TimeData
monthDay Int
4 Int
25 )
  , ( Text
"Día Mundial de la Salud Mental", String
"d(í|i)a mundial de la salud mental", Int -> Int -> TimeData
monthDay Int
10 Int
10 )
  , ( Text
"Día Mundial de la Meteorología", String
"d(í|i)a (mundial de (la )?meteorolog(í|i)a|meteorol(ó|o)gico mundial)", Int -> Int -> TimeData
monthDay Int
3 Int
23 )
  , ( Text
"Día Mundial sin Tabaco", String
"d(í|i)a mundial sin tabaco", Int -> Int -> TimeData
monthDay Int
5 Int
31 )
  , ( Text
"Dia Mundial de los Océanos", String
"d(í|i)a mundial de los oc(é|e)anos", Int -> Int -> TimeData
monthDay Int
6 Int
8 )
  , ( Text
"Día Mundial del Cáncer de Ovario", String
"d(í|i)a mundial del c(á|a)ncer de ovario", Int -> Int -> TimeData
monthDay Int
5 Int
8 )
  , ( Text
"Día Mundial contra la Neumonía", String
"d(í|i)a mundial (contra|de) la neumon(í|i)a", Int -> Int -> TimeData
monthDay Int
11 Int
12 )
  , ( Text
"Dia Mundial de la Poesia", String
"d(í|i)a mundial de la poesia", Int -> Int -> TimeData
monthDay Int
3 Int
21 )
  , ( Text
"Día Mundial de la Población", String
"d(í|i)a mundial de la poblaci(ó|o)n", Int -> Int -> TimeData
monthDay Int
7 Int
11 )
  , ( Text
"Día Mundial del Correo", String
"d(í|i)a mundial del correo", Int -> Int -> TimeData
monthDay Int
10 Int
9 )
  , ( Text
"Día de la Prematuridad Mundial", String
"d(í|i)a (de la prematuridad mundial|mundial del (ni(ñ|n)o )?prematuro)", Int -> Int -> TimeData
monthDay Int
11 Int
17 )
  , ( Text
"Día Mundial de la Libertad de Prensa", String
"d(í|i)a mundial de la libertad de prensa", Int -> Int -> TimeData
monthDay Int
5 Int
3 )
  , ( Text
"Día Mundial contra la Rabia", String
"d(í|i)a mundial (contra|de) la rabia", Int -> Int -> TimeData
monthDay Int
9 Int
28 )
  , ( Text
"Día Mundial de la Radio", String
"d(í|i)a mundial de la radio", Int -> Int -> TimeData
monthDay Int
2 Int
13 )
  , ( Text
"Día Mundial de los Refugiados", String
"d(í|i)a mundial (del|de los) refugiado(s)?", Int -> Int -> TimeData
monthDay Int
6 Int
20 )
  , ( Text
"Día Mundial de la Ciencia para la Paz y el Desarrollo", String
"d(í|i)a mundial de la ciencia para la paz y el desarrollo", Int -> Int -> TimeData
monthDay Int
11 Int
10 )
  , ( Text
"Día Mundial de la Salud Sexual", String
"dmss|d(í|i)a mundial de la salud sexual", Int -> Int -> TimeData
monthDay Int
9 Int
4 )
  , ( Text
"Día Mundial del Suelo", String
"d(í|i)a mundial del suelo", Int -> Int -> TimeData
monthDay Int
12 Int
5 )
  , ( Text
"Día Mundial del Accidente Cerebrovascular", String
"d(í|i)a mundial del (accidente cerebrovascular|acv)", Int -> Int -> TimeData
monthDay Int
10 Int
29 )
  , ( Text
"Día Mundial para la Prevención del Suicidio", String
"d(í|i)a mundial para la prevenci(ó|o)n del suicidio", Int -> Int -> TimeData
monthDay Int
9 Int
10 )
  , ( Text
"Día Mundial de los Docentes", String
"d(í|i)a mundial (de los docentes|del maestro)", Int -> Int -> TimeData
monthDay Int
10 Int
5 )
  , ( Text
"Día Mundial de la Televisión", String
"d(í|i)a mundial de la televisi(ó|o)n", Int -> Int -> TimeData
monthDay Int
11 Int
21 )
  , ( Text
"Día Mundial del Baño", String
"d(í|i)a mundial del (ba(ñ|n)o|retrete)", Int -> Int -> TimeData
monthDay Int
11 Int
19 )
  , ( Text
"Día Mundial del Turismo", String
"dmt|d(í|i)a mundial del turismo", Int -> Int -> TimeData
monthDay Int
9 Int
27 )
  , ( Text
"Día Mundial de la Tuberculosis", String
"d(í|i)a mundial de (lucha contra)?la (tuberculosis|tb)", Int -> Int -> TimeData
monthDay Int
3 Int
24 )
  , ( Text
"Día Mundial del Atun", String
"d(í|i)a mundial del atun", Int -> Int -> TimeData
monthDay Int
5 Int
2 )
  , ( Text
"Día Mundial del Veganismo", String
"d(í|i)a mundial del veganismo", Int -> Int -> TimeData
monthDay Int
11 Int
1 )
  , ( Text
"Día Mundial del Vegetarianismo", String
"d(í|i)a mundial del vegetarianismo", Int -> Int -> TimeData
monthDay Int
10 Int
1 )
  , ( Text
"Día Mundial del Agua", String
"d(í|i)a mundial del agua", Int -> Int -> TimeData
monthDay Int
3 Int
22 )
  , ( Text
"Día Mundial de los Humedales", String
"d(í|i)a mundial de los humedales", Int -> Int -> TimeData
monthDay Int
2 Int
2 )
  , ( Text
"Día Mundial de la Vida Silvestre", String
"d(í|i)a mundial de la vida silvestre", Int -> Int -> TimeData
monthDay Int
3 Int
3 )
  , ( Text
"Día Mundial de las Habilidades de la Juventud", String
"d(í|i)a mundial de las habilidades de la juventud", Int -> Int -> TimeData
monthDay Int
7 Int
15 )
  , ( Text
"Día de la Cero Discriminación", String
"d(í|i)a de la cero discriminaci(ó|o)n", Int -> Int -> TimeData
monthDay Int
3 Int
1 )

  -- Fixed day/week/month, year over year
  , ( Text
"Día de la Commonwealth", String
"d(í|i)a de la commonwealth", Int -> Int -> Int -> TimeData
nthDOWOfMonth Int
2 Int
1 Int
3 )
  , ( Text
"Día Mundial en Recuerdo de las Víctimas de Accidentes de Tráfico"
    , String
"d(í|i)a (mundial )?en recuerdo de las v(í|i)ctimas (de accidentes )?de tr(á|a)fico"
    , Int -> Int -> Int -> TimeData
nthDOWOfMonth Int
3 Int
7 Int
11 )
  , ( Text
"Día Internacional de las Cooperativas"
    , String
"d(í|i)a internacional de las cooperativas", Int -> Int -> Int -> TimeData
nthDOWOfMonth Int
1 Int
6 Int
7 )
  , ( Text
"Día de Martin Luther King"
    , String
"(MLK|d(í|i)a de Martin Luther King,?)( Jr\\.?| J(ú|u)nior)?|d(í|i)a de los derechos humanos en Idaho"
    , Int -> Int -> Int -> TimeData
nthDOWOfMonth Int
3 Int
1 Int
1
    )

  -- The day after Thanksgiving (not always the fourth Friday of November)
  , ( Text
"Viernes negro", String
"viernes negro"
    , Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
1 (TimeData -> TimeData) -> TimeData -> TimeData
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Int -> TimeData
nthDOWOfMonth Int
4 Int
4 Int
11
    )
  , ( Text
"Día Mundial del Hábitat", String
"d(í|i)a mundial del h(á|a)bitat", Int -> Int -> Int -> TimeData
nthDOWOfMonth Int
1 Int
1 Int
10 )
  , ( Text
"Día Mundial del Riñón", String
"d(í|i)a mundial del ri(ñ|n)(ó|o)n", Int -> Int -> Int -> TimeData
nthDOWOfMonth Int
2 Int
4 Int
3 )
  , ( Text
"Día Mundial de la Lepra", String
"d(í|i)a mundial (contra|de) la lepra"
    , TimeData -> TimeData -> TimeData
predLastOf (Int -> TimeData
dayOfWeek Int
7) (Int -> TimeData
month Int
1) )
  , ( Text
"Día Marítimo Mundial", String
"d(í|i)a mar(í|i)timo mundial"
    , TimeData -> TimeData -> TimeData
predLastOf (Int -> TimeData
dayOfWeek Int
4) (Int -> TimeData
month Int
9) )
  , ( Text
"Día Mundial de las Aves Migratorias", String
"d(í|i)a mundial de las aves migratorias"
    , Int -> Int -> Int -> TimeData
nthDOWOfMonth Int
2 Int
6 Int
5 )
  , ( Text
"Día mundial de la filosofía", String
"d(í|i)a mundial de la filosof(í|i)a", Int -> Int -> Int -> TimeData
nthDOWOfMonth Int
3 Int
4 Int
11 )
  , ( Text
"Día mundial de la religion", String
"d(í|i)a mundial de la(s)? religion(es)?", Int -> Int -> Int -> TimeData
nthDOWOfMonth Int
3 Int
7 Int
1 )
  , ( Text
"Día mundial de la vista", String
"d(í|i)a mundial de la (vista|visi(ó|o)n)", Int -> Int -> Int -> TimeData
nthDOWOfMonth Int
2 Int
4 Int
10 )

  -- Other
  , ( Text
"Día del jefe", String
"(el )?d(í|i)a (nacional )?del jefe"
    , Int -> TimeData -> TimeData -> TimeData
predNthClosest Int
0 TimeData
weekday (Int -> Int -> TimeData
monthDay Int
10 Int
16) )
  ]

ruleElDayofmonthNonOrdinalWithDia :: Rule
ruleElDayofmonthNonOrdinalWithDia :: Rule
ruleElDayofmonthNonOrdinalWithDia = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"dia <day-of-month> (non ordinal)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"día"
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
1 Int
31
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token
token:[Token]
_) -> do
        Int
v <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> TimeData
dayOfMonth Int
v
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleNextWeekAlt :: Rule
ruleNextWeekAlt :: Rule
ruleNextWeekAlt = Rule :: Text -> Pattern -> Production -> Rule
Rule
  {
    name :: Text
name = Text
"next week (alt)"
  , pattern :: Pattern
pattern =
    [
      String -> PatternItem
regex String
"pr(ó|o)xim(o|a)s?|siguientes?"
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Grain -> Predicate
isGrain Grain
TG.Week
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> Int -> TimeData
cycleNth Grain
TG.Week Int
1
  }

ruleYearByAddingThreeNumbers :: Rule
ruleYearByAddingThreeNumbers :: Rule
ruleYearByAddingThreeNumbers = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name    = Text
"year (value by adding three composing numbers together)"
  , pattern :: Pattern
pattern =
    [
      String -> PatternItem
regex String
"mil"
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
100 Int
1000
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
1 Int
100
    ]
  , prod :: Production
prod    = \case
      (
        Token
_:
        Token
t1:
        Token
t2:
        [Token]
_) -> do
          Int
v1 <- Token -> Maybe Int
getIntValue Token
t1
          Int
v2 <- Token -> Maybe Int
getIntValue Token
t2
          TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> TimeData
year (Int -> TimeData) -> Int -> TimeData
forall a b. (a -> b) -> a -> b
$ Int
1000 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
v1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
v2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

rules :: [Rule]
rules :: [Rule]
rules =
  [ Rule
ruleALasHourmintimeofday
  , Rule
ruleALasTimeofday
  , Rule
ruleAfternoon
  , Rule
ruleAnoNuevo
  , Rule
ruleCeTime
  , Rule
ruleDatetimeDatetimeInterval
  , Rule
ruleDayOfMonthSt
  , Rule
ruleDayofmonthDeNamedmonth
  , Rule
ruleDayofweekDayofmonth
  , Rule
ruleDdddMonthinterval
  , Rule
ruleDdmm
  , Rule
ruleDdmmyyyy
  , Rule
ruleDeDatetimeDatetimeInterval
  , Rule
ruleDelMedioda
  , Rule
ruleDelYear
  , Rule
ruleDentroDeDuration
  , Rule
ruleDimTimeDeLaManana
  , Rule
ruleDimTimeDeLaTarde
  , Rule
ruleDimTimeDeLaTarde2
  , Rule
ruleElCycleAntesTime
  , Rule
ruleElCycleProximoqueViene
  , Rule
ruleElCycleProximoqueVieneTime
  , Rule
ruleElDayofmonthDeNamedmonth
  , Rule
ruleElDayofmonthNonOrdinal
  , Rule
ruleElProximoCycle
  , Rule
ruleElTime
  , Rule
ruleEnDuration
  , Rule
ruleEntreDatetimeEtDatetimeInterval
  , Rule
ruleEntreDdEtDdMonthinterval
  , Rule
ruleEsteenUnCycle
  , Rule
ruleEvening
  , Rule
ruleHaceDuration
  , Rule
ruleHhhmmTimeofday
  , Rule
ruleHourofdayAndRelativeMinutes
  , Rule
ruleHourofdayIntegerAsRelativeMinutes
  , Rule
ruleHourofdayMinusIntegerAsRelativeMinutes
  , Rule
ruleInThePartofday
  , Rule
ruleIntegerInThePartofday
  , Rule
ruleIntersect
  , Rule
ruleIntersectByDe
  , Rule
ruleLaCyclePasado
  , Rule
ruleLaPasadoCycle
  , Rule
ruleMidnight
  , Rule
ruleMorning
  , Rule
ruleNCycleProximoqueViene
  , Rule
ruleNPasadosCycle
  , Rule
ruleNProximasCycle
  , Rule
ruleNamedmonthDayofmonth
  , Rule
ruleNamedmonthnameddayNext
  , Rule
ruleNamedmonthnameddayPast
  , Rule
ruleNavidad
  , Rule
ruleNochevieja
  , Rule
ruleNoon
  , Rule
ruleNow
  , Rule
ruleNthTimeDeTime
  , Rule
ruleNthTimeDeTime2
  , Rule
ruleOrdinalQuarter
  , Rule
ruleOrdinalQuarterYear
  , Rule
rulePasadosNCycle
  , Rule
ruleProximasNCycle
  , Rule
ruleRightNow
  , Rule
ruleTheDayAfterTomorrow
  , Rule
ruleTheDayBeforeYesterday
  , Rule
ruleThisDayofweek
  , Rule
ruleThisPartofday
  , Rule
ruleTimeofdayAmpm
  , Rule
ruleTimeofdayHoras
  , Rule
ruleTimeofdayLatent
  , Rule
ruleTimeofdayPartofday
  , Rule
ruleTomorrow
  , Rule
ruleTwoTimeTokensSeparatedBy
  , Rule
ruleUltimoDayofweekDeTime
  , Rule
ruleWeekend
  , Rule
ruleYear
  , Rule
ruleYearLatent
  , Rule
ruleYesterday
  , Rule
ruleYyyymmdd
  , Rule
ruleHourofdayAndThreeQuarter
  , Rule
ruleHourofdayAndHalf
  , Rule
ruleHourofdayAndQuarter
  , Rule
ruleHourofdayAndRelativeMinutes2
  , Rule
ruleHourofdayThreeQuarter
  , Rule
ruleHourofdayHalf
  , Rule
ruleHourofdayQuarter
  , Rule
ruleHourofdayIntegerAsRelativeMinutes2
  , Rule
ruleHourofdayMinusThreeQuarter
  , Rule
ruleHourofdayMinusHalf
  , Rule
ruleHourofdayMinusQuarter
  , Rule
ruleHourofdayMinusIntegerAsRelativeMinutes2
  , Rule
ruleTimezone
  , Rule
ruleElDayofmonthNonOrdinalWithDia
  , Rule
ruleNextWeek
  , Rule
ruleNextWeekAlt
  , Rule
ruleYearByAddingThreeNumbers
  ]
  [Rule] -> [Rule] -> [Rule]
forall a. [a] -> [a] -> [a]
++ [Rule]
ruleDaysOfWeek
  [Rule] -> [Rule] -> [Rule]
forall a. [a] -> [a] -> [a]
++ [Rule]
ruleMonths
  [Rule] -> [Rule] -> [Rule]
forall a. [a] -> [a] -> [a]
++ [Rule]
ruleSeasons
  [Rule] -> [Rule] -> [Rule]
forall a. [a] -> [a] -> [a]
++ [Rule]
rulePeriodicHolidays