Skip to content

Commit

Permalink
Fix format of modified_utc in database, use ms precision for import
Browse files Browse the repository at this point in the history
  • Loading branch information
ad-si committed May 17, 2024
1 parent 0ce4006 commit 0f26ff1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
15 changes: 11 additions & 4 deletions tasklite-core/source/ImportExport.hs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ textToNote utc body =

importUtcFormat :: TimeFormatString
importUtcFormat =
toFormat ("YYYY-MM-DD H:MI:S" :: [Char])
toFormat ("YYYY-MM-DD H:MI:S.ms" :: [Char])


data ImportTask = ImportTask
Expand Down Expand Up @@ -496,11 +496,11 @@ setMissingFields importTaskRec = do
, Task.modified_utc =
if importTaskRec.task.modified_utc == ""
|| importTaskRec.task.modified_utc == "1970-01-01 00:00:00"
|| importTaskRec.task.modified_utc == "1970-01-01 00:00:00.000"
|| parseUtc importTaskRec.task.modified_utc == parseUtcNum 0
then
now
& timePrint
(toFormat ("YYYY-MM-DD H:MI:S.ms" :: [P.Char]))
& timePrint (toFormat importUtcFormat)
& T.pack
else show importTaskRec.task.modified_utc
}
Expand Down Expand Up @@ -879,7 +879,14 @@ editTaskByTask editMode conn taskToEdit = do
-- SQL trigger which would overwrite the `closed_utc` field.
P.when (isJust taskFixed.closed_utc) $ do
now_ <- dateCurrent
updateTask conn taskFixed{Task.modified_utc = show @DateTime now_}
updateTask
conn
taskFixed
{ Task.modified_utc =
now_
& timePrint (toFormat importUtcFormat)
& T.pack
}

tagWarnings <- insertTags conn Nothing taskFixed importTaskRec.tags
noteWarnings <- insertNotes conn Nothing taskFixed notesCorrectUtc
Expand Down
7 changes: 3 additions & 4 deletions tasklite-core/test/ImportExportSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import Config (defaultConfig)
import FullTask (FullTask, emptyFullTask)
import FullTask qualified
import ImportExport (ImportTask (ImportTask, notes, tags, task), insertImportTask)
import Task (Task (body, ulid, user, modified_utc), emptyTask)
import Task (Task (body, modified_utc, ulid, user), emptyTask)
import TaskToNote (TaskToNote (TaskToNote))
import TaskToNote qualified
import TestUtils (withMemoryDb)
Expand Down Expand Up @@ -187,10 +187,10 @@ spec = do
ImportTask
{ task =
emptyTask
{ Task.ulid = "01hrz2qz7g0000f4wgrw89nzvm"
{ Task.ulid = "01hrz2qz7g0004gmhn6t73xt9a"
, Task.body = "Support getting the note body from stdin"
, Task.user = "ad-si"
, Task.modified_utc = "2024-03-14 18:14:14"
, Task.modified_utc = "2024-03-14 18:14:14.000"
}
, notes = []
, tags = []
Expand All @@ -207,5 +207,4 @@ spec = do
task.body `shouldBe` expectedImpTask.task.body
task.user `shouldBe` expectedImpTask.task.user
task.modified_utc `shouldBe` expectedImpTask.task.modified_utc

_ -> P.die "Found more than one note"
7 changes: 4 additions & 3 deletions tasklite-core/test/LibSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import Test.Hspec (
)

import Config (defaultConfig)
import Data.Hourglass (TimeFormat (..), timePrint)
import FullTask (FullTask, emptyFullTask)
import FullTask qualified
import ImportExport (EditMode (ApplyPreEdit), editTaskByTask)
Expand Down Expand Up @@ -522,11 +523,11 @@ spec = do
tasks :: [Task] <- query_ memConn "SELECT * FROM tasks"
case tasks of
[task] -> do
task.closed_utc `shouldBe` Just "2024-05-08 10:04:00"
task.closed_utc `shouldBe` Just "2024-05-08 10:04:00.000"
task.state `shouldBe` Just Done
now_ <- dateCurrent
let today = now_ & show & T.take 10
task.modified_utc `shouldSatisfy` (today `T.isPrefixOf`)
let today = now_ & timePrint (toFormat ("YYYY-MM-DD" :: [P.Char]))
T.unpack task.modified_utc `shouldStartWith` today
_ -> P.die "Found more than one task"

it "lets you add notes" $ do
Expand Down

0 comments on commit 0f26ff1

Please sign in to comment.