-- 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 #-}

module Duckling.Time.EN.AU.Rules
  ( rules
  ) where

import Data.Maybe
import Prelude

import Duckling.Dimensions.Types
import Duckling.Numeral.Helpers (parseInt)
import Duckling.Regex.Types
import Duckling.Time.Computed (easterSunday)
import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData (..))
import Duckling.Types
import qualified Duckling.Time.Types as TTime
import qualified Duckling.TimeGrain.Types as TG

ruleDDMM :: Rule
ruleDDMM = Rule
  { name = "dd/mm"
  , pattern =
    [ regex "(3[01]|[12]\\d|0?[1-9])\\s?[/-]\\s?(1[0-2]|0?[1-9])"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (dd:mm:_)):_) -> do
        d <- parseInt dd
        m <- parseInt mm
        tt $ monthDay m d
      _ -> Nothing
  }

ruleDDMMYYYY :: Rule
ruleDDMMYYYY = Rule
  { name = "dd/mm/yyyy"
  , pattern =
    [ regex "(3[01]|[12]\\d|0?[1-9])[-/\\s](1[0-2]|0?[1-9])[-/\\s](\\d{2,4})"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (dd:mm:yy:_)):_) -> do
        y <- parseInt yy
        d <- parseInt dd
        m <- parseInt mm
        tt $ yearMonthDay y m d
      _ -> Nothing
  }

-- Clashes with HHMMSS, hence only 4-digit years
ruleDDMMYYYYDot :: Rule
ruleDDMMYYYYDot = Rule
  { name = "dd.mm.yyyy"
  , pattern =
    [ regex "(3[01]|[12]\\d|0?[1-9])\\.(1[0-2]|0?[1-9])\\.(\\d{4})"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (dd:mm:yy:_)):_) -> do
        y <- parseInt yy
        d <- parseInt dd
        m <- parseInt mm
        tt $ yearMonthDay y m d
      _ -> Nothing
  }

rulePeriodicHolidays :: [Rule]
rulePeriodicHolidays = mkRuleHolidays
  -- Fixed dates, year over year
  [ ( "ANZAC Day", "anzac day", monthDay 4 25 )
  , ( "Australia Day", "(ana|anniversary|australia|foundation) day"
    , monthDay 1 26 )
  , ( "Harmony Day", "harmony day", monthDay 3 21 )
  , ( "National Sorry Day", "national sorry day", monthDay 5 26 )
  , ( "Queensland Day", "queensland day", monthDay 6 6 )
  , ( "Remembrance Day", "remembrance day", monthDay 11 11 )
  , ( "Take our Daughters and Sons to Work Day"
    , "take our daughters and sons to work day", monthDay 1 5 )

  -- Fixed day/week/month, year over year
  , ( "Adelaide Cup", "adelaide cup", nthDOWOfMonth 2 1 3 )
  , ( "Administrative Professionals' Day"
    , "(administrative professional|secretarie|admin)('?s'?)? day"
    , nthDOWOfMonth 1 5 5 )
  , ( "Canberra Day", "canberra day", nthDOWOfMonth 2 1 3 )
  , ( "Eight Hours Day", "eight hours day", nthDOWOfMonth 2 1 3 )
  , ( "Father's Day", "father'?s?'? day", nthDOWOfMonth 1 7 9 )
  , ( "Labour Day", "labour day", nthDOWOfMonth 1 1 10 )
  , ( "Melbourne Cup Day", "melbourne cup day", nthDOWOfMonth 1 2 11 )
  , ( "Mother's Day", "mother'?s?'? day", nthDOWOfMonth 2 7 5 )
  , ( "National Close the Gap Day", "national close the gap day"
    , nthDOWOfMonth 3 4 3 )
  , ( "National Tree Day", "(arbor|national tree) day"
    , predLastOf (dayOfWeek 7) (month 6) )
  , ( "National Schools Tree Day", "national schools tree day"
    , predLastOf (dayOfWeek 5) (month 6) )
  , ( "New South Wales Bank Holiday", "new south wales bank holiday"
    , nthDOWOfMonth 1 1 8 )
  , ( "Picnic Day", "(northern territory )?picnic day", nthDOWOfMonth 1 1 8 )
  , ( "Recreation Day", "recreation day", nthDOWOfMonth 1 1 10 )
  , ( "Thanksgiving Day", "thanks?giving( day)?", nthDOWOfMonth 4 4 11 )
  , ( "Western Australia Day", "western australia day", nthDOWOfMonth 1 1 6 )

  -- Other
  , ( "Reconciliation Day", "reconciliation\\s+day"
    , predNthAfter 0 (dayOfWeek 1) (monthDay 5 26) )
  ]

rulePeriodicHolidays' :: [Rule]
rulePeriodicHolidays' = mkRuleHolidays'
  -- Fixed day/week/month, year over year
  -- Week from Sunday of July until following Sunday that has the second Friday
  [ ( "NAIDOC Week"
    , "(naidoc|national aboriginal and islander day observance committee) week"
    , let fri = nthDOWOfMonth 2 5 7
          start = cycleNthAfter False TG.Day (- 5) fri
          end = cycleNthAfter False TG.Day 2 fri
      in interval TTime.Open start end )
  -- 3 days ending on the second Monday of February
  , ( "Royal Hobart Regatta", "royal hobart regatta"
    , let end = nthDOWOfMonth 2 1 2
      in interval TTime.Open (cycleNthAfter False TG.Day (- 2) end) end )

  -- Other
  -- Wednesday of the Royal Queensland Show
  -- Starts on the first Friday of August if it's not before August 5th
  -- Otherwise on the second Friday of August
  , ( "Royal Queensland Show Day"
    , "(royal (national agricultural|queensland)|rna) show day|ekka day"
    , let tentative = nthDOWOfMonth 1 5 8
          alternative = nthDOWOfMonth 2 5 8
      in do
        forbidden <- interval TTime.Open (monthDay 8 1) (monthDay 8 4)
        start <- intersectWithReplacement forbidden tentative alternative
        return $ cycleNthAfter False TG.Day 5 start )
  -- Starts on the first Friday of August if it's not before August 5th
  -- Otherwise on the second Friday of August
  , ( "Royal Queensland Show"
    , "ekka|(royal (national agricultural|queensland)|rna) show"
    , let tentative = nthDOWOfMonth 1 5 8
          alternative = nthDOWOfMonth 2 5 8
      in do
        forbidden <- interval TTime.Open (monthDay 8 1) (monthDay 8 4)
        start <- intersectWithReplacement forbidden tentative alternative
        interval TTime.Open start $ cycleNthAfter False TG.Day 9 start )
  ]

ruleComputedHolidays :: [Rule]
ruleComputedHolidays = mkRuleHolidays
  [ ( "Easter Tuesday", "easter\\s+tue(sday)?"
    , cycleNthAfter False TG.Day 2 easterSunday )
  ]

rules :: [Rule]
rules =
  [ ruleDDMM
  , ruleDDMMYYYY
  , ruleDDMMYYYYDot
  ]
  ++ ruleComputedHolidays
  ++ rulePeriodicHolidays
  ++ rulePeriodicHolidays'


-- 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 OverloadedStrings #-}

module Duckling.Time.EN.BZ.Corpus
  ( allExamples
  ) where

import Data.String
import Prelude

import Duckling.Testing.Types hiding (examples)
import Duckling.Time.Corpus
import Duckling.Time.Types hiding (Month)
import Duckling.TimeGrain.Types hiding (add)

allExamples :: [Example]
allExamples = concat
  [ examples (datetime (2013, 2, 15, 0, 0, 0) Day)
             [ "15/2"
             , "on 15/2"
             , "15 / 2"
             , "15-2"
             , "15 - 2"
             ]
  , examples (datetime (1974, 10, 31, 0, 0, 0) Day)
             [ "31/10/1974"
             , "31/10/74"
             , "31-10-74"
             , "31.10.1974"
             , "31 10 1974"
             ]
  , examples (datetime (2013, 4, 25, 16, 0, 0) Minute)
             [ "25/4 at 4:00pm"
             ]
  , examples (datetime (2013, 10, 10, 0, 0, 0) Day)
             [ "10/10"
             , "10/10/2013"
             ]
  , examples (datetimeHoliday (2013, 11, 28, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving day"
             , "thanksgiving"
             , "thanksgiving 2013"
             , "this thanksgiving"
             , "next thanksgiving day"
             ]
  , examples (datetimeHoliday (2014, 11, 27, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving of next year"
             , "thanksgiving 2014"
             ]
  , examples (datetimeHoliday (2012, 11, 22, 0, 0, 0) Day "Thanksgiving Day")
             [ "last thanksgiving"
             , "thanksgiving day 2012"
             ]
  , examples (datetimeHoliday (2016, 11, 24, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving 2016"
             ]
  , examples (datetimeHoliday (2017, 11, 23, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving 2017"
             ]
  , examples (datetimeHoliday (2013, 11, 19, 0, 0, 0) Day "Garifuna Settlement Day")
             [ "garifuna settlement day"
             ]
  , examples (datetimeHoliday (2013, 6, 16, 0, 0, 0) Day "Father's Day")
             [ "Father's Day"
             ]
  , examples (datetimeHoliday (2012, 6, 17, 0, 0, 0) Day "Father's Day")
             [ "last fathers day"
             ]
  , examples (datetimeHoliday (1996, 6, 16, 0, 0, 0) Day "Father's Day")
             [ "fathers day 1996"
             ]
  , examples (datetimeHoliday (2013, 5, 12, 0, 0, 0) Day "Mother's Day")
             [ "Mother's Day"
             , "next mothers day"
             ]
  , examples (datetimeHoliday (2012, 5, 13, 0, 0, 0) Day "Mother's Day")
             [ "last mothers day"
             ]
  , examples (datetimeHoliday (2014, 5, 11, 0, 0, 0) Day "Mother's Day")
             [ "mothers day 2014"
             ]
  , examples (datetimeHoliday (2013, 5, 1, 0, 0, 0) Day "Labour Day")
             [ "labour day"
             ]
  , examples (datetimeHoliday (2012, 5, 1, 0, 0, 0) Day "Labour Day")
             [ "labour day of last year"
             , "Labour Day 2012"
             ]
  ]


-- 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 #-}

module Duckling.Time.EN.BZ.Rules
  ( rules
  ) where

import Data.Maybe
import Prelude

import Duckling.Dimensions.Types
import Duckling.Numeral.Helpers (parseInt)
import Duckling.Regex.Types
import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData (..))
import Duckling.Types

ruleDDMM :: Rule
ruleDDMM = Rule
  { name = "dd/mm"
  , pattern =
    [ regex "(3[01]|[12]\\d|0?[1-9])\\s?[/-]\\s?(1[0-2]|0?[1-9])"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (dd:mm:_)):_) -> do
        d <- parseInt dd
        m <- parseInt mm
        tt $ monthDay m d
      _ -> Nothing
  }

ruleDDMMYYYY :: Rule
ruleDDMMYYYY = Rule
  { name = "dd/mm/yyyy"
  , pattern =
    [ regex "(3[01]|[12]\\d|0?[1-9])[-/\\s](1[0-2]|0?[1-9])[-/\\s](\\d{2,4})"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (dd:mm:yy:_)):_) -> do
        y <- parseInt yy
        d <- parseInt dd
        m <- parseInt mm
        tt $ yearMonthDay y m d
      _ -> Nothing
  }

-- Clashes with HHMMSS, hence only 4-digit years
ruleDDMMYYYYDot :: Rule
ruleDDMMYYYYDot = Rule
  { name = "dd.mm.yyyy"
  , pattern =
    [ regex "(3[01]|[12]\\d|0?[1-9])\\.(1[0-2]|0?[1-9])\\.(\\d{4})"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (dd:mm:yy:_)):_) -> do
        y <- parseInt yy
        d <- parseInt dd
        m <- parseInt mm
        tt $ yearMonthDay y m d
      _ -> Nothing
  }

rulePeriodicHolidays :: [Rule]
rulePeriodicHolidays = mkRuleHolidays
  -- Fixed dates, year over year
  [ ( "Garifuna Settlement Day", "garifuna settlement day", monthDay 11 19 )
  , ( "Labour Day", "labour day", monthDay 5 1 )
  , ( "National Heroes and Benefactors Day"
    , "national heroes and benefactors day", monthDay 3 9 )
  , ( "Pan American Day", "pan american day", monthDay 10 12 )
  , ( "St. George's Caye Day", "st\\.? george'?s caye day", monthDay 9 10 )

  -- Fixed day/week/month, year over year
  , ( "Father's Day", "father'?s?'? day", nthDOWOfMonth 3 7 6 )
  , ( "Mother's Day", "mother'?s?'? day", nthDOWOfMonth 2 7 5 )
  , ( "Thanksgiving Day", "thanks?giving( day)?", nthDOWOfMonth 4 4 11 )
  ]

rules :: [Rule]
rules =
  [ ruleDDMM
  , ruleDDMMYYYY
  , ruleDDMMYYYYDot
  ]
  ++ rulePeriodicHolidays


-- 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 OverloadedStrings #-}

module Duckling.Time.EN.CA.Corpus
  ( allExamples
  ) where

import Data.String
import Prelude

