@@ -581,9 +581,7 @@ render x =
581581 <> " us"
582582
583583-- | Parses an interval. This is not a general purpose parser. It only supports
584- -- the formats that PostgreSQL generates. For example, it will fail to parse an
585- -- interval like @"1 week"@ because PostgreSQL never uses weeks when rendering
586- -- intervals.
584+ -- the formats that PostgreSQL generates.
587585parse :: A. Parser Interval
588586parse =
589587 -- Start with parsers that have non-empty prefixes, in order to avoid
@@ -636,6 +634,7 @@ parsePostgresVerbose = do
636634 flip A. sepBy " " $
637635 A. choice
638636 [ Years <$> A. signed A. decimal <* maybePlural " year" ,
637+ Weeks <$> A. signed A. decimal <* maybePlural " week" ,
639638 Months <$> A. signed A. decimal <* maybePlural " mon" ,
640639 Days <$> A. signed A. decimal <* maybePlural " day" ,
641640 Hours <$> A. signed A. decimal <* maybePlural " hour" ,
@@ -652,6 +651,7 @@ parsePostgres = do
652651 flip A. sepBy " " $
653652 A. choice
654653 [ Years <$> A. signed A. decimal <* maybePlural " year" ,
654+ Weeks <$> A. signed A. decimal <* maybePlural " week" ,
655655 Months <$> A. signed A. decimal <* maybePlural " mon" ,
656656 Days <$> A. signed A. decimal <* maybePlural " day"
657657 ]
@@ -688,6 +688,7 @@ maybePlural word = (<>) <$> A.string word <*> A.option "" "s"
688688-- are accepted, like years and months.
689689data Component
690690 = Years ! Integer
691+ | Weeks ! Integer
691692 | Months ! Integer
692693 | Days ! Integer
693694 | Hours ! Integer
@@ -701,6 +702,7 @@ data Component
701702fromComponent :: Component -> Maybe Interval
702703fromComponent c = case c of
703704 Years y -> fromYears =<< Bits. toIntegralSized y
705+ Weeks w -> fromWeeks =<< Bits. toIntegralSized w
704706 Months m -> fromMonths <$> Bits. toIntegralSized m
705707 Days d -> fromDays <$> Bits. toIntegralSized d
706708 Hours h -> fromHours =<< Bits. toIntegralSized h
@@ -722,6 +724,7 @@ fromComponents =
722724negateComponent :: Component -> Component
723725negateComponent c = case c of
724726 Years y -> Years (- y)
727+ Weeks w -> Weeks (- w)
725728 Months m -> Months (- m)
726729 Days d -> Days (- d)
727730 Hours h -> Hours (- h)
0 commit comments