mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-05-18 19:10:21 -07:00
X.P.OrgMode: Fallback to "today" if no day is given
This commit is contained in:
parent
8ac84079a2
commit
d691d25d1c
@ -533,7 +533,7 @@ pInput inp = (`runParser` inp) . choice $
|
||||
-- | Parse a 'Priority'.
|
||||
pPriority :: Parser Priority
|
||||
pPriority = option NoPriority $
|
||||
" " *> skipSpaces *> choice
|
||||
skipSpaces *> choice
|
||||
[ "#" *> foldCase "a" $> A
|
||||
, "#" *> foldCase "b" $> B
|
||||
, "#" *> foldCase "c" $> C
|
||||
@ -546,7 +546,7 @@ pTimeOfDay = option Nothing $
|
||||
[ TimeOfDay <$> pHour <* ":" <*> pMinute -- HH:MM
|
||||
, pHHMM -- HHMM
|
||||
, TimeOfDay <$> pHour <*> pure 0 -- HH
|
||||
]
|
||||
] <* (void " " <|> eof)
|
||||
where
|
||||
pHHMM :: Parser TimeOfDay
|
||||
pHHMM = do
|
||||
@ -566,6 +566,7 @@ pDate = skipSpaces *> choice
|
||||
, pPrefix "tom" "orrow" Tomorrow
|
||||
, Next <$> pNext
|
||||
, Date <$> pDate'
|
||||
, pure Today -- Fallback to today if no date was given.
|
||||
]
|
||||
where
|
||||
pNext :: Parser DayOfWeek = choice
|
||||
@ -585,7 +586,7 @@ pDate = skipSpaces *> choice
|
||||
|
||||
pDate' :: Parser (Int, Maybe Int, Maybe Integer)
|
||||
pDate' =
|
||||
(,,) <$> pNumBetween 1 31 -- day
|
||||
(,,) <$> (pNumBetween 1 31 <* (void " " <|> eof)) -- day
|
||||
<*> optional (skipSpaces *> choice
|
||||
[ pPrefix "ja" "nuary" 1 , pPrefix "f" "ebruary" 2
|
||||
, pPrefix "mar" "ch" 3 , pPrefix "ap" "ril" 4
|
||||
|
@ -56,6 +56,11 @@ spec = do
|
||||
(Time {date = Date (22, Just 1, Just 2021), tod = Just $ TimeOfDay 1 1})
|
||||
B
|
||||
)
|
||||
it "parses no day as today when given a time" $ do
|
||||
pInput "todo +s 12:00"
|
||||
`shouldBe` Just (Scheduled "todo" (Time {date = Today, tod = Just $ TimeOfDay 12 0}) NoPriority)
|
||||
pInput "todo +d 14:05 #B"
|
||||
`shouldBe` Just (Deadline "todo" (Time {date = Today, tod = Just $ TimeOfDay 14 5}) B)
|
||||
|
||||
context "no priority#b" $ do
|
||||
it "parses to the correct thing" $
|
||||
@ -179,7 +184,7 @@ instance Arbitrary Date where
|
||||
[ pure Today
|
||||
, pure Tomorrow
|
||||
, Next . toEnum <$> choose (0, 6)
|
||||
, do d <- posInt
|
||||
, do d <- posInt `suchThat` (<= 31)
|
||||
m <- mbPos `suchThat` (<= Just 12)
|
||||
Date . (d, m, ) <$> if isNothing m
|
||||
then pure Nothing
|
||||
|
Loading…
x
Reference in New Issue
Block a user