import Duckling.Testing.Types hiding (examples)
import Duckling.Time.Corpus
import Duckling.Time.Types hiding (Month)
import Duckling.TimeGrain.Types hiding (add)

allExamples :: [Example]
allExamples = concat
  [ examples (datetime (2013, 2, 15, 0, 0, 0) Day)
             [ "2/15"
             , "on 2/15"
             , "2 / 15"
             , "2-15"
             , "2 - 15"
             ]
  , examples (datetime (1974, 10, 31, 0, 0, 0) Day)
             [ "10/31/1974"
             , "10/31/74"
             , "10-31-74"
             , "10.31.1974"
             , "10 31 1974"
             ]
  , examples (datetime (2013, 4, 25, 16, 0, 0) Minute)
             [ "4/25 at 4:00pm"
             ]
  , examples (datetimeHoliday (2013, 10, 14, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving day"
             , "thanksgiving"
             , "thanksgiving 2013"
             , "this thanksgiving"
             , "next thanksgiving day"
             ]
  , examples (datetimeHoliday (2014, 10, 13, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving of next year"
             , "thanksgiving 2014"
             ]
  , examples (datetimeHoliday (2012, 10, 8, 0, 0, 0) Day "Thanksgiving Day")
             [ "last thanksgiving"
             , "thanksgiving day 2012"
             ]
  , examples (datetimeHoliday (2016, 10, 10, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving 2016"
             ]
  , examples (datetimeHoliday (2017, 10, 9, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving 2017"
             ]
  , examples (datetimeHoliday (2013, 7, 1, 0, 0, 0) Day "Memorial Day")
             [ "canada day"
             , "memorial day"
             , "dominion day"
             , "Next Memorial Day"
             ]
  , examples (datetimeHoliday (2013, 4, 9, 0, 0, 0) Day "Vimy Ridge Day")
             [ "vimy ridge day"
             ]
  , examples (datetimeHoliday (2013, 7, 12, 0, 0, 0) Day "The Twelfth")
             [ "the Glorious Twelfth"
             , "Orangemen's Day"
             , "the twelfth"
             ]
  , examples (datetimeHoliday (2013, 6, 24, 0, 0, 0) Day "Discovery Day")
             [ "discovery day"
             , "next discovery  day"
             ]
  , examples (datetimeHoliday (2018, 6, 25, 0, 0, 0) Day "Discovery Day")
             [ "discovery day 2018"
             ]
  , examples (datetimeHoliday (2020, 6, 22, 0, 0, 0) Day "Discovery Day")
             [ "discovery   day 2020"
             ]
  , examples (datetimeHoliday (2013, 6, 16, 0, 0, 0) Day "Father's Day")
             [ "Father's Day"
             ]
  , examples (datetimeHoliday (2012, 6, 17, 0, 0, 0) Day "Father's Day")
             [ "last fathers day"
             ]
  , examples (datetimeHoliday (1996, 6, 16, 0, 0, 0) Day "Father's Day")
             [ "fathers day 1996"
             ]
  , examples (datetimeHoliday (2018, 5, 21, 0, 0, 0) Day "Victoria Day")
             [ "Victoria day 2018"
             , "Sovereign's birthday 2018"
             ]
  , examples (datetimeHoliday (2013, 8, 5, 0, 0, 0) Day "Civic Holiday")
             [ "Civic Holiday"
             , "British Columbia Day"
             , "Natal Day"
             , "New Brunswick Day"
             , "Saskatchewan Day"
             , "Terry Fox Day"
             ]
  , examples (datetimeHoliday (2018, 2, 19, 0, 0, 0) Day "Family Day")
             [ "family day 2018"
             , "islander day 2018"
             , "louis riel day 2018"
             , "nova scotia heritage day 2018"
             ]
  , examples (datetimeHoliday (2013, 5, 12, 0, 0, 0) Day "Mother's Day")
             [ "Mother's Day"
             , "next mothers day"
             ]
  , examples (datetimeHoliday (2012, 5, 13, 0, 0, 0) Day "Mother's Day")
             [ "last mothers day"
             ]
  , examples (datetimeHoliday (2014, 5, 11, 0, 0, 0) Day "Mother's Day")
             [ "mothers day 2014"
             ]
  , examples (datetimeHoliday (2017, 5, 22, 0, 0, 0) Day "National Patriots' Day")
             [ "national patriots' day 2017"
             ]
  , examples (datetimeHoliday (2018, 5, 21, 0, 0, 0) Day "National Patriots' Day")
             [ "national patriots' day 2018"
             ]
  , examples (datetimeHoliday (2019, 5, 20, 0, 0, 0) Day "National Patriots' Day")
             [ "national patriots' day 2019"
             ]
  , examples (datetimeHoliday (2013, 9, 2, 0, 0, 0) Day "Labour Day")
             [ "labor day"
             ]
  , examples (datetimeHoliday (2012, 9, 3, 0, 0, 0) Day "Labour Day")
             [ "labor day of last year"
             , "Labour Day 2012"
             ]
  , examples (datetimeIntervalHoliday ((2013, 8, 30, 18, 0, 0), (2013, 9, 3, 0, 0, 0)) Hour "Labour Day weekend")
             [ "labor day weekend"
             ]
  , examples (datetimeHoliday (2013, 2, 2, 0, 0, 0) Day "Groundhog Day")
             [ "Groundhog day"
             , "groundhogs day"
             ]
  , examples (datetimeHoliday (2010, 4, 21, 0, 0, 0) Day "Administrative Professionals' Day")
             [ "administrative professionals' day 2010"
             ]
  , examples (datetimeHoliday (2019, 4, 24, 0, 0, 0) Day "Administrative Professionals' Day")
             [ "admin day 2019"
             , "secretaries day in six years"
             ]
  ]


-- 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 #-}

module Duckling.Time.EN.CA.Rules
  ( rules
  ) where

import Data.Maybe
import Prelude

import Duckling.Dimensions.Types
import Duckling.Numeral.Helpers (parseInt)
import Duckling.Regex.Types
import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData (..))
import Duckling.Types
import qualified Duckling.TimeGrain.Types as TG

-- Although one can see both MMDD and DDMM in Canada,
-- there is no direct way to implement this today. Let's fallback to MMDD (US).
ruleMMDD :: Rule
ruleMMDD = Rule
  { name = "mm/dd"
  , pattern =
    [ regex "(1[0-2]|0?[1-9])\\s?[/-]\\s?(3[01]|[12]\\d|0?[1-9])"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (mm:dd:_)):_) -> do
        m <- parseInt mm
        d <- parseInt dd
        tt $ monthDay m d
      _ -> Nothing
  }

ruleMMDDYYYY :: Rule
ruleMMDDYYYY = Rule
  { name = "mm/dd/yyyy"
  , pattern =
    [ regex "(1[0-2]|0?[1-9])[-/\\s](3[01]|[12]\\d|0?[1-9])[-/\\s](\\d{2,4})"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (mm:dd:yy:_)):_) -> do
        y <- parseInt yy
        m <- parseInt mm
        d <- parseInt dd
        tt $ yearMonthDay y m d
      _ -> Nothing
  }

-- Clashes with HHMMSS, hence only 4-digit years
ruleMMDDYYYYDot :: Rule
ruleMMDDYYYYDot = Rule
  { name = "mm.dd.yyyy"
  , pattern =
    [ regex "(1[0-2]|0?[1-9])\\.(3[01]|[12]\\d|0?[1-9])\\.(\\d{4})"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (mm:dd:yy:_)):_) -> do
        y <- parseInt yy
        m <- parseInt mm
        d <- parseInt dd
        tt $ yearMonthDay y m d
      _ -> Nothing
  }

rulePeriodicHolidays :: [Rule]
rulePeriodicHolidays = mkRuleHolidays
  -- Fixed dates, year over year
  [ ( "Anniversary of the Statute of Westminster", "anniversary of the statute of westminster", monthDay 12 11 )
  , ( "Memorial Day", "(canada|dominion|memorial) day", monthDay 7 1 )
  , ( "Groundhog Day", "groundhogs? day", monthDay 2 2 )
  , ( "Healthcare Aide Day", "healthcare aide day", monthDay 10 18 )
  , ( "National Aboriginal Day", "national aboriginal day", monthDay 6 21 )
  , ( "National Flag of Canada Day", "national flag of canada day", monthDay 2 15 )
  , ( "National Tartan Day", "national tartan day", monthDay 4 6 )
  , ( "Nunavut Day", "nunavut day", monthDay 7 9 )
  , ( "Remembrance Day", "remembrance day", monthDay 11 11 )
  , ( "St David's Day", "st\\.? david'?s day", monthDay 3 1 )
  , ( "St. Jean Baptiste Day", "st\\.? jean baptiste day", monthDay 6 24 )
  , ( "The Twelfth", "orangemen's day|the (glorious )?twelfth", monthDay 7 12 )
  , ( "Victoria Day", "sovereign's birthday|victoria day"
    , predLastOf (dayOfWeek 1) (monthDay 5 25) )
  , ( "Vimy Ridge Day", "vimy ridge day", monthDay 4 9 )

  -- Fixed day/week/month, year over year
  , ( "Civic Holiday"
    , "british columbia day|civic holiday|natal day|new brunswick day|Saskatchewan Day|terry fox day"
    , nthDOWOfMonth 1 1 8
    )
  , ( "Family Day"
    , "(family|islander|louis riel|nova scotia heritage) day"
    , nthDOWOfMonth 3 1 2 )
  , ( "Father's Day", "father'?s?'? day", nthDOWOfMonth 3 7 6 )
  , ( "Gold Cup Parade", "gold cup parade", nthDOWOfMonth 3 5 8 )
  , ( "Heritage Day in Alberta", "heritage day in alberta", nthDOWOfMonth 1 1 8 )
  , ( "Labour Day", "labou?r day", nthDOWOfMonth 1 1 9 )
  -- Long weekend before the first Monday of September
  , ( "Labour Day weekend", "labou?r day week(\\s|-)?ends?"
    , longWEBefore $ nthDOWOfMonth 1 1 9
    )
  , ( "Mother's Day", "mother'?s?'? day", nthDOWOfMonth 2 7 5 )
  , ( "Royal St. John's Regatta", "regatta day|royal st\\.? john's regatta"
    , nthDOWOfMonth 1 3 8 )
  , ( "Take our Daughters and Sons to Work Day"
    , "take our daughters and sons to work day", nthDOWOfMonth 1 3 11 )
  , ( "Thanksgiving Day", "thanks?giving( day)?", nthDOWOfMonth 2 1 10 )
  , ( "Yukon's Discovery Day", "(klondike gold|yukon's) discovery day"
    , nthDOWOfMonth 3 1 8 )

  -- Monday before May 25th
  , ( "National Patriots' Day", "national patriot'?s'? day"
    , predNthAfter (-1) (dayOfWeek 1) (monthDay 5 25) )

  -- Closest Monday to June 24th
  , ( "Discovery Day", "discovery\\s+day"
    , predNthClosest 0 (dayOfWeek 1) (monthDay 6 24) )

  -- Wednesday of the last full week of April, where a full week starts on
  -- Sunday and ends on Saturday.
  , ( "Administrative Professionals' Day"
    , "(administrative professional|secretarie|admin)('?s'?)? day"
    , cycleNthAfter False TG.Day (-3) $
        predNthAfter (-1) (dayOfWeek 6) (monthDay 5 1)
    )
  ]

rules :: [Rule]
rules =
  [ ruleMMDD
  , ruleMMDDYYYY
  , ruleMMDDYYYYDot
  ]
  ++ rulePeriodicHolidays


-- 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 OverloadedStrings #-}

module Duckling.Time.EN.GB.Corpus
  ( allExamples
  ) where

import Data.String
import Prelude

import Duckling.Testing.Types hiding (examples)
import Duckling.Time.Corpus
import Duckling.Time.Types hiding (Month)
import Duckling.TimeGrain.Types hiding (add)

