fix(posts): normalize PostDate to yyyy-MM-dd HH:mm:ss GMT

Text-file exports can carry RFC 1123 dates ("Fri, 14 Feb 2025 15:20:09 GMT"),
which sort on the weekday name and fall outside --fromDate/--toDate
comparisons. PostDates.Normalize converts them on every PostDate write path
(AddPost, UpsertPostFromTextFile, UpdatePostContentFields).
normalize-postdate.sql fixes the 4 existing rows.

Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
jim
2026-09-21 14:07:05 -05:00
co-authored by Claude Opus 5
parent b8231d6a4c
commit 2948a4aff0
4 changed files with 66 additions and 1 deletions
+31
View File
@@ -0,0 +1,31 @@
-- normalize-postdate.sql
-- Rewrites Posts.PostDate values held in RFC 1123 form ("Fri, 14 Feb 2025 15:20:09 GMT")
-- into the column's canonical "yyyy-MM-dd HH:mm:ss GMT" (the Tumblr API's own format).
--
-- As of 2026-09-21 this matched 4 rows, all zombaee, from one text-file import. As text
-- they sort on the weekday name and never satisfy --fromDate / --toDate comparisons.
-- New writes are normalized in code by PostDates.Normalize, so this is a one-off.
--
-- Only PostDate changes. DateModified is left alone: the post content did not change.
--
-- HOW TO RUN: back up TL.db, then from the URLNotesGrabberCORE project folder:
-- sqlite3 TL.db < ../normalize-postdate.sql
SELECT 'before', COUNT(*) FROM Posts WHERE PostDate LIKE '___, __ ___ ____ __:__:__ GMT';
BEGIN;
UPDATE Posts
SET PostDate = substr(PostDate, 13, 4) || '-' ||
printf('%02d', (instr('JanFebMarAprMayJunJulAugSepOctNovDec', substr(PostDate, 9, 3)) + 2) / 3) || '-' ||
substr(PostDate, 6, 2) || ' ' ||
substr(PostDate, 18)
WHERE PostDate LIKE '___, __ ___ ____ __:__:__ GMT'
AND instr('JanFebMarAprMayJunJulAugSepOctNovDec', substr(PostDate, 9, 3)) % 3 = 1;
COMMIT;
-- VERIFY: expect 0, then a single shape '9999-99-99 99:99:99 GMT' (plus any NULL/blank)
SELECT 'after', COUNT(*) FROM Posts WHERE PostDate LIKE '___, %';
SELECT CASE WHEN PostDate GLOB '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] GMT'
THEN 'yyyy-MM-dd HH:mm:ss GMT' ELSE IFNULL(PostDate, '(null)') END AS shape,
COUNT(*)
FROM Posts GROUP BY 1 ORDER BY 2 DESC;