Files
URLNotesGrabberCore/URLNotesGrabberCORE/PostDates.cs
T
jimandClaude Opus 5 2948a4aff0 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]>
2026-09-21 14:07:05 -05:00

28 lines
1.2 KiB
C#

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;
}
}
}