allExamples :: [Example]
allExamples = concat
  [ examples (datetime (2013, 2, 15, 0, 0, 0) Day)
             [ "15/2"
             , "on 15/2"
             , "15 / 2"
             , "15-2"
             , "15 - 2"
             ]
  , examples (datetime (1974, 10, 31, 0, 0, 0) Day)
             [ "31/10/1974"
             , "31/10/74"
             , "31-10-74"
             , "31.10.1974"
             , "31 10 1974"
             ]
  , examples (datetime (2013, 10, 10, 0, 0, 0) Day)
             [ "10/10"
             , "10/10/2013"
             ]
  , examples (datetime (2013, 4, 25, 16, 0, 0) Minute)
             [ "25/4 at 4:00pm"
             ]
  , examples (datetimeHoliday (2013, 11, 28, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving day"
             , "thanksgiving"
             , "thanksgiving 2013"
             , "this thanksgiving"
             , "next thanksgiving day"
             ]
  , examples (datetimeHoliday (2014, 11, 27, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving of next year"
             , "thanksgiving 2014"
             ]
  , examples (datetimeHoliday (2012, 11, 22, 0, 0, 0) Day "Thanksgiving Day")
             [ "last thanksgiving"
             , "thanksgiving day 2012"
             ]
  , examples (datetimeHoliday (2016, 11, 24, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving 2016"
             ]
  , examples (datetimeHoliday (2017, 11, 23, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving 2017"
             ]
  , examples (datetimeHoliday (2013, 11, 5, 0, 0, 0) Day "Guy Fawkes Day")
             [ "guy fawkes day"
             ]
  , examples (datetimeHoliday (2018, 8, 27, 0, 0, 0) Day "August Bank Holiday")
             [ "august bank holiday 2018"
             , "summer bank holiday 2018"
             , "late summer bank holiday 2018"
             ]
  , examples (datetimeHoliday (2013, 6, 16, 0, 0, 0) Day "Father's Day")
             [ "Father's Day"
             ]
  , examples (datetimeHoliday (2012, 6, 17, 0, 0, 0) Day "Father's Day")
             [ "last fathers day"
             ]
  , examples (datetimeHoliday (1996, 6, 16, 0, 0, 0) Day "Father's Day")
             [ "fathers day 1996"
             ]
  , examples (datetimeHoliday (2013, 3, 10, 0, 0, 0) Day "Mothering Sunday")
             [ "Mother's Day"
             , "next mothers day"
             , "mothering sunday"
             ]
  , examples (datetimeHoliday (2012, 3, 18, 0, 0, 0) Day "Mothering Sunday")
             [ "mothers day 2012"
             , "last mothers day"
             ]
  , examples (datetimeHoliday (2014, 3, 30, 0, 0, 0) Day "Mothering Sunday")
             [ "mothers day 2014"
             ]
  , examples (datetimeHoliday (2013, 5, 19, 0, 0, 0) Day "Pentecost")
             [ "whitsunday"
             ]
  ]


-- 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 #-}

module Duckling.Time.EN.GB.Rules
  ( rules
  ) where

import Data.Maybe
import Prelude

import Duckling.Dimensions.Types
import Duckling.Numeral.Helpers (parseInt)
import Duckling.Regex.Types
import Duckling.Time.Computed (easterSunday)
import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData (..))
import Duckling.Types
import qualified Duckling.TimeGrain.Types as TG

ruleDDMM :: Rule
ruleDDMM = Rule
  { name = "dd/mm"
  , pattern =
    [ regex "(3[01]|[12]\\d|0?[1-9])\\s?[/-]\\s?(1[0-2]|0?[1-9])"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (dd:mm:_)):_) -> do
        d <- parseInt dd
        m <- parseInt mm
        tt $ monthDay m d
      _ -> Nothing
  }

ruleDDMMYYYY :: Rule
ruleDDMMYYYY = Rule
  { name = "dd/mm/yyyy"
  , pattern =
    [ regex "(3[01]|[12]\\d|0?[1-9])[-/\\s](1[0-2]|0?[1-9])[-/\\s](\\d{2,4})"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (dd:mm:yy:_)):_) -> do
        y <- parseInt yy
        d <- parseInt dd
        m <- parseInt mm
        tt $ yearMonthDay y m d
      _ -> Nothing
  }

-- Clashes with HHMMSS, hence only 4-digit years
ruleDDMMYYYYDot :: Rule
ruleDDMMYYYYDot = Rule
  { name = "dd.mm.yyyy"
  , pattern =
    [ regex "(3[01]|[12]\\d|0?[1-9])\\.(1[0-2]|0?[1-9])\\.(\\d{4})"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (dd:mm:yy:_)):_) -> do
        y <- parseInt yy
        d <- parseInt dd
        m <- parseInt mm
        tt $ yearMonthDay y m d
      _ -> Nothing
  }

rulePeriodicHolidays :: [Rule]
rulePeriodicHolidays = mkRuleHolidays
  -- Fixed dates, year over year
  [ ( "Bank Holiday", "bank holiday", monthDay 12 28 )
  , ( "Battle of the Boyne", "battle of the boyne", monthDay 7 12 )
  , ( "Burns Night", "burns night", monthDay 1 25 )
  , ( "Guy Fawkes Day", "guy fawkes day", monthDay 11 5 )
  , ( "Shakespeare Day", "shakespeare day", monthDay 4 23 )
  , ( "St Andrew's Day", "st\\.? andrew'?s day", monthDay 11 30 )
  , ( "St. David's Day", "st\\.? david'?s day", monthDay 3 1 )
  , ( "Victory in Europe Day", "victory in europe day", monthDay 5 8 )

  -- Fixed day/week/month, year over year
  , ( "August Bank Holiday", "(august|(late )?summer) bank holiday"
    , predLastOf (dayOfWeek 1) (month 8) )
  , ( "Early May Bank Holiday", "early may bank holiday", nthDOWOfMonth 1 1 5 )
  , ( "Father's Day", "father'?s?'? day", nthDOWOfMonth 3 7 6 )
  , ( "Remembrance Sunday", "remembrance sunday", nthDOWOfMonth 2 7 11 )
  , ( "Spring Bank Holiday", "(sprint|late may) bank holiday"
    , predLastOf (dayOfWeek 1) (month 5) )
  , ( "Thanksgiving Day", "thanks?giving( day)?", nthDOWOfMonth 4 4 11 )
  ]

ruleComputedHolidays :: [Rule]
ruleComputedHolidays = mkRuleHolidays
  -- 3 weeks before Easter
  [ ( "Mothering Sunday", "mothering sunday|mother'?s?'? day"
    , cycleNthAfter False TG.Day (-21) easterSunday )
  ]

rules :: [Rule]
rules =
  [ ruleDDMM
  , ruleDDMMYYYY
  , ruleDDMMYYYYDot
  ]
  ++ ruleComputedHolidays
  ++ rulePeriodicHolidays


-- 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 OverloadedStrings #-}

module Duckling.Time.EN.IE.Corpus
  ( allExamples
  ) where

import Data.String
import Prelude

import Duckling.Testing.Types hiding (examples)
import Duckling.Time.Corpus
import Duckling.Time.Types hiding (Month)
import Duckling.TimeGrain.Types hiding (add)

allExamples :: [Example]
allExamples = concat
  [ examples (datetime (2013, 2, 15, 0, 0, 0) Day)
             [ "15/2"
             , "on 15/2"
             , "15 / 2"
             , "15-2"
             , "15 - 2"
             ]
  , examples (datetime (1974, 10, 31, 0, 0, 0) Day)
             [ "31/10/1974"
             , "31/10/74"
             , "31-10-74"
             , "31.10.1974"
             , "31 10 1974"
             ]
  , examples (datetime (2013, 4, 25, 16, 0, 0) Minute)
             [ "25/4 at 4:00pm"
             ]
  , examples (datetime (2013, 10, 10, 0, 0, 0) Day)
             [ "10/10"
             , "10/10/2013"
             ]
  , examples (datetimeHoliday (2013, 11, 28, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving day"
             , "thanksgiving"
             , "thanksgiving 2013"
             , "this thanksgiving"
             , "next thanksgiving day"
             ]
  , examples (datetimeHoliday (2014, 11, 27, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving of next year"
             , "thanksgiving 2014"
             ]
  , examples (datetimeHoliday (2012, 11, 22, 0, 0, 0) Day "Thanksgiving Day")
             [ "last thanksgiving"
             , "thanksgiving day 2012"
             ]
  , examples (datetimeHoliday (2016, 11, 24, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving 2016"
             ]
  , examples (datetimeHoliday (2017, 11, 23, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving 2017"
             ]
  , examples (datetimeHoliday (2018, 8, 6, 0, 0, 0) Day "August Bank Holiday")
             [ "august bank holiday 2018"
             , "summer bank holiday 2018"
             ]
  , examples (datetimeHoliday (2013, 6, 16, 0, 0, 0) Day "Father's Day")
             [ "Father's Day"
             ]
  , examples (datetimeHoliday (2012, 6, 17, 0, 0, 0) Day "Father's Day")
             [ "last fathers day"
             ]
  , examples (datetimeHoliday (1996, 6, 16, 0, 0, 0) Day "Father's Day")
             [ "fathers day 1996"
             ]
  , examples (datetimeHoliday (2013, 5, 12, 0, 0, 0) Day "Mother's Day")
             [ "Mother's Day"
             , "next mothers day"
             ]
  , examples (datetimeHoliday (2012, 5, 13, 0, 0, 0) Day "Mother's Day")
             [ "last mothers day"
             ]
  , examples (datetimeHoliday (2014, 5, 11, 0, 0, 0) Day "Mother's Day")
             [ "mothers day 2014"
             ]
  , examples (datetimeHoliday (2013, 5, 6, 0, 0, 0) Day "Labour Day")
             [ "labour day"
             ]
  , examples (datetimeHoliday (2012, 5, 7, 0, 0, 0) Day "Labour Day")
             [ "labour day of last year"
             , "Labour Day 2012"
             ]
  ]


-- 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 #-}

module Duckling.Time.EN.IE.Rules
  ( rules
  ) where

import Data.Maybe
import Prelude

import Duckling.Dimensions.Types
import Duckling.Numeral.Helpers (parseInt)
import Duckling.Regex.Types
import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData (..))
import Duckling.Types

ruleDDMM :: Rule
ruleDDMM = Rule
  { name = "dd/mm"
  , pattern =
    [ regex "(3[01]|[12]\\d|0?[1-9])\\s?[/-]\\s?(1[0-2]|0?[1-9])"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (dd:mm:_)):_) -> do
        d <- parseInt dd
        m <- parseInt mm
        tt $ monthDay m d
      _ -> Nothing
  }

ruleDDMMYYYY :: Rule
ruleDDMMYYYY = Rule
  { name = "dd/mm/yyyy"
  , pattern =
    [ regex "(3[01]|[12]\\d|0?[1-9])[-/\\s](1[0-2]|0?[1-9])[-/\\s](\\d{2,4})"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (dd:mm:yy:_)):_) -> do
        y <- parseInt yy
        d <- parseInt dd
        m <- parseInt mm
        tt $ yearMonthDay y m d
      _ -> Nothing
  }

-- Clashes with HHMMSS, hence only 4-digit years
ruleDDMMYYYYDot :: Rule
ruleDDMMYYYYDot = Rule
  { name = "dd.mm.yyyy"
  , pattern =
    [ regex "(3[01]|[12]\\d|0?[1-9])\\.(1[0-2]|0?[1-9])\\.(\\d{4})"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (dd:mm:yy:_)):_) -> do
        y <- parseInt yy
        d <- parseInt dd
        m <- parseInt mm
        tt $ yearMonthDay y m d
      _ -> Nothing
  }

rulePeriodicHolidays :: [Rule]
rulePeriodicHolidays = mkRuleHolidays
  -- Fixed day/week/month, year over year
  [ ( "August Bank Holiday", "(august|summer) bank holiday"
    , nthDOWOfMonth 1 1 8 )
  , ( "Early May Bank Holiday", "early may bank holiday", nthDOWOfMonth 1 1 5 )
  , ( "Father's Day", "father'?s?'? day", nthDOWOfMonth 3 7 6 )
  , ( "Mother's Day", "mother'?s?'? day", nthDOWOfMonth 2 7 5 )
  , ( "June Bank Holiday", "june bank holiday", nthDOWOfMonth 1 1 6 )
  , ( "Labour Day", "labour day", nthDOWOfMonth 1 1 5 )
  , ( "October Bank Holiday", "october (bank )?holiday"
    , predLastOf (dayOfWeek 1) (month 10) )
  , ( "Thanksgiving Day", "thanks?giving( day)?", nthDOWOfMonth 4 4 11 )
  ]

rules :: [Rule]
rules =
  [ ruleDDMM
  , ruleDDMMYYYY
  , ruleDDMMYYYYDot
  ]
  ++ rulePeriodicHolidays


-- 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 OverloadedStrings #-}

module Duckling.Time.EN.IN.Corpus
  ( allExamples
  ) where

import Data.String
import Prelude

import Duckling.Testing.Types hiding (examples)
import Duckling.Time.Corpus
import Duckling.Time.Types hiding (Month)
import Duckling.TimeGrain.Types hiding (add)

