Uses correct date format for all EN locales

Summary: The date format changes between EN locales (https://en.wikipedia.org/wiki/Date_format_by_country). This diff fixes how dates are handled in each locale.

Reviewed By: patapizza

Differential Revision: D6156147

fbshipit-source-id: 22f296c
This commit is contained in:
Sam Pepose 2017-10-26 08:39:53 -07:00 committed by Facebook Github Bot
parent df6484945a
commit 251028e691
31 changed files with 21974 additions and 3 deletions

View File

@ -69,13 +69,22 @@ instance TextShow Lang where
-- | ISO 3166-1 alpha-2 Country code (includes regions and territories).
-- See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
data Region
= CA
= AU
| BZ
| CA
| CN
| GB
| HK
| IE
| IN
| JM
| MO
| NZ
| PH
| TT
| TW
| US
| ZA
deriving (Bounded, Enum, Eq, Generic, Hashable, Ord, Read, Show)
instance TextShow Region where
@ -101,6 +110,6 @@ makeLocale lang (Just region)
allLocales :: HashMap Lang (HashSet Region)
allLocales = HashMap.fromList
[ (EN, HashSet.fromList [CA, GB, US])
[ (EN, HashSet.fromList [AU, BZ, CA, GB, IN, IE, JM, NZ, PH, ZA, TT, US])
, (ZH, HashSet.fromList [CN, HK, MO, TW])
]

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -29,9 +29,18 @@ import qualified Duckling.Ordinal.EN.Rules as Ordinal
import qualified Duckling.Quantity.EN.Rules as Quantity
import qualified Duckling.Temperature.EN.Rules as Temperature
import qualified Duckling.Time.EN.Rules as Time
import qualified Duckling.Time.EN.AU.Rules as TimeAU
import qualified Duckling.Time.EN.BZ.Rules as TimeBZ
import qualified Duckling.Time.EN.CA.Rules as TimeCA
import qualified Duckling.Time.EN.GB.Rules as TimeGB
import qualified Duckling.Time.EN.IE.Rules as TimeIE
import qualified Duckling.Time.EN.IN.Rules as TimeIN
import qualified Duckling.Time.EN.JM.Rules as TimeJM
import qualified Duckling.Time.EN.NZ.Rules as TimeNZ
import qualified Duckling.Time.EN.PH.Rules as TimePH
import qualified Duckling.Time.EN.TT.Rules as TimeTT
import qualified Duckling.Time.EN.US.Rules as TimeUS
import qualified Duckling.Time.EN.ZA.Rules as TimeZA
import qualified Duckling.TimeGrain.EN.Rules as TimeGrain
import qualified Duckling.Volume.EN.Rules as Volume
@ -44,9 +53,18 @@ defaultRules dim@(This Time) =
defaultRules dim = langRules dim
localeRules :: Region -> Some Dimension -> [Rule]
localeRules AU (This Time) = TimeAU.rules
localeRules BZ (This Time) = TimeBZ.rules
localeRules CA (This Time) = TimeCA.rules
localeRules GB (This Time) = TimeGB.rules
localeRules IE (This Time) = TimeIE.rules
localeRules IN (This Time) = TimeIN.rules
localeRules JM (This Time) = TimeJM.rules
localeRules NZ (This Time) = TimeNZ.rules
localeRules PH (This Time) = TimePH.rules
localeRules TT (This Time) = TimeTT.rules
localeRules US (This Time) = TimeUS.rules
localeRules ZA (This Time) = TimeZA.rules
localeRules _ _ = []
langRules :: Some Dimension -> [Rule]

View File

@ -0,0 +1,43 @@
-- 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. An additional grant
-- of patent rights can be found in the PATENTS file in the same directory.
{-# LANGUAGE OverloadedStrings #-}
module Duckling.Time.EN.AU.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"
]
, 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"
]
]

View File

@ -0,0 +1,60 @@
-- 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. An additional grant
-- of patent rights can be found in the PATENTS file in the same directory.
{-# 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.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])[/-](1[0-2]|0?[1-9])[-/](\\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
}
rules :: [Rule]
rules =
[ ruleDDMM
, ruleDDMMYYYY
]

View File

@ -0,0 +1,43 @@
-- 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. An additional grant
-- of patent rights can be found in the PATENTS file in the same directory.
{-# 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"
]
, 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"
]
]

View File

@ -0,0 +1,61 @@
-- 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. An additional grant
-- of patent rights can be found in the PATENTS file in the same directory.
{-# 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])[/-](1[0-2]|0?[1-9])[-/](\\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
}
rules :: [Rule]
rules =
[ ruleDDMM
, ruleDDMMYYYY
]

View File

@ -0,0 +1,43 @@
-- 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. An additional grant
-- of patent rights can be found in the PATENTS file in the same directory.
{-# 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"
]
, 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"
]
]

View File

