@@ -13,7 +13,9 @@ import Control.Lazy as Lazy
1313import Data.Array as A
1414import Data.Bifunctor (lmap )
1515import Data.Const (Const (..))
16+ import Data.DateTime as DT
1617import Data.Either (Either (..))
18+ import Data.Enum (toEnum )
1719import Data.Foldable (elem )
1820import Data.Functor.Compose (Compose (..))
1921import Data.HugeNum as HN
@@ -291,19 +293,19 @@ inlines = L.many inline2 <* PS.eof
291293 M.Nothing →
292294 pure $ Left case template of
293295 SD.DateTime SD.Minutes _ →
294- " Incorrect datetime default value, please use \" YYYY-MM-DD HH:mm \" or \" YYYY-MM-DDTHH :mm\" format"
296+ " Invalid datetime default value, please use \" YYYY-MM-DD HH:mm\" format"
295297 SD.DateTime SD.Seconds _ →
296- " Incorrect datetime default value, please use \" YYYY-MM-DD HH:mm:ss \" or \" YYYY-MM-DDTHH :mm:ss\" format"
298+ " Invalid datetime default value, please use \" YYYY-MM-DD HH:mm:ss\" format"
297299 SD.Date _ →
298- " Incorrect date default value, please use \" YYYY-MM-DD\" format"
300+ " Invalid date default value, please use \" YYYY-MM-DD\" format"
299301 SD.Time SD.Minutes _ →
300- " Incorrect time default value, please use \" HH:mm\" format"
302+ " Invalid time default value, please use \" HH:mm\" format"
301303 SD.Time SD.Seconds _ →
302- " Incorrect time default value, please use \" HH:mm:ss\" format"
304+ " Invalid time default value, please use \" HH:mm:ss\" format"
303305 SD.Numeric _ →
304- " Incorrect numeric default value"
306+ " Invalid numeric default value"
305307 SD.PlainText _ →
306- " Incorrect default value"
308+ " Invalid default value"
307309
308310 parseTextBoxTemplate ∷ P.Parser String (SD.TextBox (Const Unit ))
309311 parseTextBoxTemplate =
@@ -419,28 +421,33 @@ parseTextBox isPlainText eta template =
419421 SD.PlainText _ → SD.PlainText <$> eta parsePlainTextValue
420422
421423 where
424+ parseDateTimeValue ∷ SD.TimePrecision → P.Parser String DT.DateTime
422425 parseDateTimeValue prec = do
423426 date ← parseDateValue
424427 (PC .try $ void $ PS .string " T" ) <|> PU .skipSpaces
425428 time ← parseTimeValue prec
426- pure { date, time }
429+ pure $ DT.DateTime date time
427430
431+ parseDateValue ∷ P.Parser String DT.Date
428432 parseDateValue = do
429433 year ← parseYear
430434 PU .skipSpaces *> dash *> PU .skipSpaces
431435 month ← natural
432- when (month > 12 ) $ P .fail " Incorrect month"
436+ when (month > 12 ) $ P .fail " Invalid month"
433437 PU .skipSpaces *> dash *> PU .skipSpaces
434438 day ← natural
435- when (day > 31 ) $ P .fail " Incorrect day"
436- pure { month, day, year }
439+ when (day > 31 ) $ P .fail " Invalid day"
440+ case DT .canonicalDate <$> toEnum year <*> toEnum month <*> toEnum day of
441+ M.Nothing → P .fail " Invalid date"
442+ M.Just dt → pure dt
437443
444+ parseTimeValue ∷ SD.TimePrecision → P.Parser String DT.Time
438445 parseTimeValue prec = do
439446 hours ← natural
440- when (hours > 23 ) $ P .fail " Incorrect hours"
447+ when (hours > 23 ) $ P .fail " Invalid hours"
441448 PU .skipSpaces *> colon *> PU .skipSpaces
442449 minutes ← natural
443- when (minutes > 59 ) $ P .fail " Incorrect minutes"
450+ when (minutes > 59 ) $ P .fail " Invalid minutes"
444451 seconds ← case prec of
445452 SD.Minutes -> do
446453 scolon ← PC .try $ PC .optionMaybe $ PU .skipSpaces *> colon
@@ -449,7 +456,7 @@ parseTextBox isPlainText eta template =
449456 SD.Seconds -> do
450457 PU .skipSpaces *> colon *> PU .skipSpaces
451458 secs ← natural
452- when (secs > 59 ) $ P .fail " Incorrect seconds"
459+ when (secs > 59 ) $ P .fail " Invalid seconds"
453460 PU .skipSpaces
454461 pure $ M.Just secs
455462 PU .skipSpaces
@@ -466,7 +473,9 @@ parseTextBox isPlainText eta template =
466473 else if isAM && hours == 12
467474 then 0
468475 else hours
469- pure { hours : hours', minutes, seconds }
476+ case DT.Time <$> toEnum hours' <*> toEnum minutes <*> toEnum (M .fromMaybe 0 seconds) <*> pure bottom of
477+ M.Nothing → P .fail " Invalid time"
478+ M.Just t → pure t
470479
471480 parseNumericValue = do
472481 sign ← PC .try (-1 <$ PS .char ' -' ) <|> pure 1
0 commit comments