allExamples :: [Example]
allExamples = concat
  [ examples (datetime (2013, 2, 15, 0, 0, 0) Day)
             [ "15/2"
             , "on 15/2"
             , "15 / 2"
             , "15-2"
             , "15 - 2"
             ]
  , examples (datetime (1974, 10, 31, 0, 0, 0) Day)
             [ "31/10/1974"
             , "31/10/74"
             , "31-10-74"
             , "31.10.1974"
             , "31 10 1974"
             ]
  , examples (datetime (2013, 4, 25, 16, 0, 0) Minute)
             [ "25/4 at 4:00pm"
             ]
  , examples (datetime (2013, 10, 10, 0, 0, 0) Day)
             [ "10/10"
             , "10/10/2013"
             ]
  , examples (datetimeHoliday (2013, 11, 28, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving day"
             , "thanksgiving"
             , "thanksgiving 2013"
             , "this thanksgiving"
             , "next thanksgiving day"
             ]
  , examples (datetimeHoliday (2014, 11, 27, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving of next year"
             , "thanksgiving 2014"
             ]
  , examples (datetimeHoliday (2012, 11, 22, 0, 0, 0) Day "Thanksgiving Day")
             [ "last thanksgiving"
             , "thanksgiving day 2012"
             ]
  , examples (datetimeHoliday (2016, 11, 24, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving 2016"
             ]
  , examples (datetimeHoliday (2017, 11, 23, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving 2017"
             ]
  , examples (datetimeHoliday (2013, 2, 19, 0, 0, 0) Day "Shivaji Jayanti")
             [ "shivaji jayanti 2013"
             ]
  , examples (datetimeHoliday (2013, 8, 15, 0, 0, 0) Day "Independence Day")
             [ "independence day"
             ]
  , examples (datetimeHoliday (2013, 6, 16, 0, 0, 0) Day "Father's Day")
             [ "Father's Day"
             ]
  , examples (datetimeHoliday (2012, 6, 17, 0, 0, 0) Day "Father's Day")
             [ "last fathers day"
             ]
  , examples (datetimeHoliday (1996, 6, 16, 0, 0, 0) Day "Father's Day")
             [ "fathers day 1996"
             ]
  , examples (datetimeHoliday (2013, 5, 12, 0, 0, 0) Day "Mother's Day")
             [ "Mother's Day"
             , "next mothers day"
             ]
  , examples (datetimeHoliday (2012, 5, 13, 0, 0, 0) Day "Mother's Day")
             [ "last mothers day"
             ]
  , examples (datetimeHoliday (2014, 5, 11, 0, 0, 0) Day "Mother's Day")
             [ "mothers day 2014"
             ]
  , examples (datetimeHoliday (2013, 5, 1, 0, 0, 0) Day "Labour Day")
             [ "labour day"
             ]
  , examples (datetimeHoliday (2012, 5, 1, 0, 0, 0) Day "Labour Day")
             [ "labour day of last year"
             , "Labour Day 2012"
             ]
  , examples (datetimeHoliday (2018, 3, 30, 0, 0, 0) Day "Hazarat Ali's Birthday")
             [ "Hazarat Ali's Birthday 2018"
             ]
  , examples (datetimeHoliday (2019, 3, 20, 0, 0, 0) Day "Hazarat Ali's Birthday")
             [ "Hazarat Ali's Birthday 2019"
             ]
  , examples (datetimeIntervalHoliday ((2018, 5, 16, 0, 0, 0), (2018, 6, 15, 0, 0, 0)) Day "Ramadan")
             [ "ramzaan 2018"
             ]
  ]


-- 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 #-}

module Duckling.Time.EN.IN.Rules
  ( rules
  ) where

import Data.Maybe
import Prelude

import Duckling.Dimensions.Types
import Duckling.Numeral.Helpers (parseInt)
import Duckling.Regex.Types
import Duckling.Time.Computed
import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData (..))
import Duckling.Types
import qualified Duckling.TimeGrain.Types as TG

ruleDDMM :: Rule
ruleDDMM = Rule
  { name = "dd/mm"
  , pattern =
    [ regex "(3[01]|[12]\\d|0?[1-9])\\s?[/-]\\s?(1[0-2]|0?[1-9])"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (dd:mm:_)):_) -> do
        d <- parseInt dd
        m <- parseInt mm
        tt $ monthDay m d
      _ -> Nothing
  }

ruleDDMMYYYY :: Rule
ruleDDMMYYYY = Rule
  { name = "dd/mm/yyyy"
  , pattern =
    [ regex "(3[01]|[12]\\d|0?[1-9])[-/\\s](1[0-2]|0?[1-9])[-/\\s](\\d{2,4})"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (dd:mm:yy:_)):_) -> do
        y <- parseInt yy
        d <- parseInt dd
        m <- parseInt mm
        tt $ yearMonthDay y m d
      _ -> Nothing
  }

-- Clashes with HHMMSS, hence only 4-digit years
ruleDDMMYYYYDot :: Rule
ruleDDMMYYYYDot = Rule
  { name = "dd.mm.yyyy"
  , pattern =
    [ regex "(3[01]|[12]\\d|0?[1-9])\\.(1[0-2]|0?[1-9])\\.(\\d{4})"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (dd:mm:yy:_)):_) -> do
        y <- parseInt yy
        d <- parseInt dd
        m <- parseInt mm
        tt $ yearMonthDay y m d
      _ -> Nothing
  }

rulePeriodicHolidays :: [Rule]
rulePeriodicHolidays = mkRuleHolidays
  -- Fixed dates, year over year
  [ ( "Guru Tegh Bahadur's Martyrdom Day", "guru tegh bahadur'?s martyrdom day"
    , monthDay 11 24 )
  , ( "Independence Day", "independence day", monthDay 8 15 )
  , ( "Labour Day", "labour day", monthDay 5 1 )
  , ( "Mahatma Gandhi Jayanti", "mahatma gandhi jayanti", monthDay 10 2 )
  , ( "Republic Day", "republic day", monthDay 1 26 )
  , ( "Shivaji Jayanti", "shivaji jayanti", monthDay 2 19 )

  -- Fixed day/week/month, year over year
  , ( "Father's Day", "father'?s?'? day", nthDOWOfMonth 3 7 6 )
  , ( "Friendship Day", "friendship day", nthDOWOfMonth 1 7 8 )
  , ( "Mother's Day", "mother'?s?'? day", nthDOWOfMonth 2 7 5 )
  , ( "Thanksgiving Day", "thanks?giving( day)?", nthDOWOfMonth 4 4 11 )
  ]

ruleComputedHolidays :: [Rule]
ruleComputedHolidays = mkRuleHolidays
  [ ( "Hazarat Ali's Birthday", "hazarat ali's birthday"
    , cycleNthAfter False TG.Day 12 rajab )
  ]

rules :: [Rule]
rules =
  [ ruleDDMM
  , ruleDDMMYYYY
  , ruleDDMMYYYYDot
  ]
  ++ ruleComputedHolidays
  ++ rulePeriodicHolidays


-- 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 OverloadedStrings #-}

module Duckling.Time.EN.JM.Corpus
  ( allExamples
  ) where

import Data.String
import Prelude

import Duckling.Testing.Types hiding (examples)
import Duckling.Time.Corpus
import Duckling.Time.Types hiding (Month)
import Duckling.TimeGrain.Types hiding (add)

allExamples :: [Example]
allExamples = concat
  [ examples (datetime (2013, 2, 15, 0, 0, 0) Day)
             [ "15/2"
             , "on 15/2"
             , "15 / 2"
             , "15-2"
             , "15 - 2"
             ]
  , examples (datetime (1974, 10, 31, 0, 0, 0) Day)
             [ "31/10/1974"
             , "31/10/74"
             , "31-10-74"
             , "31.10.1974"
             , "31 10 1974"
             ]
  , examples (datetime (2013, 4, 25, 16, 0, 0) Minute)
             [ "25/4 at 4:00pm"
             ]
  , examples (datetime (2013, 10, 10, 0, 0, 0) Day)
             [ "10/10"
             , "10/10/2013"
             ]
  , examples (datetimeHoliday (2013, 11, 28, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving day"
             , "thanksgiving"
             , "thanksgiving 2013"
             , "this thanksgiving"
             , "next thanksgiving day"
             ]
  , examples (datetimeHoliday (2014, 11, 27, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving of next year"
             , "thanksgiving 2014"
             ]
  , examples (datetimeHoliday (2012, 11, 22, 0, 0, 0) Day "Thanksgiving Day")
             [ "last thanksgiving"
             , "thanksgiving day 2012"
             ]
  , examples (datetimeHoliday (2016, 11, 24, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving 2016"
             ]
  , examples (datetimeHoliday (2017, 11, 23, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving 2017"
             ]
  , examples (datetimeHoliday (2013, 6, 16, 0, 0, 0) Day "Father's Day")
             [ "Father's Day"
             ]
  , examples (datetimeHoliday (2012, 6, 17, 0, 0, 0) Day "Father's Day")
             [ "last fathers day"
             ]
  , examples (datetimeHoliday (1996, 6, 16, 0, 0, 0) Day "Father's Day")
             [ "fathers day 1996"
             ]
  , examples (datetimeHoliday (2013, 5, 12, 0, 0, 0) Day "Mother's Day")
             [ "Mother's Day"
             , "next mothers day"
             ]
  , examples (datetimeHoliday (2012, 5, 13, 0, 0, 0) Day "Mother's Day")
             [ "last mothers day"
             ]
  , examples (datetimeHoliday (2014, 5, 11, 0, 0, 0) Day "Mother's Day")
             [ "mothers day 2014"
             ]
  , examples (datetimeHoliday (2013, 5, 23, 0, 0, 0) Day "Labour Day")
             [ "labour day"
             ]
  , examples (datetimeHoliday (2012, 5, 23, 0, 0, 0) Day "Labour Day")
             [ "labour day of last year"
             , "Labour Day 2012"
             ]
  , examples (datetimeHoliday (2013, 10, 21, 0, 0, 0) Day "Heroes' Day")
             [ "heroes' day"
             ]
  ]


-- 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 #-}

module Duckling.Time.EN.JM.Rules
  ( rules
  ) where

import Data.Maybe
import Prelude

import Duckling.Dimensions.Types
import Duckling.Numeral.Helpers (parseInt)
import Duckling.Regex.Types
import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData (..))
import Duckling.Types

ruleDDMM :: Rule
ruleDDMM = Rule
  { name = "dd/mm"
  , pattern =
    [ regex "(3[01]|[12]\\d|0?[1-9])\\s?[/-]\\s?(1[0-2]|0?[1-9])"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (dd:mm:_)):_) -> do
        d <- parseInt dd
        m <- parseInt mm
        tt $ monthDay m d
      _ -> Nothing
  }

ruleDDMMYYYY :: Rule
ruleDDMMYYYY = Rule
  { name = "dd/mm/yyyy"
  , pattern =
    [ regex "(3[01]|[12]\\d|0?[1-9])[-/\\s](1[0-2]|0?[1-9])[-/\\s](\\d{2,4})"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (dd:mm:yy:_)):_) -> do
        y <- parseInt yy
        d <- parseInt dd
        m <- parseInt mm
        tt $ yearMonthDay y m d
      _ -> Nothing
  }

-- Clashes with HHMMSS, hence only 4-digit years
ruleDDMMYYYYDot :: Rule
ruleDDMMYYYYDot = Rule
  { name = "dd.mm.yyyy"
  , pattern =
    [ regex "(3[01]|[12]\\d|0?[1-9])\\.(1[0-2]|0?[1-9])\\.(\\d{4})"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (dd:mm:yy:_)):_) -> do
        y <- parseInt yy
        d <- parseInt dd
        m <- parseInt mm
        tt $ yearMonthDay y m d
      _ -> Nothing
  }

rulePeriodicHolidays :: [Rule]
rulePeriodicHolidays = mkRuleHolidays
  -- Fixed dates, year over year
  [ ( "Labour Day", "labour day", monthDay 5 23 )

  -- Fixed day/week/month, year over year
  , ( "Father's Day", "father'?s?'? day", nthDOWOfMonth 3 7 6 )
  , ( "Heroes' Day", "heroes' day", nthDOWOfMonth 3 1 10 )
  , ( "Mother's Day", "mother'?s?'? day", nthDOWOfMonth 2 7 5 )
  , ( "Thanksgiving Day", "thanks?giving( day)?", nthDOWOfMonth 4 4 11 )
  ]

rules :: [Rule]
rules =
  [ ruleDDMM
  , ruleDDMMYYYY
  , ruleDDMMYYYYDot
  ]
  ++ rulePeriodicHolidays


-- 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 OverloadedStrings #-}

module Duckling.Time.EN.NZ.Corpus
  ( allExamples
  ) where

import Data.String
import Prelude

import Duckling.Testing.Types hiding (examples)
import Duckling.Time.Corpus
import Duckling.Time.Types hiding (Month)
import Duckling.TimeGrain.Types hiding (add)

