@@ -8,7 +8,7 @@ import Protolude as P
8
8
9
9
import Data.Hourglass
10
10
import Data.Text as T
11
- import qualified Data.Time.ISO8601.Duration as Iso8601
11
+ import qualified Data.Time.ISO8601.Duration as Iso
12
12
import Data.ULID
13
13
import Data.Coerce
14
14
import Data.Yaml as Yaml
@@ -339,15 +339,18 @@ setReadyUtc conf connection datetime ids = do
339
339
pure $ vsep docs
340
340
341
341
342
- waitFor :: Config -> Connection -> Duration -> [Text ] -> IO (Doc AnsiStyle )
342
+ waitFor
343
+ :: Config -> Connection -> Iso. Duration -> [Text ] -> IO (Doc AnsiStyle )
343
344
waitFor conf connection duration ids = do
344
345
docs <- forM ids $ \ idSubstr ->
345
346
execWithTask conf connection idSubstr $ \ task -> do
346
347
now <- timeCurrentP
347
348
let
348
349
taskUlid@ (TaskUlid idText) = primaryKey task
349
350
nowAsText = (pack . timePrint (utcFormat conf)) now
350
- threeDays = (pack . timePrint (utcFormat conf)) (now `timeAdd` duration)
351
+ threeDays = (pack . timePrint (utcFormat conf))
352
+ (utcTimeToDateTime $ Iso. addDuration duration $
353
+ dateTimeToUtcTime $ timeFromElapsedP now)
351
354
prettyBody = dquotes (pretty $ Task. body task)
352
355
prettyId = dquotes (pretty idText)
353
356
@@ -373,18 +376,21 @@ waitFor conf connection duration ids = do
373
376
374
377
waitTasks :: Config -> Connection -> [Text ] -> IO (Doc AnsiStyle )
375
378
waitTasks conf connection =
376
- waitFor conf connection $ mempty { durationHours = 72 }
379
+ waitFor conf connection $
380
+ Iso. DurationDate (Iso. DurDateDay (Iso. DurDay 3 ) Nothing )
377
381
378
382
379
383
reviewTasksIn :: Config -> Connection
380
- -> Duration -> [Text ] -> IO (Doc AnsiStyle )
381
- reviewTasksIn conf connection days ids = do
384
+ -> Iso. Duration -> [Text ] -> IO (Doc AnsiStyle )
385
+ reviewTasksIn conf connection duration ids = do
382
386
docs <- forM ids $ \ idSubstr -> do
383
387
execWithTask conf connection idSubstr $ \ task -> do
384
388
now <- timeCurrentP
385
389
let
386
390
taskUlid@ (TaskUlid idText) = primaryKey task
387
- xDays = (pack . timePrint (utcFormat conf)) (now `timeAdd` days)
391
+ xDays = (pack . timePrint (utcFormat conf))
392
+ (utcTimeToDateTime $ Iso. addDuration duration $
393
+ dateTimeToUtcTime $ timeFromElapsedP now)
388
394
prettyBody = dquotes (pretty $ Task. body task)
389
395
prettyId = dquotes (pretty idText)
390
396
warningStart = " ⚠️ Task" <+> prettyBody <+> " with id" <+> prettyId
@@ -498,14 +504,14 @@ createNextRecurrence conf connection task = do
498
504
isoDurEither =
499
505
durTextEither
500
506
<&> encodeUtf8
501
- >>= Iso8601 . parseDuration
507
+ >>= Iso . parseDuration
502
508
503
509
showEither e = e
504
510
& (either (const Nothing ) Just )
505
511
<&> utcTimeToDateTime
506
512
<&> showDateTime
507
513
508
- nextDueMb = liftA2 Iso8601 . addDuration isoDurEither
514
+ nextDueMb = liftA2 Iso . addDuration isoDurEither
509
515
(maybeToEither " Task has no due UTC" (dueUtcMb <&> dateTimeToUtcTime))
510
516
511
517
runBeamSqlite connection $ do
@@ -519,13 +525,13 @@ createNextRecurrence conf connection task = do
519
525
, Task. due_utc = val_ $ nextDueMb & showEither
520
526
521
527
, Task. awake_utc = val_ $
522
- (liftA2 Iso8601 . addDuration isoDurEither
528
+ (liftA2 Iso . addDuration isoDurEither
523
529
(maybeToEither " Task has no awake UTC"
524
530
((Task. awake_utc task) >>= parseUtc <&> dateTimeToUtcTime)))
525
531
& showEither
526
532
527
533
, Task. ready_utc = val_ $
528
- (liftA2 Iso8601 . addDuration isoDurEither
534
+ (liftA2 Iso . addDuration isoDurEither
529
535
(maybeToEither " Task has no ready UTC"
530
536
((Task. ready_utc task) >>= parseUtc <&> dateTimeToUtcTime)))
531
537
& showEither
@@ -661,9 +667,9 @@ durationToIso dur =
661
667
662
668
663
669
repeatTasks ::
664
- Config -> Connection -> Duration -> [IdText ] -> IO (Doc AnsiStyle )
670
+ Config -> Connection -> Iso. Duration -> [IdText ] -> IO (Doc AnsiStyle )
665
671
repeatTasks conf connection duration ids = do
666
- let durIso = durationToIso duration
672
+ let durationIsoText = decodeUtf8 $ Iso. formatDuration duration
667
673
668
674
docs <- forM ids $ \ idSubstr ->
669
675
execWithTask conf connection idSubstr $ \ task -> do
@@ -677,28 +683,29 @@ repeatTasks conf connection duration ids = do
677
683
runBeamSqlite connection $ runUpdate $
678
684
update (_tldbTasks taskLiteDb)
679
685
(\ task_ -> mconcat
680
- [ (Task. repetition_duration task_) <-. val_ (Just durIso )
686
+ [ (Task. repetition_duration task_) <-. val_ (Just durationIsoText )
681
687
, (Task. group_ulid task_) <-. val_ (Just groupUlid)
682
688
])
683
689
(\ task_ -> primaryKey task_ ==. val_ taskUlid)
684
690
685
691
pure $ " 📅 Set repeat duration of task" <+> prettyBody
686
692
<+> " with id" <+> prettyId
687
- <+> " to" <+> dquotes (pretty $ durIso )
693
+ <+> " to" <+> dquotes (pretty $ durationIsoText )
688
694
689
695
pure $ vsep docs
690
696
691
697
692
698
recurTasks ::
693
- Config -> Connection -> Iso8601 . Duration -> [IdText ] -> IO (Doc AnsiStyle )
699
+ Config -> Connection -> Iso . Duration -> [IdText ] -> IO (Doc AnsiStyle )
694
700
recurTasks conf connection duration ids = do
701
+ let durationIsoText = decodeUtf8 $ Iso. formatDuration duration
702
+
695
703
docs <- forM ids $ \ idSubstr ->
696
704
execWithTask conf connection idSubstr $ \ task -> do
697
705
let
698
706
taskUlid@ (TaskUlid idText) = primaryKey task
699
707
prettyBody = dquotes (pretty $ Task. body task)
700
708
prettyId = dquotes (pretty idText)
701
- durationIsoText = decodeUtf8 $ Iso8601. formatDuration duration
702
709
703
710
groupUlid <- formatUlid getULID
704
711
0 commit comments