@ -0,0 +1,60 @@
-- 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. An additional grant
-- of patent rights can be found in the PATENTS file in the same directory.
{-# 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])[/-](1[0-2]|0?[1-9])[-/](\\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
}
rules :: [Rule]
rules =
[ ruleDDMM
, ruleDDMMYYYY
]

View File

@ -0,0 +1,43 @@
-- 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. An additional grant
-- of patent rights can be found in the PATENTS file in the same directory.
{-# 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"
]
, 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"
]
]

View File

@ -0,0 +1,60 @@
-- 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. An additional grant
-- of patent rights can be found in the PATENTS file in the same directory.
{-# 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.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])[/-](1[0-2]|0?[1-9])[-/](\\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
}
rules :: [Rule]
rules =
[ ruleDDMM
, ruleDDMMYYYY
]

View File

@ -0,0 +1,43 @@
-- 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. An additional grant
-- of patent rights can be found in the PATENTS file in the same directory.
{-# 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"
]
, 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"
]
]

View File

@ -0,0 +1,60 @@
-- 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. An additional grant
-- of patent rights can be found in the PATENTS file in the same directory.
{-# 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])[/-](1[0-2]|0?[1-9])[-/](\\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
}
rules :: [Rule]
rules =
[ ruleDDMM
, ruleDDMMYYYY
]

View File

@ -0,0 +1,43 @@
-- 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. An additional grant
-- of patent rights can be found in the PATENTS file in the same directory.
{-# 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"
]
, 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"
]
]

View File

@ -0,0 +1,60 @@
-- 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. An additional grant
-- of patent rights can be found in the PATENTS file in the same directory.
{-# 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.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])[/-](1[0-2]|0?[1-9])[-/](\\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
}
rules :: [Rule]
rules =
[ ruleDDMM
, ruleDDMMYYYY
]

View File

@ -0,0 +1,39 @@
-- 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. An additional grant
-- of patent rights can be found in the PATENTS file in the same directory.
{-# 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"
]
, examples (datetime (2013, 4, 25, 16, 0, 0) Minute)
[ "4/25 at 4:00pm"
]
]

View File

@ -0,0 +1,60 @@
-- 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. An additional grant
-- of patent rights can be found in the PATENTS file in the same directory.
{-# 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])[/-](3[01]|[12]\\d|0?[1-9])[-/](\\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
}
rules :: [Rule]
rules =
[ ruleMMDD
, ruleMMDDYYYY
]

View File

@ -0,0 +1,43 @@
-- 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. An additional grant
-- of patent rights can be found in the PATENTS file in the same directory.
{-# 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.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"
]
, 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"
]
]

View File

@ -0,0 +1,60 @@
-- 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. An additional grant
-- of patent rights can be found in the PATENTS file in the same directory.
{-# 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.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])[/-](1[0-2]|0?[1-9])[-/](\\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
}
rules :: [Rule]
rules =
[ ruleDDMM
, ruleDDMMYYYY
]

View File

@ -0,0 +1,39 @@
-- 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. An additional grant
-- of patent rights can be found in the PATENTS file in the same directory.
{-# 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"
]
, examples (datetime (2013, 4, 25, 16, 0, 0) Minute)
[ "4/25 at 4:00pm"
]
]

View File

@ -0,0 +1,60 @@
-- 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. An additional grant
-- of patent rights can be found in the PATENTS file in the same directory.
{-# 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
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])[/-](1[0-2]|0?[1-9])[-/](\\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
}
rules :: [Rule]
rules =
[ ruleMMDD
, ruleDDMMYYYY
]

View File

@ -439,12 +439,30 @@ library
, Duckling.Time.DE.Rules
, Duckling.Time.EN.Corpus
, Duckling.Time.EN.Rules
, Duckling.Time.EN.AU.Corpus
, Duckling.Time.EN.AU.Rules
, Duckling.Time.EN.BZ.Corpus
, Duckling.Time.EN.BZ.Rules
, Duckling.Time.EN.CA.Corpus
, Duckling.Time.EN.CA.Rules
, Duckling.Time.EN.GB.Corpus
, Duckling.Time.EN.GB.Rules
, Duckling.Time.EN.IE.Corpus
, Duckling.Time.EN.IE.Rules
, Duckling.Time.EN.IN.Corpus
, Duckling.Time.EN.IN.Rules
, Duckling.Time.EN.JM.Corpus
, Duckling.Time.EN.JM.Rules
, Duckling.Time.EN.NZ.Corpus
, Duckling.Time.EN.NZ.Rules
, Duckling.Time.EN.PH.Corpus
, Duckling.Time.EN.PH.Rules
, Duckling.Time.EN.TT.Corpus
, Duckling.Time.EN.TT.Rules
, Duckling.Time.EN.US.Corpus
, Duckling.Time.EN.US.Rules
, Duckling.Time.EN.ZA.Corpus
, Duckling.Time.EN.ZA.Rules
, Duckling.Time.ES.Corpus
, Duckling.Time.ES.Rules
, Duckling.Time.FR.Corpus