allExamples :: [Example]
allExamples = concat
  [ examples (datetime (2013, 2, 15, 0, 0, 0) Day)
             [ "15/2"
             , "on 15/2"
             , "15 / 2"
             , "15-2"
             , "15 - 2"
             ]
  , examples (datetime (1974, 10, 31, 0, 0, 0) Day)
             [ "31/10/1974"
             , "31/10/74"
             , "31-10-74"
             , "31.10.1974"
             , "31 10 1974"
             ]
  , examples (datetime (2013, 4, 25, 16, 0, 0) Minute)
             [ "25/4 at 4:00pm"
             ]
  , examples (datetime (2013, 10, 10, 0, 0, 0) Day)
             [ "10/10"
             , "10/10/2013"
             ]
  , examples (datetimeHoliday (2013, 11, 28, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving day"
             , "thanksgiving"
             , "thanksgiving 2013"
             , "this thanksgiving"
             , "next thanksgiving day"
             ]
  , examples (datetimeHoliday (2014, 11, 27, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving of next year"
             , "thanksgiving 2014"
             ]
  , examples (datetimeHoliday (2012, 11, 22, 0, 0, 0) Day "Thanksgiving Day")
             [ "last thanksgiving"
             , "thanksgiving day 2012"
             ]
  , examples (datetimeHoliday (2016, 11, 24, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving 2016"
             ]
  , examples (datetimeHoliday (2017, 11, 23, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving 2017"
             ]
  , examples (datetimeHoliday (2013, 4, 25, 0, 0, 0) Day "ANZAC Day")
             [ "ANZAC day"
             ]
  , examples (datetimeHoliday (2013, 9, 1, 0, 0, 0) Day "Father's Day")
             [ "Father's Day"
             ]
  , examples (datetimeHoliday (2012, 9, 2, 0, 0, 0) Day "Father's Day")
             [ "last fathers day"
             ]
  , examples (datetimeHoliday (1996, 9, 1, 0, 0, 0) Day "Father's Day")
             [ "fathers day 1996"
             ]
  , examples (datetimeHoliday (2013, 5, 12, 0, 0, 0) Day "Mother's Day")
             [ "Mother's Day"
             , "next mothers day"
             ]
  , examples (datetimeHoliday (2012, 5, 13, 0, 0, 0) Day "Mother's Day")
             [ "last mothers day"
             ]
  , examples (datetimeHoliday  (2014, 5, 11, 0, 0, 0) Day "Mother's Day")
             [ "mothers day 2014"
             ]
  , examples (datetimeHoliday (2013, 10, 28, 0, 0, 0) Day "Labour Day")
             [ "labour day"
             ]
  , examples (datetimeHoliday (2012, 10, 22, 0, 0, 0) Day "Labour Day")
             [ "labour day of last year"
             , "Labour Day 2012"
             ]
  , examples (datetimeHoliday (2013, 4, 17, 0, 0, 0) Day "Administrative Professionals' Day")
             [ "admin day"
             ]
  ]


-- 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 #-}

module Duckling.Time.EN.NZ.Rules
  ( rules
  ) where

import Data.Maybe
import Prelude

import Duckling.Dimensions.Types
import Duckling.Numeral.Helpers (parseInt)
import Duckling.Regex.Types
import Duckling.Time.Computed (easterSunday)
import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData (..))
import Duckling.Types
import qualified Duckling.TimeGrain.Types as TG

ruleDDMM :: Rule
ruleDDMM = Rule
  { name = "dd/mm"
  , pattern =
    [ regex "(3[01]|[12]\\d|0?[1-9])\\s?[/-]\\s?(1[0-2]|0?[1-9])"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (dd:mm:_)):_) -> do
        d <- parseInt dd
        m <- parseInt mm
        tt $ monthDay m d
      _ -> Nothing
  }

ruleDDMMYYYY :: Rule
ruleDDMMYYYY = Rule
  { name = "dd/mm/yyyy"
  , pattern =
    [ regex "(3[01]|[12]\\d|0?[1-9])[-/\\s](1[0-2]|0?[1-9])[-/\\s](\\d{2,4})"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (dd:mm:yy:_)):_) -> do
        y <- parseInt yy
        d <- parseInt dd
        m <- parseInt mm
        tt $ yearMonthDay y m d
      _ -> Nothing
  }

-- Clashes with HHMMSS, hence only 4-digit years
ruleDDMMYYYYDot :: Rule
ruleDDMMYYYYDot = Rule
  { name = "dd.mm.yyyy"
  , pattern =
    [ regex "(3[01]|[12]\\d|0?[1-9])\\.(1[0-2]|0?[1-9])\\.(\\d{4})"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (dd:mm:yy:_)):_) -> do
        y <- parseInt yy
        d <- parseInt dd
        m <- parseInt mm
        tt $ yearMonthDay y m d
      _ -> Nothing
  }

rulePeriodicHolidays :: [Rule]
rulePeriodicHolidays = mkRuleHolidays
  -- Fixed dates, year over year
  [ ( "ANZAC Day", "anzac day", monthDay 4 25 )
  , ( "Guy Fawkes Night", "guy fawkes night", monthDay 11 5 )
  , ( "Waitangi Day", "waitangi day", monthDay 2 6 )

  -- Fixed day/week/month, year over year
  , ( "Administrative Professionals' Day"
    , "(administrative professional|secretarie|admin)('?s'?)? day"
    , nthDOWOfMonth 3 3 4 )
  , ( "Father's Day", "father'?s?'? day", nthDOWOfMonth 1 7 9 )
  , ( "Labour Day", "labour day", nthDOWOfMonth 4 1 10 )
  , ( "Mother's Day", "mother'?s?'? day", nthDOWOfMonth 2 7 5 )
  , ( "Queen's birthday", "queen's birthday", nthDOWOfMonth 1 1 6 )
  , ( "Thanksgiving Day", "thanks?giving( day)?", nthDOWOfMonth 4 4 11 )
  ]

ruleComputedHolidays :: [Rule]
ruleComputedHolidays = mkRuleHolidays
  [ ( "Easter Tuesday", "easter\\s+tue(sday)?"
    , cycleNthAfter False TG.Day 2 easterSunday )
  ]

rules :: [Rule]
rules =
  [ ruleDDMM
  , ruleDDMMYYYY
  , ruleDDMMYYYYDot
  ]
  ++ ruleComputedHolidays
  ++ rulePeriodicHolidays


-- 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 OverloadedStrings #-}

module Duckling.Time.EN.PH.Corpus
  ( allExamples
  ) where

import Data.String
import Prelude

import Duckling.Testing.Types hiding (examples)
import Duckling.Time.Corpus
import Duckling.Time.Types hiding (Month)
import Duckling.TimeGrain.Types hiding (add)

allExamples :: [Example]
allExamples = concat
  [ examples (datetime (2013, 2, 15, 0, 0, 0) Day)
             [ "2/15"
             , "on 2/15"
             , "2 / 15"
             , "2-15"
             , "2 - 15"
             ]
  , examples (datetime (1974, 10, 31, 0, 0, 0) Day)
             [ "10/31/1974"
             , "10/31/74"
             , "10-31-74"
             , "10.31.1974"
             , "10 31 1974"
             ]
  , examples (datetime (2013, 4, 25, 16, 0, 0) Minute)
             [ "4/25 at 4:00pm"
             ]
  , examples (datetimeHoliday (2013, 11, 28, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving day"
             , "thanksgiving"
             , "thanksgiving 2013"
             , "this thanksgiving"
             , "next thanksgiving day"
             ]
  , examples (datetimeHoliday (2014, 11, 27, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving of next year"
             , "thanksgiving 2014"
             ]
  , examples (datetimeHoliday (2012, 11, 22, 0, 0, 0) Day "Thanksgiving Day")
             [ "last thanksgiving"
             , "thanksgiving day 2012"
             ]
  , examples (datetimeHoliday (2016, 11, 24, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving 2016"
             ]
  , examples (datetimeHoliday (2017, 11, 23, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving 2017"
             ]
  , examples (datetimeHoliday (2013, 12, 30, 0, 0, 0) Day "Rizal Day")
             [ "Rizal day"
             ]
  , examples (datetimeHoliday (2013, 6, 12, 0, 0, 0) Day "Independence Day")
             [ "Independence day"
             ]
  , examples (datetimeHoliday (2013, 6, 16, 0, 0, 0) Day "Father's Day")
             [ "Father's Day"
             ]
  , examples (datetimeHoliday (2012, 6, 17, 0, 0, 0) Day "Father's Day")
             [ "last fathers day"
             ]
  , examples (datetimeHoliday (1996, 6, 16, 0, 0, 0) Day "Father's Day")
             [ "fathers day 1996"
             ]
  , examples (datetimeHoliday (2013, 5, 12, 0, 0, 0) Day "Mother's Day")
             [ "Mother's Day"
             , "next mothers day"
             ]
  , examples (datetimeHoliday (2012, 5, 13, 0, 0, 0) Day "Mother's Day")
             [ "last mothers day"
             ]
  , examples (datetimeHoliday (2014, 5, 11, 0, 0, 0) Day "Mother's Day")
             [ "mothers day 2014"
             ]
  , examples (datetimeHoliday (2013, 5, 1, 0, 0, 0) Day "Labour Day")
             [ "labour day"
             ]
  , examples (datetimeHoliday (2012, 5, 1, 0, 0, 0) Day "Labour Day")
             [ "labour day of last year"
             , "Labour Day 2012"
             ]
  , examples (datetimeHoliday (2013, 8, 26, 0, 0, 0) Day "National Heroes' Day")
             [ "national heroes' day"
             ]
  ]


-- 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 #-}

module Duckling.Time.EN.PH.Rules
  ( rules
  ) where

import Data.Maybe
import Prelude

import Duckling.Dimensions.Types
import Duckling.Numeral.Helpers (parseInt)
import Duckling.Regex.Types
import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData (..))
import Duckling.Types

ruleMMDD :: Rule
ruleMMDD = Rule
  { name = "mm/dd"
  , pattern =
    [ regex "(1[0-2]|0?[1-9])\\s?[/-]\\s?(3[01]|[12]\\d|0?[1-9])"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (mm:dd:_)):_) -> do
        m <- parseInt mm
        d <- parseInt dd
        tt $ monthDay m d
      _ -> Nothing
  }

ruleMMDDYYYY :: Rule
ruleMMDDYYYY = Rule
  { name = "mm/dd/yyyy"
  , pattern =
    [ regex "(1[0-2]|0?[1-9])[-/\\s](3[01]|[12]\\d|0?[1-9])[-/\\s](\\d{2,4})"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (mm:dd:yy:_)):_) -> do
        y <- parseInt yy
        m <- parseInt mm
        d <- parseInt dd
        tt $ yearMonthDay y m d
      _ -> Nothing
  }

-- Clashes with HHMMSS, hence only 4-digit years
ruleMMDDYYYYDot :: Rule
ruleMMDDYYYYDot = Rule
  { name = "mm.dd.yyyy"
  , pattern =
    [ regex "(1[0-2]|0?[1-9])\\.(3[01]|[12]\\d|0?[1-9])\\.(\\d{4})"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (mm:dd:yy:_)):_) -> do
        y <- parseInt yy
        m <- parseInt mm
        d <- parseInt dd
        tt $ yearMonthDay y m d
      _ -> Nothing
  }

rulePeriodicHolidays :: [Rule]
rulePeriodicHolidays = mkRuleHolidays
  -- Fixed dates, year over year
  [ ( "Arbor Day", "arbor day", monthDay 6 25 )
  , ( "Bonifacio Day", "bonifacio day", monthDay 11 30 )
  , ( "Independence Day", "independence day", monthDay 6 12 )
  , ( "Labour Day", "labour day", monthDay 5 1 )
  , ( "Ninoy Aquino Day", "ninoy aquino day", monthDay 8 21 )
  , ( "People Power Anniversary", "(edsa revolution|people power) anniversary"
    , monthDay 2 25 )
  , ( "Rizal Day", "rizal day", monthDay 12 30 )
  , ( "The Day of Valor", "the day of valor", monthDay 4 9 )

  -- Fixed day/week/month, year over year
  , ( "Father's Day", "father'?s?'? day", nthDOWOfMonth 3 7 6 )
  , ( "Mother's Day", "mother'?s?'? day", nthDOWOfMonth 2 7 5 )
  , ( "National Elections Day", "national elections day", nthDOWOfMonth 2 1 5 )
  , ( "National Heroes' Day", "(national )?heroes' day"
    , predLastOf (dayOfWeek 1) (month 8) )
  , ( "Parents' Day", "parents' day", nthDOWOfMonth 1 1 12 )
  , ( "Thanksgiving Day", "thanks?giving( day)?", nthDOWOfMonth 4 4 11 )
  ]

rules :: [Rule]
rules =
  [ ruleMMDD
  , ruleMMDDYYYY
  , ruleMMDDYYYYDot
  ]
  ++ rulePeriodicHolidays


-- 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 OverloadedStrings #-}

module Duckling.Time.EN.TT.Corpus
  ( allExamples
  ) where

import Data.String
import Prelude

import Duckling.Testing.Types hiding (examples)
import Duckling.Time.Corpus
import Duckling.TimeGrain.Types hiding (add)

