@@ -76,11 +76,15 @@ data ImportTask = ImportTask
76
76
-- | Values a suffixed with a prime (') to avoid name collisions
77
77
instance FromJSON ImportTask where
78
78
parseJSON = withObject " task" $ \ o -> do
79
+ utc <- o .:? " utc"
79
80
entry <- o .:? " entry"
80
81
creation <- o .:? " creation"
81
82
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
84
88
85
89
o_body <- o .:? " body"
86
90
description <- o .:? " description"
@@ -91,8 +95,8 @@ instance FromJSON ImportTask where
91
95
let state = textToTaskState =<< (o_state <|> status)
92
96
93
97
o_priority_adjustment <- o .:? " priority_adjustment"
94
- urgency <- o .:? " urgency"
95
- priority <- optional (o .: " priority" )
98
+ urgency <- o .:? " urgency"
99
+ priority <- optional (o .: " priority" )
96
100
let priority_adjustment = o_priority_adjustment <|> urgency <|> priority
97
101
98
102
modified <- o .:? " modified"
@@ -205,9 +209,22 @@ instance FromJSON ImportTask where
205
209
annotations <- o .:? " annotations" :: Parser (Maybe [Annotation ])
206
210
let
207
211
notes = case (o_notes, annotations) of
208
- (Just theNotes , _ ) -> theNotes
212
+ (Nothing , Nothing ) -> []
209
213
(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
211
228
212
229
o_user <- o .:? " user"
213
230
let user = fromMaybe " " o_user
@@ -244,8 +261,10 @@ insertImportTask connection importTaskRecord = do
244
261
then taskParsed { Task. user = T. pack effectiveUserName }
245
262
else taskParsed
246
263
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)
249
268
pure $
250
269
" 📥 Imported task" <+> dquotes (pretty $ Task. body theTask)
251
270
<+> " with ulid" <+> dquotes (pretty $ Task. ulid theTask)
@@ -364,8 +383,10 @@ editTask conf connection idSubstr = do
364
383
}
365
384
366
385
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)
369
390
pure $
370
391
" ✏️ Edited task" <+> dquotes (pretty $ Task. body taskFixed)
371
392
<+> " with ulid" <+> dquotes (pretty $ Task. ulid taskFixed)
0 commit comments