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:
@@ -597,6 +597,7 @@ namespace URLNotesGrabberCORE
|
||||
{
|
||||
DBPath ??= GetDefaultDbPath();
|
||||
postType = PostTypes.Normalize(postType);
|
||||
postDate = PostDates.Normalize(postDate)!;
|
||||
try { AddBlog(blogName, byLikes, DBPath); } catch { }
|
||||
try { UpdatePostSetDate(blogName, postID, postDate, DBPath); } catch { }
|
||||
try { UpdatePost(blogName, postID, reblogURL, postDate, postURL, slug, reblogKey, reblogName, summary, quote, body, tags, link, photoURL, photoCaption, downloadedFiles, audioCaption, question, answer, title, hasImage, byLikes, DBPath, rootBlogName, rootURL, postType); } catch { }
|
||||
@@ -2249,6 +2250,7 @@ namespace URLNotesGrabberCORE
|
||||
// column. PostType is used as an output filename, so this is the invariant that keeps
|
||||
// a stray value from becoming a stray file.
|
||||
postType = PostTypes.Normalize(postType);
|
||||
postDate = PostDates.Normalize(postDate);
|
||||
try { AddBlog(blogName, false, DBPath); } catch { }
|
||||
|
||||
SQLiteConnection connection;
|
||||
@@ -2620,10 +2622,11 @@ namespace URLNotesGrabberCORE
|
||||
if (string.IsNullOrWhiteSpace(kvp.Value)) continue;
|
||||
string? column = MapPrefixToColumn(kvp.Key);
|
||||
if (column == null) continue;
|
||||
string value = column == "PostDate" ? PostDates.Normalize(kvp.Value)! : kvp.Value;
|
||||
string paramName = "@p" + parameters.Count;
|
||||
setClauses.Add($"{column} = {paramName}");
|
||||
changedClauses.Add($"IFNULL({column}, '') <> {paramName}");
|
||||
parameters.Add((paramName, kvp.Value));
|
||||
parameters.Add((paramName, value));
|
||||
}
|
||||
|
||||
if (setClauses.Count == 0) return false;
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace URLNotesGrabberCORE
|
||||
{
|
||||
/// <summary>
|
||||
/// The single format for Posts.PostDate: "yyyy-MM-dd HH:mm:ss GMT", which is what the
|
||||
/// Tumblr API sends and what nearly every row holds. Text-file exports can carry the
|
||||
/// RFC 1123 form ("Fri, 14 Feb 2025 15:20:09 GMT") instead, which as text sorts on its
|
||||
/// weekday name and falls outside every --fromDate/--toDate range comparison.
|
||||
///
|
||||
/// Every path that writes PostDate routes through <see cref="Normalize"/>. Only the RFC 1123
|
||||
/// form is rewritten; anything else, including the "." no-change sentinel, passes through.
|
||||
/// </summary>
|
||||
public static class PostDates
|
||||
{
|
||||
public static string? Normalize(string? value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value)) return value;
|
||||
string trimmed = value.Trim();
|
||||
if (DateTime.TryParseExact(trimmed, "r", CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out DateTime parsed))
|
||||
return parsed.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture) + " GMT";
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -154,6 +154,10 @@ Notable:
|
||||
on every row, and something has since started writing it. Anything that treated it as
|
||||
permanently unset, or derived the type from post content instead, should be re-examined
|
||||
against the live data. Rolodex still derives it.
|
||||
- **`PostDate` is `yyyy-MM-dd HH:mm:ss GMT`** — UTC, as the Tumblr API sends it, unlike
|
||||
the local-time `DateCreated`/`DateModified`. Text-file exports may carry RFC 1123
|
||||
(`Fri, 14 Feb 2025 15:20:09 GMT`); every write path runs `PostDates.Normalize` to
|
||||
convert it, and `../normalize-postdate.sql` fixed the 4 rows written before that.
|
||||
- `HasImage = 1` on 14,026 rows. It records that the post *had* a picture, not that a
|
||||
usable URL was kept, so it is not a reliable predictor that anything will render.
|
||||
- `PhotoURL` is largely unused; in practice the image markup lives inside `Body`.
|
||||
|
||||
Reference in New Issue
Block a user