allExamples :: [Example]
allExamples = concat
  [ examples (datetime (2013, 2, 15, 0, 0, 0) Day)
             [ "15/2"
             , "on 15/2"
             , "15 / 2"
             , "15-2"
             , "15 - 2"
             ]
  , examples (datetime (1974, 10, 31, 0, 0, 0) Day)
             [ "31/10/1974"
             , "31/10/74"
             , "31-10-74"
             , "31.10.1974"
             , "31 10 1974"
             ]
  , examples (datetime (2013, 4, 25, 16, 0, 0) Minute)
             [ "25/4 at 4:00pm"
             ]
  , examples (datetime (2013, 10, 10, 0, 0, 0) Day)
             [ "10/10"
             , "10/10/2013"
             ]
  , examples (datetimeHoliday (2013, 11, 28, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving day"
             , "thanksgiving"
             , "thanksgiving 2013"
             , "this thanksgiving"
             , "next thanksgiving day"
             ]
  , examples (datetimeHoliday (2014, 11, 27, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving of next year"
             , "thanksgiving 2014"
             ]
  , examples (datetimeHoliday (2012, 11, 22, 0, 0, 0) Day "Thanksgiving Day")
             [ "last thanksgiving"
             , "thanksgiving day 2012"
             ]
  , examples (datetimeHoliday (2016, 11, 24, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving 2016"
             ]
  , examples (datetimeHoliday (2017, 11, 23, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving 2017"
             ]
  , examples (datetimeHoliday (2013, 5, 30, 0, 0, 0) Day "Indian Arrival Day")
             [ "Indian arrival day"
             ]
  , examples (datetimeHoliday (2013, 6, 16, 0, 0, 0) Day "Father's Day")
             [ "Father's Day"
             ]
  , examples (datetimeHoliday (2012, 6, 17, 0, 0, 0) Day "Father's Day")
             [ "last fathers day"
             ]
  , examples (datetimeHoliday (1996, 6, 16, 0, 0, 0) Day "Father's Day")
             [ "fathers day 1996"
             ]
  , examples (datetimeHoliday (2013, 5, 12, 0, 0, 0) Day "Mother's Day")
             [ "Mother's Day"
             , "next mothers day"
             ]
  , examples (datetimeHoliday (2012, 5, 13, 0, 0, 0) Day "Mother's Day")
             [ "last mothers day"
             ]
  , examples (datetimeHoliday (2014, 5, 11, 0, 0, 0) Day "Mother's Day")
             [ "mothers day 2014"
             ]
  , examples (datetimeHoliday (2013, 6, 19, 0, 0, 0) Day "Labour Day")
             [ "labour day"
             ]
  , examples (datetimeHoliday (2012, 6, 19, 0, 0, 0) Day "Labour Day")
             [ "labour day of last year"
             , "Labour Day 2012"
             ]
  , examples (datetimeHoliday (2017, 9, 30, 0, 0, 0) Day "Hosay")
             [ "hosay 2017"
             ]
  ]


-- 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 #-}

module Duckling.Time.EN.TT.Rules
  ( rules
  ) where

import Data.Maybe
import Prelude

import Duckling.Dimensions.Types
import Duckling.Numeral.Helpers (parseInt)
import Duckling.Regex.Types
import Duckling.Time.Computed
import Duckling.Time.Helpers
import Duckling.Types
import qualified Duckling.TimeGrain.Types as TG

ruleDDMM :: Rule
ruleDDMM = Rule
  { name = "dd/mm"
  , pattern =
    [ regex "(3[01]|[12]\\d|0?[1-9])\\s?[/-]\\s?(1[0-2]|0?[1-9])"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (dd:mm:_)):_) -> do
        d <- parseInt dd
        m <- parseInt mm
        tt $ monthDay m d
      _ -> Nothing
  }

ruleDDMMYYYY :: Rule
ruleDDMMYYYY = Rule
  { name = "dd/mm/yyyy"
  , pattern =
    [ regex "(3[01]|[12]\\d|0?[1-9])[-/\\s](1[0-2]|0?[1-9])[-/\\s](\\d{2,4})"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (dd:mm:yy:_)):_) -> do
        y <- parseInt yy
        d <- parseInt dd
        m <- parseInt mm
        tt $ yearMonthDay y m d
      _ -> Nothing
  }

-- Clashes with HHMMSS, hence only 4-digit years
ruleDDMMYYYYDot :: Rule
ruleDDMMYYYYDot = Rule
  { name = "dd.mm.yyyy"
  , pattern =
    [ regex "(3[01]|[12]\\d|0?[1-9])\\.(1[0-2]|0?[1-9])\\.(\\d{4})"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (dd:mm:yy:_)):_) -> do
        y <- parseInt yy
        d <- parseInt dd
        m <- parseInt mm
        tt $ yearMonthDay y m d
      _ -> Nothing
  }

rulePeriodicHolidays :: [Rule]
rulePeriodicHolidays = mkRuleHolidays
  -- Fixed dates, year over year
  [ ( "Indian Arrival Day", "indian arrival day", monthDay 5 30 )
  , ( "Labour Day", "labour day", monthDay 6 19 )
  , ( "Spiritual Baptist Liberation Day", "spiritual baptist liberation day", monthDay 3 30 )

  -- Fixed day/week/month, year over year
  , ( "Father's Day", "father'?s?'? day", nthDOWOfMonth 3 7 6 )
  , ( "Mother's Day", "mother'?s?'? day", nthDOWOfMonth 2 7 5 )
  , ( "Thanksgiving Day", "thanks?giving( day)?", nthDOWOfMonth 4 4 11 )
  ]

ruleComputedHolidays :: [Rule]
ruleComputedHolidays = mkRuleHolidays
  [ ( "Hosay", "hosay", cycleNthAfter False TG.Day 9 muharram )
  ]

rules :: [Rule]
rules =
  [ ruleDDMM
  , ruleDDMMYYYY
  , ruleDDMMYYYYDot
  ]
  ++ ruleComputedHolidays
  ++ rulePeriodicHolidays


-- 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 OverloadedStrings #-}

module Duckling.Time.EN.US.Corpus
  ( allExamples
  ) where

import Data.String
import Prelude

import Duckling.Testing.Types hiding (examples)
import Duckling.Time.Corpus
import Duckling.TimeGrain.Types hiding (add)

allExamples :: [Example]
allExamples = concat
  [ examples (datetime (2013, 2, 15, 0, 0, 0) Day)
             [ "2/15"
             , "on 2/15"
             , "2 / 15"
             , "2-15"
             , "2 - 15"
             ]
  , examples (datetime (1974, 10, 31, 0, 0, 0) Day)
             [ "10/31/1974"
             , "10/31/74"
             , "10-31-74"
             , "10.31.1974"
             , "10 31 1974"
             ]
  , examples (datetime (2013, 4, 25, 16, 0, 0) Minute)
             [ "4/25 at 4:00pm"
             ]
  , examples (datetimeHoliday (2013, 11, 28, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving day"
             , "thanksgiving"
             , "thanksgiving 2013"
             , "this thanksgiving"
             , "next thanksgiving day"
             ]
  , examples (datetimeHoliday (2014, 11, 27, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving of next year"
             , "thanksgiving 2014"
             ]
  , examples (datetimeHoliday (2012, 11, 22, 0, 0, 0) Day "Thanksgiving Day")
             [ "last thanksgiving"
             , "thanksgiving day 2012"
             ]
  , examples (datetimeHoliday (2016, 11, 24, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving 2016"
             ]
  , examples (datetimeHoliday (2017, 11, 23, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving 2017"
             ]
  , examples (datetimeHoliday (2012, 11, 26, 0, 0, 0) Day "Cyber Monday")
             [ "last cyber monday"
             , "cyber monday 2012"
             ]
  , examples (datetimeHoliday (2017, 11, 27, 0, 0, 0) Day "Cyber Monday")
             [ "cyber monday 2017"
             ]
  , examples (datetimeHoliday (2013, 5, 27, 0, 0, 0) Day "Memorial Day")
             [ "memorial day"
             , "Next Memorial Day"
             , "decoration day"
             ]
  , examples (datetimeHoliday (2012, 5, 28, 0, 0, 0) Day "Memorial Day")
             [ "last memorial day"
             , "memorial day of last year"
             ]
  , examples (datetimeIntervalHoliday ((2013, 5, 24, 18, 0, 0), (2013, 5, 28, 0, 0, 0)) Hour "Memorial Day weekend")
             [ "memorial day week-end"
             ]
  , examples (datetimeHoliday (2013, 7, 4, 0, 0, 0) Day "Independence Day")
             [ "independence day"
             ]
  , examples (datetimeHoliday (2013, 11, 11, 0, 0, 0) Day "Veterans Day")
             [ "veterans day"
             , "veteran day"
             ]
  , examples (datetimeHoliday (2013, 5, 1, 0, 0, 0) Day "Loyalty Day")
             [ "law day"
             , "Lei Day"
             , "loyalty day"
             ]
  , examples (datetimeHoliday (2013, 2, 18, 0, 0, 0) Day "President's Day")
             [ "George Washington Day"
             , "washington's birthday"
             , "presidents' day"
             , "president day 2013"
             , "Daisy Gatson Bates Day"
             ]
  , examples (datetimeHoliday (2013, 2, 12, 0, 0, 0) Day "Lincoln's Birthday")
             [ "Lincolns birthday"
             , "Abraham Lincoln's birthday"
             , "Lincoln birthday"
             , "Lincolns' birthday"
             ]
  , examples (datetimeHoliday (2013, 6, 16, 0, 0, 0) Day "Father's Day")
             [ "Father's Day"
             ]
  , examples (datetimeHoliday (2012, 6, 17, 0, 0, 0) Day "Father's Day")
             [ "last fathers day"
             ]
  , examples (datetimeHoliday (1996, 6, 16, 0, 0, 0) Day "Father's Day")
             [ "fathers day 1996"
             ]
  , examples (datetimeHoliday (2019, 9, 8, 0, 0, 0) Day "National Grandparents Day")
             [ "national grandparents day 2019"
             ]
  , examples (datetimeHoliday (2018, 5, 11, 0, 0, 0) Day "Military Spouse Day")
             [ "Military Spouse day 2018"
             ]
  , examples (datetimeHoliday (2013, 5, 12, 0, 0, 0) Day "Mother's Day")
             [ "Mother's Day"
             , "next mothers day"
             ]
  , examples (datetimeHoliday (2012, 5, 13, 0, 0, 0) Day "Mother's Day")
             [ "last mothers day"
             ]
  , examples (datetimeHoliday (2014, 5, 11, 0, 0, 0) Day "Mother's Day")
             [ "mothers day 2014"
             ]
  , examples (datetimeHoliday (2013, 9, 2, 0, 0, 0) Day "Labor Day")
             [ "labor day"
             ]
  , examples (datetimeHoliday (2012, 9, 3, 0, 0, 0) Day "Labor Day")
             [ "labor day of last year"
             , "Labor Day 2012"
             ]
  , examples (datetimeIntervalHoliday ((2013, 8, 30, 18, 0, 0), (2013, 9, 3, 0, 0, 0)) Hour "Labor Day weekend")
             [ "labor day weekend"
             ]
  , examples (datetimeHoliday (2013, 2, 2, 0, 0, 0) Day "Groundhog Day")
             [ "Groundhog day"
             , "groundhogs day"
             ]
  , examples (datetimeHoliday (2011, 4, 15, 0, 0, 0) Day "Emancipation Day")
             [ "emancipation day 2011"
             ]
  , examples (datetimeHoliday (2012, 4, 16, 0, 0, 0) Day "Emancipation Day")
             [ "emancipation day 2012"
             ]
  , examples (datetimeHoliday (2017, 4, 17, 0, 0, 0) Day "Emancipation Day")
             [ "emancipation day 2017"
             ]
  , examples (datetimeHoliday (2011, 4, 18, 0, 0, 0) Day "Tax Day")
             [ "tax day 2011"
             , "tax day two years ago"
             ]
  , examples (datetimeHoliday (2012, 4, 17, 0, 0, 0) Day "Tax Day")
             [ "tax day 2012"
             , "tax day last year"
             ]
  , examples (datetimeHoliday (2013, 4, 15, 0, 0, 0) Day "Tax Day")
             [ "next tax day"
             , "tax day 2013"
             ]
  , examples (datetimeHoliday (2017, 4, 18, 0, 0, 0) Day "Tax Day")
             [ "tax day 2017"
             , "tax day in 4 years"
             ]
  , examples (datetimeHoliday (2013, 4, 10, 0, 0, 0) Day "Siblings Day")
             [ "siblings day"
             , "national sibling day"
             ]
  , examples (datetimeHoliday (2016, 4, 27, 0, 0, 0) Day "Administrative Professionals' Day")
             [ "administrative professionals' day 2016"
             , "administrative professionals day 2016"
             , "administrative professional day 2016"
             , "administrative professional's day of 2016"
             , "secretaries' day 2016"
             , "admins day 2016"
             ]
  , examples (datetimeHoliday (2010, 4, 21, 0, 0, 0) Day "Administrative Professionals' Day")
             [ "administrative professionals' day 2010"
             ]
  , examples (datetimeHoliday (2019, 4, 24, 0, 0, 0) Day "Administrative Professionals' Day")
             [ "administrative professionals' day 2019"
             ]
  , examples (datetimeIntervalHoliday ((2013, 4, 26, 0, 0, 0), (2013, 4, 29, 0, 0, 0)) Day "Global Youth Service Day")
             [ "national youth service day"
             ]
  , examples (datetimeIntervalHoliday ((2018, 5, 20, 0, 0, 0), (2018, 5, 27, 0, 0, 0)) Day "Emergency Medical Services Week")
             [ "ems week 2018"
             ]
  , examples (datetimeHoliday (2018, 5, 23, 0, 0, 0) Day "Emergency Medical Services for Children Day")
             [ "emsc day 2018"
             ]
  , examples (datetimeHoliday (2017, 3, 12, 0, 0, 0) Day "Daylight Saving Start Day")
             [ "daylight saving start day 2017"
             , "daylight saving start 2017"
             , "daylight savings start day 2017"
             , "daylight savings start 2017"
             ]
  , examples (datetimeHoliday (2017, 11, 5, 0, 0, 0) Day "Daylight Saving End Day")
             [ "daylight saving end day 2017"
             , "daylight saving end 2017"
             , "daylight savings end day 2017"
             , "daylight savings end 2017"
             ]
  , examples (datetimeHoliday (2008, 2, 5, 0, 0, 0) Day "Super Tuesday")
             [ "super tuesday 2008"
             , "giga Tuesday"
             , "mega giga Tuesday"
             , "Tsunami Tuesday in 2008"
             , "Super Duper Tuesday"
             ]
  , examples (datetimeHoliday (2012, 3, 6, 0, 0, 0) Day "Super Tuesday")
             [ "super tuesday 2012"
             , "last super tuesday"
             , "super tuesday last year"
             , "the second closest super tuesday to the third Sunday of 2015"
             ]
  , examples (datetimeHoliday (2016, 3, 1, 0, 0, 0) Day "Super Tuesday")
             [ "super tuesday 2016"
             , "next super tuesday"
             , "super tuesday"
             ]
  , examples (datetimeHoliday (2020, 3, 3, 0, 0, 0) Day "Super Tuesday")
             [ "super tuesday 2020"
             , "super tuesday in seven years"
             , "the first super tue. after 2019"
             , "the 2nd Super Tuesday after next year"
             , "the closest super tuesday to 2019"
             , "the closest super tuesday to March 6, 2019"
             ]
  , examples (datetimeHoliday (2004, 2, 3, 0, 0, 0) Day "Mini-Tuesday")
             [ "mini-tuesday"
             , "Mini - Tuesday 2004"
             , "mini tuesday nine yrs ago"
             ]
  , examples (datetimeHoliday (2004, 3, 2, 0, 0, 0) Day "Super Tuesday")
             [ "the closest super tuesday to mini-tuesday"
             ]
  , examples (datetimeHoliday (2000, 3, 7, 0, 0, 0) Day "Super Tuesday")
             [ "the second closest super tuesday to mini-tuesday"
             ]
  , examples (datetimeHoliday (2008, 2, 5, 0, 0, 0) Day "Super Tuesday")
             [ "the 3rd closest super tuesday to mini-tuesday"
             , "the first closest Super Tuesday to tax day 2006"
             ]
  ]


-- 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 #-}

module Duckling.Time.EN.US.Rules where

import Data.Maybe
import Prelude

import Duckling.Dimensions.Types
import Duckling.Numeral.Helpers (parseInt)
import Duckling.Regex.Types
import Duckling.Time.Computed
import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData (..))
import Duckling.Types
import qualified Duckling.Time.Types as TTime
import qualified Duckling.TimeGrain.Types as TG

ruleMMDD :: Rule
ruleMMDD = Rule
  { name = "mm/dd"
  , pattern =
    [ regex "(1[0-2]|0?[1-9])\\s?[/-]\\s?(3[01]|[12]\\d|0?[1-9])"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (mm:dd:_)):_) -> do
        m <- parseInt mm
        d <- parseInt dd
        tt $ monthDay m d
      _ -> Nothing
  }

ruleMMDDYYYY :: Rule
ruleMMDDYYYY = Rule
  { name = "mm/dd/yyyy"
  , pattern =
    [ regex "(1[0-2]|0?[1-9])[-/\\s](3[01]|[12]\\d|0?[1-9])[-/\\s](\\d{2,4})"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (mm:dd:yy:_)):_) -> do
        y <- parseInt yy
        m <- parseInt mm
        d <- parseInt dd
        tt $ yearMonthDay y m d
      _ -> Nothing
  }

-- Clashes with HHMMSS, hence only 4-digit years
ruleMMDDYYYYDot :: Rule
ruleMMDDYYYYDot = Rule
  { name = "mm.dd.yyyy"
  , pattern =
    [ regex "(1[0-2]|0?[1-9])\\.(3[01]|[12]\\d|0?[1-9])\\.(\\d{4})"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (mm:dd:yy:_)):_) -> do
        y <- parseInt yy
        m <- parseInt mm
        d <- parseInt dd
        tt $ yearMonthDay y m d
      _ -> Nothing
  }

ruleBackwardCompatibleHolidays :: [Rule]
ruleBackwardCompatibleHolidays = mkRuleHolidays
  [ ("Thanksgiving Day", "thanks?giving( day)?", nthDOWOfMonth 4 4 11)
  , ("Father's Day", "father'?s?'? day", nthDOWOfMonth 3 7 6)
  ]

rulePeriodicHolidays :: [Rule]
rulePeriodicHolidays = mkRuleHolidays
  -- Fixed dates, year over year
  [ ( "African Liberation Day", "african liberation day", monthDay 5 25 )
  , ( "Air Force Birthday", "air force birthday", monthDay 9 18 )
  , ( "Alaska Day", "alaska day", monthDay 10 18 )
  , ( "American Eagle Day", "american eagle day", monthDay 6 20 )
  , ( "Army Birthday", "army birthday", monthDay 6 14 )
  , ( "Bennington Battle Day", "bennington battle day", monthDay 8 16 )
  , ( "Bunker Hill Day", "bunker hill day", monthDay 6 17 )
  , ( "California Admission Day", "california admission day", monthDay 9 9 )
  , ( "Cinco de Mayo", "cinco de mayo", monthDay 5 5 )
  , ( "Citizenship Day", "citizenship day|i am an american day", monthDay 9 17 )
  , ( "Coast Guard Birthday", "coast guard (birth)?day", monthDay 8 4 )
  , ( "Colorado Day", "colorado day", monthDay 8 1 )
  , ( "Constitution Day and Citizenship Day", "constitution day and citizenship day", monthDay 9 17 )
  , ( "CÃ©sar ChÃ¡vez Day", "c[Ã©e]sar ch[Ã¡a]vez day", monthDay 3 31 )
  , ( "D-Day", "d\\-day", monthDay 6 6 )
  , ( "Day After Christmas Day", "day after christmas day", monthDay 12 26 )
  , ( "Elizabeth Peratrovich Day", "elizabeth peratrovich day", monthDay 2 16 )
  , ( "Evacuation Day", "evacuation day", monthDay 3 17 )
  , ( "Father Damien Day", "father damien day", monthDay 4 15 )
  , ( "Feast of Our Lady of Guadalupe", "feast of our lady of guadalupe", monthDay 12 12 )
  , ( "Flag Day", "flag day", monthDay 6 14 )
  , ( "Groundhog Day", "groundhogs? day", monthDay 2 2 )
  , ( "Harvey Milk Day", "harvey milk day", monthDay 5 22 )
  , ( "Inauguration Day", "inauguration day", monthDay 1 20 )
  , ( "Independence Day", "independence day", monthDay 7 4 )
  , ( "Juneteenth", "juneteenth", monthDay 6 19 )
  , ( "Kamehameha Day", "kamehameha day", monthDay 6 11 )
  , ( "Kansas Day", "kansas day", monthDay 1 29 )
  , ( "Kent State Shootings Remembrance", "kent state shootings remembrance", monthDay 5 4 )
  , ( "Loyalty Day", "l(aw|ei|oyalty) day", monthDay 5 1 )
  , ( "Leif Erikson Day", "leif erikson day", monthDay 10 9 )
  , ( "Lincoln's Birthday", "(abraham )?lincoln'?s?'? birthday", monthDay 2 12 )
  , ( "Linus Pauling Day", "linus pauling day", monthDay 2 28 )
  , ( "Lyndon Baines Johnson Day", "lyndon baines johnson day", monthDay 8 27 )
  , ( "Marine Corps Birthday", "marine corps (birth)?day", monthDay 11 10 )
  , ( "Maryland Day", "maryland day", monthDay 3 25 )
  , ( "National Aviation Day", "national aviation day", monthDay 8 19 )
  , ( "National Freedom Day", "national freedom day", monthDay 2 1 )
  , ( "National Guard Birthday", "national guard (birth)?day", monthDay 12 13 )
  , ( "National Korean War Veterans Armistice Day", "national korean war veterans armistice day", monthDay 7 27 )
  , ( "National Maritime Day", "national maritime day", monthDay 5 22 )
  , ( "National Missing Children's Day", "national missing children'?s day", monthDay 5 25 )
  , ( "National Nurses Day", "national nurses day", monthDay 5 6 )
  , ( "National Tartan Day", "national tartan day", monthDay 4 6 )
  , ( "Navy Birthday", "(u\\.?s\\.? )?navy (birth)?day", monthDay 10 13 )
  , ( "Oklahoma Day", "oklahoma day", monthDay 4 22 )
  , ( "Pan American Aviation Day", "pan american aviation day", monthDay 12 17 )
  , ( "Pascua Florida Day", "pascua florida day", monthDay 4 2 )
  , ( "Patriot Day", "patriot day", monthDay 9 11 )
  , ( "Peace Officers Memorial Day", "peace officers memorial day", monthDay 5 15 )
  , ( "Pearl Harbor Remembrance Day", "pearl harbor remembrance day", monthDay 12 7 )
  , ( "Pioneer Day", "pioneer day", monthDay 7 24 )
  , ( "Prince Jonah Kuhio Kalanianaole Day", "prince jonah kuhio kalanianaole day", monthDay 3 26 )
  , ( "Purple Heart Day", "purple heart day", monthDay 8 7 )
  , ( "Read Across America Day", "read across america day", monthDay 3 2 )
  , ( "Rhode Island Independence Day", "rhode island independence day", monthDay 5 4 )
  , ( "Rosa Parks Day", "rosa parks day", monthDay 2 4 )
  , ( "San Jacinto Day", "san jacinto day", monthDay 4 21 )
  , ( "Self-Injury Awareness Day", "self\\-injury awareness day", monthDay 3 1 )
  , ( "Senior Citizens Day", "senior citizens day", monthDay 8 21 )
  , ( "Siblings Day", "(national )?sibling'?s?'? day", monthDay 4 10 )
  , ( "St Nicholas' Day", "st\\.? nicholas'? day", monthDay 12 6 )
  , ( "St. David's Day", "st\\.? david'?s day", monthDay 3 1 )
  , ( "Statehood Day", "statehood day", monthDay 6 1 )
  , ( "Statehood Day in Arizona", "statehood day in arizona", monthDay 2 14 )
  , ( "Stephen Foster Memorial Day", "stephen foster memorial day", monthDay 1 13 )
  , ( "Susan B Anthony's Birthday", "susan b\\.? anthony'?s birthday", monthDay 2 15 )
  , ( "Texas Independence Day", "texas independence day", monthDay 3 2 )
  , ( "Thomas Jefferson's Birthday", "thomas jefferson'?s birthday", monthDay 4 13 )
  , ( "Truman Day", "truman day", monthDay 5 8 )
  , ( "Veterans Day", "veterans? day", monthDay 11 11 )
  , ( "West Virginia Day", "west virginia day", monthDay 6 20 )
  , ( "White Cane Safety Day", "white cane safety day", monthDay 10 15 )
  , ( "Women's Equality Day", "women'?s equality day", monthDay 8 26 )
  , ( "Wright Brothers Day", "wright brothers day", monthDay 12 17 )

  -- Fixed day/week/month, year over year
  , ( "Arbor Day", "arbor day", predLastOf (dayOfWeek 5) (month 4) )
  , ( "Armed Forces Day", "armed forces day", nthDOWOfMonth 3 6 5 )
  , ( "Casimir Pulaski Day", "casimir pulaski day", nthDOWOfMonth 1 1 3 )
  , ( "Child Health Day", "child health day", nthDOWOfMonth 1 1 10 )
  , ( "Columbus Day", "columbus day", nthDOWOfMonth 2 1 10 )
  , ( "Daylight Saving Start Day", "daylight savings? start( day)?", nthDOWOfMonth 2 7 3 )
  , ( "Daylight Saving End Day", "daylight savings? end( day)?", nthDOWOfMonth 1 7 11 )

  -- Saturday after Labor Day
  , ( "Carl Garner Federal Lands Cleanup Day"
    , "carl garner federal lands cleanup day"
    , cycleNthAfter False TG.Day 5 $ nthDOWOfMonth 1 1 9 )
  -- Monday after Thanksgiving
  , ( "Cyber Monday", "cyber monday"
    , cycleNthAfter False TG.Day 4 $ nthDOWOfMonth 4 4 11 )
  , ( "Election Day", "election day"
    , cycleNthAfter False TG.Day 1 $ nthDOWOfMonth 1 1 11 )
  , ( "Employee Appreciation Day", "employee appreciation day"
    , nthDOWOfMonth 1 5 3 )
  , ( "Friendship Day", "friendship day", nthDOWOfMonth 1 7 8 )
  , ( "Gold Star Mother's Day", "gold star mother's day"
    , predLastOf (dayOfWeek 7) (month 9) )
  , ( "Indigenous People's Day", "indigenous people's day"
    , nthDOWOfMonth 2 1 10 )
  , ( "Labor Day", "labor day", nthDOWOfMonth 1 1 9 )
  -- Long weekend before the first Monday of September
  , ( "Labor Day weekend", "labor day week(\\s|-)?ends?"
    , longWEBefore $ nthDOWOfMonth 1 1 9
    )
  , ( "Lee Jackson Day", "lee jackson day", nthDOWOfMonth 2 5 1 )
  -- Last Monday of May
  , ( "Memorial Day", "(decoration|memorial) day"
    , predLastOf (dayOfWeek 1) (month 5) )
  -- Long weekend before the last Monday of May
  , ( "Memorial Day weekend", "(decoration|memorial) day week(\\s|-)?ends?"
    , longWEBefore $ predLastOf (dayOfWeek 1) (month 5) )
  -- 2 days before Mother's Day
  , ( "Military Spouse Day", "military spouse (appreciation )?day"
    , cycleNthAfter False TG.Day (- 2) $ nthDOWOfMonth 2 7 5 )
  , ( "Mother's Day", "mother'?s?'? day", nthDOWOfMonth 2 7 5 )
  , ( "National CleanUp Day", "national clean\\-?up day", nthDOWOfMonth 3 6 9 )
  , ( "National Day of Prayer", "national day of prayer", nthDOWOfMonth 1 4 5 )
  , ( "National Defense Transportation Day"
    , "national defense transportation day"
    , nthDOWOfMonth 3 5 5 )
  , ( "National Explosive Ordnance Disposal Day"
    , "national (eod|explosive ordnance disosal) day"
    , nthDOWOfMonth 1 6 5 )
  -- First Sunday after Labor Day
  , ( "National Grandparents Day", "national grandparents day"
    , cycleNthAfter False TG.Day 6 $ nthDOWOfMonth 1 1 9 )
  , ( "National POW/MIA Recognition Day", "national pow/mia recognition day"
    , nthDOWOfMonth 3 5 9 )
  , ( "National Wear Red Day", "national wear red day", nthDOWOfMonth 1 5 2 )
  -- Day after Thanksgiving
  , ( "Native American Heritage Day"
    , "(american indian|native american) heritage day"
    , cycleNthAfter False TG.Day 1 $ nthDOWOfMonth 4 4 11 )
  , ( "Native Americans' Day", "native americans' day", nthDOWOfMonth 4 1 9 )
  , ( "Nevada Day", "nevada day", predLastOf (dayOfWeek 5) (month 10) )
  , ( "Parents' Day", "parents' day", nthDOWOfMonth 4 7 7 )
  , ( "Patriots' Day", "patriot'?s'? day", nthDOWOfMonth 3 1 4 )
  , ( "Robert E. Lee Day", "robert e\\. lee day|lee's (birth)?day"
    , nthDOWOfMonth 3 1 1 )
  , ( "Seward's Day", "seward's day", predLastOf (dayOfWeek 1) (month 3) )
  , ( "Statehood Day", "(admission|statehood) day", nthDOWOfMonth 3 5 8 )
  , ( "Sweetest Day", "sweetest day", nthDOWOfMonth 3 6 10 )
  , ( "Take our Daughters and Sons to Work Day"
    , "take our daughters and sons to work day", nthDOWOfMonth 4 4 4 )
  , ( "Town Meeting Day", "town meeting day", nthDOWOfMonth 1 2 3 )
  , ( "Victory Day", "victory day", nthDOWOfMonth 2 1 8 )
  , ( "President's Day"
    , "(george )?washington'?s? (birth)?day|president'?s?'? day|daisy gatson bates'? day"
    , nthDOWOfMonth 3 1 2
    )

  -- Wednesday of the last full week of April, where a full week starts on
  -- Sunday and ends on Saturday.
  , ( "Administrative Professionals' Day"
    , "(administrative professional|secretarie|admin)('?s'?)? day"
    , cycleNthAfter False TG.Day (-3) $
        predNthAfter (-1) (dayOfWeek 6) (monthDay 5 1) )
  -- Wednesday of the 3rd full week in May, starting on a Sunday
  , ( "Emergency Medical Services for Children Day"
    , "(national )?(emsc|emergency medical services for children) day"
    , cycleNthAfter False TG.Day 3 $ predNthAfter 2 (dayOfWeek 7) (monthDay 5 1)
    )

  -- Other
  , ( "Emancipation Day", "emancipation day"
    , predNthClosest 0 weekday $ monthDay 4 16 )
  ]

rulePeriodicHolidays' :: [Rule]
rulePeriodicHolidays' = mkRuleHolidays'
  -- Fixed dates, year over year
  [ ( "Kwanzaa", "kwanzaa", interval TTime.Open (monthDay 12 26) (monthDay 1 1) )

  -- 3rd full week in May, starting on a Sunday
  , ( "Emergency Medical Services Week"
    , "(national )?(ems|emergency medical services) week"
    , let start = predNthAfter 2 (dayOfWeek 7) (monthDay 5 1)
          end = cycleNthAfter False TG.Day 6 start
      in interval TTime.Open start end )

  -- Other
  -- First weekday on or after April 15 if different than Emancipation Day
  -- Otherwise, first weekday following Emancipation Day
  , ( "Tax Day", "tax day"
    , let emancipationDay = predNthClosest 0 weekday $ monthDay 4 16
          tentative = predNthAfter 0 weekday $ monthDay 4 15
          alternative = predNthAfter 1 weekday emancipationDay
      in intersectWithReplacement emancipationDay tentative alternative )
  ]

-- duplicating "Tuesday" regex as we lost the internal info
tuesday :: String
tuesday = "(tuesdays?|tue?\\.?)"

ruleComputedHolidays :: [Rule]
ruleComputedHolidays = mkRuleHolidays
  [ ( "Super Tuesday", "super\\s+" ++ tuesday, superTuesday )
  , ( "Mini-Tuesday"
    , "mini(\\s*\\-\\s*|\\s+)" ++ tuesday
    , yearMonthDay 2004 2 3
    )
  , ( "Super Tuesday"
    , "((mega\\s+)?giga|tsunami|super\\s+duper)\\s+" ++ tuesday
    , yearMonthDay 2008 2 5
    )
  ]

ruleComputedHolidays' :: [Rule]
ruleComputedHolidays' = mkRuleHolidays'
  [ ( "Global Youth Service Day", "national youth service day"
    , let start = globalYouthServiceDay
          end = cycleNthAfter False TG.Day 2 globalYouthServiceDay
        in interval TTime.Open start end )
  ]

rulesBackwardCompatible :: [Rule]
rulesBackwardCompatible =
  [ ruleMMDD
  , ruleMMDDYYYY
  , ruleMMDDYYYYDot
  ]
  ++ ruleBackwardCompatibleHolidays

rules :: [Rule]
rules = rulesBackwardCompatible
  ++ ruleComputedHolidays
  ++ ruleComputedHolidays'
  ++ rulePeriodicHolidays
  ++ rulePeriodicHolidays'


-- 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 OverloadedStrings #-}

module Duckling.Time.EN.ZA.Corpus
  ( allExamples
  ) where

import Data.String
import Prelude

import Duckling.Testing.Types hiding (examples)
import Duckling.Time.Corpus
import Duckling.Time.Types hiding (Month)
import Duckling.TimeGrain.Types hiding (add)

allExamples :: [Example]
allExamples = concat
  [ examples (datetime (2013, 2, 15, 0, 0, 0) Day)
             [ "2/15"
             , "on 2/15"
             , "2 / 15"
             , "2-15"
             , "2 - 15"
             ]
  , examples (datetime (1974, 10, 31, 0, 0, 0) Day)
             [ "31/10/1974"
             , "31/10/74"
             , "31-10-74"
             , "31.10.1974"
             , "31 10 1974"
             ]
  , examples (datetime (2013, 4, 25, 16, 0, 0) Minute)
             [ "4/25 at 4:00pm"
             ]
  , examples (datetimeHoliday (2013, 11, 28, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving day"
             , "thanksgiving"
             , "thanksgiving 2013"
             , "this thanksgiving"
             , "next thanksgiving day"
             ]
  , examples (datetimeHoliday (2014, 11, 27, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving of next year"
             , "thanksgiving 2014"
             ]
  , examples (datetimeHoliday (2012, 11, 22, 0, 0, 0) Day "Thanksgiving Day")
             [ "last thanksgiving"
             , "thanksgiving day 2012"
             ]
  , examples (datetimeHoliday (2016, 11, 24, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving 2016"
             ]
  , examples (datetimeHoliday (2017, 11, 23, 0, 0, 0) Day "Thanksgiving Day")
             [ "thanksgiving 2017"
             ]
  , examples (datetimeHoliday (2013, 12, 16, 0, 0, 0) Day "Day of Reconciliation")
             [ "day of the vow"
             , "day of reconciliation"
             , "day of the covenant"
             ]
  , examples (datetimeIntervalHoliday ((2013, 9, 1, 0, 0, 0), (2013, 9, 8, 0, 0, 0)) Day "National Arbor Week")
             [ "national arbor week"
             ]
  , examples (datetimeHoliday (2013, 6, 16, 0, 0, 0) Day "Father's Day")
             [ "Father's Day"
             ]
  , examples (datetimeHoliday (2012, 6, 17, 0, 0, 0) Day "Father's Day")
             [ "last fathers day"
             ]
  , examples (datetimeHoliday (1996, 6, 16, 0, 0, 0) Day "Father's Day")
             [ "fathers day 1996"
             ]
  , examples (datetimeHoliday (2013, 5, 12, 0, 0, 0) Day "Mother's Day")
             [ "Mother's Day"
             , "next mothers day"
             ]
  , examples (datetimeHoliday (2012, 5, 13, 0, 0, 0) Day "Mother's Day")
             [ "last mothers day"
             ]
  , examples (datetimeHoliday (2014, 5, 11, 0, 0, 0) Day "Mother's Day")
             [ "mothers day 2014"
             ]
  , examples (datetimeHoliday (2013, 5, 1, 0, 0, 0) Day "Labour Day")
             [ "labour day"
             ]
  , examples (datetimeHoliday (2012, 5, 1, 0, 0, 0) Day "Labour Day")
             [ "labour day of last year"
             , "Labour Day 2012"
             ]
  , examples (datetimeHoliday (2013, 10, 10, 0, 0, 0) Day "Heroes' Day")
             [ "heroes' day"
             , "kruger day"
             ]
  , examples (datetimeHoliday (2013, 9, 4, 0, 0, 0) Day "Administrative Professionals' Day")
             [ "admin day"
             ]
  ]


-- 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 #-}

module Duckling.Time.EN.ZA.Rules
  ( rules
  ) where

import Data.Maybe
import Prelude

import Duckling.Dimensions.Types
import Duckling.Numeral.Helpers (parseInt)
import Duckling.Regex.Types
import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData (..))
import Duckling.Types
import qualified Duckling.Time.Types as TTime

ruleMMDD :: Rule
ruleMMDD = Rule
  { name = "mm/dd"
  , pattern =
    [ regex "(1[0-2]|0?[1-9])\\s?[/-]\\s?(3[01]|[12]\\d|0?[1-9])"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (mm:dd:_)):_) -> do
        m <- parseInt mm
        d <- parseInt dd
        tt $ monthDay m d
      _ -> Nothing
  }

ruleDDMMYYYY :: Rule
ruleDDMMYYYY = Rule
  { name = "dd/mm/yyyy"
  , pattern =
    [ regex "(3[01]|[12]\\d|0?[1-9])[-/\\s](1[0-2]|0?[1-9])[-/\\s](\\d{2,4})"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (dd:mm:yy:_)):_) -> do
        y <- parseInt yy
        d <- parseInt dd
        m <- parseInt mm
        tt $ yearMonthDay y m d
      _ -> Nothing
  }

-- Clashes with HHMMSS, hence only 4-digit years
ruleDDMMYYYYDot :: Rule
ruleDDMMYYYYDot = Rule
  { name = "dd.mm.yyyy"
  , pattern =
    [ regex "(3[01]|[12]\\d|0?[1-9])\\.(1[0-2]|0?[1-9])\\.(\\d{4})"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (dd:mm:yy:_)):_) -> do
        y <- parseInt yy
        d <- parseInt dd
        m <- parseInt mm
        tt $ yearMonthDay y m d
      _ -> Nothing
  }