View File

@ -29,9 +29,18 @@ import Duckling.Testing.Types hiding (examples)
import Duckling.Time.Corpus
import Duckling.Time.EN.Corpus
import Duckling.TimeGrain.Types (Grain(..))
import qualified Duckling.Time.EN.AU.Corpus as AU
import qualified Duckling.Time.EN.BZ.Corpus as BZ
import qualified Duckling.Time.EN.CA.Corpus as CA
import qualified Duckling.Time.EN.GB.Corpus as GB
import qualified Duckling.Time.EN.IE.Corpus as IE
import qualified Duckling.Time.EN.IN.Corpus as IN
import qualified Duckling.Time.EN.JM.Corpus as JM
import qualified Duckling.Time.EN.NZ.Corpus as NZ
import qualified Duckling.Time.EN.PH.Corpus as PH
import qualified Duckling.Time.EN.TT.Corpus as TT
import qualified Duckling.Time.EN.US.Corpus as US
import qualified Duckling.Time.EN.ZA.Corpus as ZA
tests :: TestTree
tests = testGroup "EN Tests"
@ -45,7 +54,15 @@ tests = testGroup "EN Tests"
localeTests :: TestTree
localeTests = testGroup "Locale Tests"
[ testGroup "EN_CA Tests"
[ testGroup "EN_AU Tests"
[ makeCorpusTest [This Time] $ withLocale corpus localeAU AU.allExamples
, makeNegativeCorpusTest [This Time] $ withLocale negativeCorpus localeAU []
]
, testGroup "EN_BZ Tests"
[ makeCorpusTest [This Time] $ withLocale corpus localeBZ BZ.allExamples
, makeNegativeCorpusTest [This Time] $ withLocale negativeCorpus localeBZ []
]
, testGroup "EN_CA Tests"
[ makeCorpusTest [This Time] $ withLocale corpus localeCA CA.allExamples
, makeNegativeCorpusTest [This Time] $ withLocale negativeCorpus localeCA []
]
@ -53,15 +70,52 @@ localeTests = testGroup "Locale Tests"
[ makeCorpusTest [This Time] $ withLocale corpus localeGB GB.allExamples
, makeNegativeCorpusTest [This Time] $ withLocale negativeCorpus localeGB []
]
, testGroup "EN_IE Tests"
[ makeCorpusTest [This Time] $ withLocale corpus localeIE IE.allExamples
, makeNegativeCorpusTest [This Time] $ withLocale negativeCorpus localeIE []
]
, testGroup "EN_IN Tests"
[ makeCorpusTest [This Time] $ withLocale corpus localeIN IN.allExamples
, makeNegativeCorpusTest [This Time] $ withLocale negativeCorpus localeIN []
]
, testGroup "EN_JM Tests"
[ makeCorpusTest [This Time] $ withLocale corpus localeJM JM.allExamples
, makeNegativeCorpusTest [This Time] $ withLocale negativeCorpus localeJM []
]
, testGroup "EN_NZ Tests"
[ makeCorpusTest [This Time] $ withLocale corpus localeNZ NZ.allExamples
, makeNegativeCorpusTest [This Time] $ withLocale negativeCorpus localeNZ []
]
, testGroup "EN_PH Tests"
[ makeCorpusTest [This Time] $ withLocale corpus localePH PH.allExamples
, makeNegativeCorpusTest [This Time] $ withLocale negativeCorpus localePH []
]
, testGroup "EN_TT Tests"
[ makeCorpusTest [This Time] $ withLocale corpus localeTT TT.allExamples
, makeNegativeCorpusTest [This Time] $ withLocale negativeCorpus localeTT []
]
, testGroup "EN_US Tests"
[ makeCorpusTest [This Time] $ withLocale corpus localeUS US.allExamples
, makeNegativeCorpusTest [This Time] $ withLocale negativeCorpus localeUS []
]
, testGroup "EN_ZA Tests"
[ makeCorpusTest [This Time] $ withLocale corpus localeZA ZA.allExamples
, makeNegativeCorpusTest [This Time] $ withLocale negativeCorpus localeZA []
]
]
where
localeAU = makeLocale EN $ Just AU
localeBZ = makeLocale EN $ Just BZ
localeCA = makeLocale EN $ Just CA
localeGB = makeLocale EN $ Just GB
localeIE = makeLocale EN $ Just IE
localeIN = makeLocale EN $ Just IN
localeJM = makeLocale EN $ Just JM
localeNZ = makeLocale EN $ Just NZ
localePH = makeLocale EN $ Just PH
localeTT = makeLocale EN $ Just TT
localeUS = makeLocale EN $ Just US
localeZA = makeLocale EN $ Just ZA
exactSecondTests :: TestTree
exactSecondTests = testCase "Exact Second Tests" $