@@ -76,11 +76,15 @@ data ImportTask = ImportTask
7676-- | Values a suffixed with a prime (') to avoid name collisions
7777instance FromJSON ImportTask where
7878 parseJSON = withObject " task" $ \ o -> do
79+ utc <- o .:? " utc"
7980 entry <- o .:? " entry"
8081 creation <- o .:? " creation"
8182 created_at <- o .:? " created_at"
82- let createdUtc = fromMaybe (timeFromElapsedP 0 :: DateTime )
83- (parseUtc =<< (entry <|> creation <|> created_at))
83+ let
84+ zeroTime = timeFromElapsedP 0 :: DateTime
85+ parsedCreatedUtc = parseUtc
86+ =<< (utc <|> entry <|> creation <|> created_at)
87+ createdUtc = fromMaybe zeroTime parsedCreatedUtc
8488
8589 o_body <- o .:? " body"
8690 description <- o .:? " description"
@@ -91,8 +95,8 @@ instance FromJSON ImportTask where
9195 let state = textToTaskState =<< (o_state <|> status)
9296
9397 o_priority_adjustment <- o .:? " priority_adjustment"
94- urgency <- o .:? " urgency"
95- priority <- optional (o .: " priority" )
98+ urgency <- o .:? " urgency"
99+ priority <- optional (o .: " priority" )
96100 let priority_adjustment = o_priority_adjustment <|> urgency <|> priority
97101
98102 modified <- o .:? " modified"
@@ -205,9 +209,22 @@ instance FromJSON ImportTask where
205209 annotations <- o .:? " annotations" :: Parser (Maybe [Annotation ])
206210 let
207211 notes = case (o_notes, annotations) of
208- (Just theNotes , _ ) -> theNotes
212+ (Nothing , Nothing ) -> []
209213 (Nothing , Just values) -> values <$$> annotationToNote
210- _ -> []
214+ (Just theNotes , _) -> case parsedCreatedUtc of
215+ Just crUtc -> theNotes <&> (\ theNote ->
216+ let
217+ noteUlidTxt = Note. ulid theNote
218+ mbNoteUlid = parseUlidText noteUlidTxt
219+ mbNewUlid = do
220+ noteUlid <- mbNoteUlid
221+
222+ pure $ show $ setDateTime noteUlid crUtc
223+ in
224+ theNote { Note. ulid =
225+ (T. toLower $ fromMaybe noteUlidTxt mbNewUlid) }
226+ )
227+ Nothing -> theNotes
211228
212229 o_user <- o .:? " user"
213230 let user = fromMaybe " " o_user
@@ -244,8 +261,10 @@ insertImportTask connection importTaskRecord = do
244261 then taskParsed { Task. user = T. pack effectiveUserName }
245262 else taskParsed
246263 insertTask connection theTask
247- insertTags connection (primaryKey theTask) (tags importTaskRecord)
248- insertNotes connection (primaryKey theTask) (notes importTaskRecord)
264+ insertTags connection (ulidTextToDateTime $ Task. ulid taskParsed)
265+ (primaryKey theTask) (tags importTaskRecord)
266+ insertNotes connection (ulidTextToDateTime $ Task. ulid taskParsed)
267+ (primaryKey theTask) (notes importTaskRecord)
249268 pure $
250269 " 📥 Imported task" <+> dquotes (pretty $ Task. body theTask)
251270 <+> " with ulid" <+> dquotes (pretty $ Task. ulid theTask)
@@ -364,8 +383,10 @@ editTask conf connection idSubstr = do
364383 }
365384
366385 replaceTask connection taskFixed
367- insertTags connection (primaryKey taskFixed) (tags importTaskRecord)
368- insertNotes connection (primaryKey taskFixed) (notes importTaskRecord)
386+ insertTags connection Nothing
387+ (primaryKey taskFixed) (tags importTaskRecord)
388+ insertNotes connection Nothing
389+ (primaryKey taskFixed) (notes importTaskRecord)
369390 pure $
370391 " ✏️ Edited task" <+> dquotes (pretty $ Task. body taskFixed)
371392 <+> " with ulid" <+> dquotes (pretty $ Task. ulid taskFixed)
0 commit comments