rulePeriodicHolidays :: [Rule]
rulePeriodicHolidays = mkRuleHolidays
  -- Fixed dates, year over year
  [ ( "Day of Goodwill", "day of goodwill", monthDay 12 26 )
  , ( "Day of Reconciliation", "day of( the)? (covenant|reconciliation|vow)", monthDay 12 16 )
  , ( "Heritage Day", "heritage day", monthDay 9 24 )
  , ( "Heroes' Day", "(heroes'|kruger) day", monthDay 10 10 )
  , ( "Labour Day", "labour day", monthDay 5 1 )
  , ( "National Women's Day", "national women'?s day", monthDay 8 9 )
  , ( "Workers' Day", "workers'? day", monthDay 5 1 )

  -- Fixed day/week/month, year over year
  , ( "Administrative Professionals' Day"
    , "(administrative professional|secretarie|admin)('?s'?)? day"
    , nthDOWOfMonth 1 3 9 )
  , ( "Father's Day", "father'?s?'? day", nthDOWOfMonth 3 7 6 )
  , ( "Mother's Day", "mother'?s?'? day", nthDOWOfMonth 2 7 5 )
  , ( "Thanksgiving Day", "thanks?giving( day)?", nthDOWOfMonth 4 4 11 )
  ]

rulePeriodicHolidays' :: [Rule]
rulePeriodicHolidays' = mkRuleHolidays'
  -- Fixed dates, year over year
  [ ( "National Arbor Week", "national arbor week"
    , interval TTime.Open (monthDay 9 1) (monthDay 9 7) )
  ]

rules :: [Rule]
rules =
  [ ruleMMDD
  , ruleDDMMYYYY
  , ruleDDMMYYYYDot
  ]
  ++ rulePeriodicHolidays
  ++ rulePeriodicHolidays'