From e0fd98a494affa4929a7f19459b581c3800b3ff7 Mon Sep 17 00:00:00 2001 From: "savage@savage.za.org" Date: Mon, 19 Oct 2026 20:52:40 +0200 Subject: [PATCH] Expand news date timezone abbreviation coverage Correct CST to the -06:00 North American news-date convention and broaden the curated timezone table with international and historical abbreviations. Document ambiguous mappings and historical daylight offsets, and add UTC conversion tests. --- docs/common/ArticleRecord.md | 6 + .../NewsDateParser.DefaultTimezones.cs | 152 ++++++-- .../DateParser/NewsDateParserTests.cs | 340 ++++++++++++++++++ 3 files changed, 475 insertions(+), 23 deletions(-) diff --git a/docs/common/ArticleRecord.md b/docs/common/ArticleRecord.md index 7bd68fc4..f003bee4 100644 --- a/docs/common/ArticleRecord.md +++ b/docs/common/ArticleRecord.md @@ -263,6 +263,12 @@ ddd, dd MMM yyyy HH:mm:ss +0000 Example from parser tests: `Fri, 23 Aug 2024 07:30:10 +0200` resolves to `Fri, 23 Aug 2024 05:30:10 +0000`. The materializer overwrites only the winning header’s **value** bytes (not the header name). If Injection-Date won, that value is rewritten; `Fields.Date` then points at that rewritten Injection-Date value. +### Timezone abbreviations + +The parser replaces one trailing ASCII letter token, length 2 through 8, with a fixed offset. It does not consult the machine timezone database. RFC 1036 §2.1.2 names `CST` as a North American news-date abbreviation. The local RFC text does not give its numeric offset. The `-06:00` mapping is the Issue #164 convention. `CDT` stays `-05:00`. China Standard Time is the distinct token `BJT` (`+08:00`). `PST` is Pacific `-08:00`; the Philippines are `PHT`. `BST` is British Summer Time `+01:00`, not Bangladesh. `IST` remains the existing India Standard Time mapping `+05:30`; Irish and Israel Standard Time share those letters and are not distinguished. + +These collisions are omitted rather than given one region's offset: `AST`/`ADT`, `GST`, `NST`/`NDT`, `AMT`, `ECT`, `WST`, and `SST`. `MSD`, `BRST`, `WAST`, `IRDT`, `AZST`, and `AWDT` stay in the table as historical daylight-time conventions, not current year-round offsets. Civil offsets varied by place and period, so those static values do not reconstruct the original local civil time for every article date. `UTC+0` through `UTC+9` and `UTC-1` through `UTC-9` stay in the table and are not selected, because the detector accepts letters only. Numeric `±hhmm` and `±hh:mm` forms are a separate parse path. The table is a news-date convention, not a complete history of civil offsets. + ### Failure If no candidate parses: `NntpArticleParseFailureCode.MissingOrInvalidDate`. The factory returns `RejectedParse` and does not materialize. diff --git a/src/VectorNNTPD.Common/Articles/DateParser/NewsDateParser.DefaultTimezones.cs b/src/VectorNNTPD.Common/Articles/DateParser/NewsDateParser.DefaultTimezones.cs index 7fd19813..0db83bff 100644 --- a/src/VectorNNTPD.Common/Articles/DateParser/NewsDateParser.DefaultTimezones.cs +++ b/src/VectorNNTPD.Common/Articles/DateParser/NewsDateParser.DefaultTimezones.cs @@ -14,59 +14,165 @@ internal static partial class NewsDateParser /// /// Fixed abbreviation-to-offset table used by SubstituteTimezoneAbbreviation. - /// First case-insensitive match wins. CST maps to +08:00 and CDT maps to -05:00 - /// as stored here. UTC+0 through UTC+9 and UTC-1 through UTC-9 are included; other numeric forms are not. + /// The lookup compares the entire trailing letter token. Order does not express prefixes. + /// CST is the North American abbreviation named by RFC 1036. Its -06:00 mapping is the Issue #164 convention. + /// The local RFC 1036 text does not state that numeric offset. + /// UTC+0 through UTC+9 and UTC-1 through UTC-9 are retained and are not selected: + /// the detector accepts only a trailing ASCII letter run, so those tokens never reach this table. /// private static readonly TimezoneMapping[] TimezoneMappings = CreateDefaultTimezoneMappings(); /// /// Builds from the abbreviation/offset pairs in this method. + /// Offsets are the conventional static values used for news dates. They are not a civil-timezone database, + /// and they do not follow the machine's local zone. + /// MSD, BRST, WAST, IRDT, AZST, and AWDT are historical daylight-time conventions, not current year-round offsets. + /// Civil offsets varied by place and period, so those static values do not reconstruct the original local civil time for every article date. + /// Ambiguous tokens that are absent on purpose: + /// AST/ADT (Atlantic -04:00/-03:00 and Arabia +03:00/+04:00), + /// GST (Gulf +04:00 and South Georgia -02:00), + /// NST/NDT (Newfoundland and other historical uses), + /// AMT (Armenia +04:00 and Amazon -04:00), + /// ECT (Ecuador -05:00 and Eastern Caribbean -04:00), + /// WST (Western Australia and Samoa), and SST (American Samoa -11:00 and historical Samoa). + /// BST is British Summer Time, not Bangladesh. IST keeps the existing India Standard Time mapping; + /// Irish and Israel Standard Time use the same letters and are not distinguished. + /// PST is Pacific, not the Philippines (PHT). China Standard Time is not CST; the distinct token is BJT. /// /// The table in match order. private static TimezoneMapping[] CreateDefaultTimezoneMappings() => [ + // RFC 1036 names GMT and the North American abbreviations. CST is Central, not China. + // Its -06:00 value is the Issue #164 convention; the local RFC 1036 text does not print that offset. new("UT"u8.ToArray(), "+00:00"u8.ToArray()), new("UTC"u8.ToArray(), "+00:00"u8.ToArray()), new("GMT"u8.ToArray(), "+00:00"u8.ToArray()), - new("BST"u8.ToArray(), "+01:00"u8.ToArray()), - new("WET"u8.ToArray(), "+00:00"u8.ToArray()), - new("WEST"u8.ToArray(), "+01:00"u8.ToArray()), - new("CET"u8.ToArray(), "+01:00"u8.ToArray()), - new("CEST"u8.ToArray(), "+02:00"u8.ToArray()), - new("EET"u8.ToArray(), "+02:00"u8.ToArray()), - new("EEST"u8.ToArray(), "+03:00"u8.ToArray()), new("EST"u8.ToArray(), "-05:00"u8.ToArray()), new("EDT"u8.ToArray(), "-04:00"u8.ToArray()), - new("CST"u8.ToArray(), "+08:00"u8.ToArray()), + new("CST"u8.ToArray(), "-06:00"u8.ToArray()), new("CDT"u8.ToArray(), "-05:00"u8.ToArray()), new("MST"u8.ToArray(), "-07:00"u8.ToArray()), new("MDT"u8.ToArray(), "-06:00"u8.ToArray()), new("PST"u8.ToArray(), "-08:00"u8.ToArray()), new("PDT"u8.ToArray(), "-07:00"u8.ToArray()), + + // Alaska and Hawaii. Single-letter military zones from RFC 5322 are excluded by the 2..8 letter rule. new("AKST"u8.ToArray(), "-09:00"u8.ToArray()), new("AKDT"u8.ToArray(), "-08:00"u8.ToArray()), new("HST"u8.ToArray(), "-10:00"u8.ToArray()), - new("AEST"u8.ToArray(), "+10:00"u8.ToArray()), - new("AEDT"u8.ToArray(), "+11:00"u8.ToArray()), - new("ACST"u8.ToArray(), "+09:30"u8.ToArray()), - new("ACDT"u8.ToArray(), "+10:30"u8.ToArray()), - new("AWST"u8.ToArray(), "+08:00"u8.ToArray()), - new("JST"u8.ToArray(), "+09:00"u8.ToArray()), - new("KST"u8.ToArray(), "+09:00"u8.ToArray()), - new("HKT"u8.ToArray(), "+08:00"u8.ToArray()), - new("SGT"u8.ToArray(), "+08:00"u8.ToArray()), - new("IST"u8.ToArray(), "+05:30"u8.ToArray()), - new("PKT"u8.ToArray(), "+05:00"u8.ToArray()), + + // Europe. BST is British Summer Time (+01:00), the mapping already used here, not Bangladesh Standard Time. + new("WET"u8.ToArray(), "+00:00"u8.ToArray()), + new("WEST"u8.ToArray(), "+01:00"u8.ToArray()), + new("CET"u8.ToArray(), "+01:00"u8.ToArray()), + new("CEST"u8.ToArray(), "+02:00"u8.ToArray()), + new("MET"u8.ToArray(), "+01:00"u8.ToArray()), + new("MEST"u8.ToArray(), "+02:00"u8.ToArray()), + new("EET"u8.ToArray(), "+02:00"u8.ToArray()), + new("EEST"u8.ToArray(), "+03:00"u8.ToArray()), + new("BST"u8.ToArray(), "+01:00"u8.ToArray()), new("MSK"u8.ToArray(), "+03:00"u8.ToArray()), + // Historical Moscow daylight, not a current year-round offset. + new("MSD"u8.ToArray(), "+04:00"u8.ToArray()), new("TRT"u8.ToArray(), "+03:00"u8.ToArray()), + + // South America and Saint-Pierre. Offsets are the long-standing conventional abbreviation values. + new("ART"u8.ToArray(), "-03:00"u8.ToArray()), + new("BRT"u8.ToArray(), "-03:00"u8.ToArray()), + // Historical Brazil daylight, not a current year-round offset. + new("BRST"u8.ToArray(), "-02:00"u8.ToArray()), + new("CLT"u8.ToArray(), "-04:00"u8.ToArray()), + new("CLST"u8.ToArray(), "-03:00"u8.ToArray()), + new("COT"u8.ToArray(), "-05:00"u8.ToArray()), + new("PET"u8.ToArray(), "-05:00"u8.ToArray()), + new("BOT"u8.ToArray(), "-04:00"u8.ToArray()), + new("GYT"u8.ToArray(), "-04:00"u8.ToArray()), + new("SRT"u8.ToArray(), "-03:00"u8.ToArray()), + new("UYT"u8.ToArray(), "-03:00"u8.ToArray()), + new("GFT"u8.ToArray(), "-03:00"u8.ToArray()), + new("PMST"u8.ToArray(), "-03:00"u8.ToArray()), + new("PMDT"u8.ToArray(), "-02:00"u8.ToArray()), + + // Africa. SAST has no daylight partner in this table. + new("WAT"u8.ToArray(), "+01:00"u8.ToArray()), + // Historical West Africa daylight, not a current year-round offset. + new("WAST"u8.ToArray(), "+02:00"u8.ToArray()), + new("CAT"u8.ToArray(), "+02:00"u8.ToArray()), + new("EAT"u8.ToArray(), "+03:00"u8.ToArray()), new("SAST"u8.ToArray(), "+02:00"u8.ToArray()), + + // Middle East and South Asia, including the fractional offsets used on the wire. + // IST remains India Standard Time. IDT is Israel Daylight and does not make IST mean Israel. + new("IRST"u8.ToArray(), "+03:30"u8.ToArray()), + // Historical Iran daylight, not a current year-round offset. + new("IRDT"u8.ToArray(), "+04:30"u8.ToArray()), + new("AFT"u8.ToArray(), "+04:30"u8.ToArray()), + new("PKT"u8.ToArray(), "+05:00"u8.ToArray()), + new("IST"u8.ToArray(), "+05:30"u8.ToArray()), + new("NPT"u8.ToArray(), "+05:45"u8.ToArray()), + new("LKT"u8.ToArray(), "+05:30"u8.ToArray()), + new("MMT"u8.ToArray(), "+06:30"u8.ToArray()), + new("BTT"u8.ToArray(), "+06:00"u8.ToArray()), + new("IDT"u8.ToArray(), "+03:00"u8.ToArray()), + new("AZT"u8.ToArray(), "+04:00"u8.ToArray()), + // Historical Azerbaijan daylight, not a current year-round offset. + new("AZST"u8.ToArray(), "+05:00"u8.ToArray()), + new("GET"u8.ToArray(), "+04:00"u8.ToArray()), + + // South, Southeast, Central, and East Asia. BJT is Beijing. PHT is the Philippines, not PST. + new("ICT"u8.ToArray(), "+07:00"u8.ToArray()), new("WIB"u8.ToArray(), "+07:00"u8.ToArray()), new("WITA"u8.ToArray(), "+08:00"u8.ToArray()), new("WIT"u8.ToArray(), "+09:00"u8.ToArray()), + new("HKT"u8.ToArray(), "+08:00"u8.ToArray()), + new("SGT"u8.ToArray(), "+08:00"u8.ToArray()), + new("BJT"u8.ToArray(), "+08:00"u8.ToArray()), + new("PHT"u8.ToArray(), "+08:00"u8.ToArray()), + new("MYT"u8.ToArray(), "+08:00"u8.ToArray()), + new("BNT"u8.ToArray(), "+08:00"u8.ToArray()), + new("JST"u8.ToArray(), "+09:00"u8.ToArray()), + new("KST"u8.ToArray(), "+09:00"u8.ToArray()), + new("ULAT"u8.ToArray(), "+08:00"u8.ToArray()), + new("HOVT"u8.ToArray(), "+07:00"u8.ToArray()), + new("KGT"u8.ToArray(), "+06:00"u8.ToArray()), + new("UZT"u8.ToArray(), "+05:00"u8.ToArray()), + new("TMT"u8.ToArray(), "+05:00"u8.ToArray()), + new("TJT"u8.ToArray(), "+05:00"u8.ToArray()), + new("YEKT"u8.ToArray(), "+05:00"u8.ToArray()), + new("OMST"u8.ToArray(), "+06:00"u8.ToArray()), + new("NOVT"u8.ToArray(), "+07:00"u8.ToArray()), + new("KRAT"u8.ToArray(), "+07:00"u8.ToArray()), + new("IRKT"u8.ToArray(), "+08:00"u8.ToArray()), + new("YAKT"u8.ToArray(), "+09:00"u8.ToArray()), + new("VLAT"u8.ToArray(), "+10:00"u8.ToArray()), + new("PETT"u8.ToArray(), "+12:00"u8.ToArray()), + + // Australia, New Zealand, and the Pacific. Fractional offsets are the zone's conventional standard or daylight value. + new("AWST"u8.ToArray(), "+08:00"u8.ToArray()), + // Historical Western Australia daylight, not a current year-round offset. + new("AWDT"u8.ToArray(), "+09:00"u8.ToArray()), + new("ACST"u8.ToArray(), "+09:30"u8.ToArray()), + new("ACDT"u8.ToArray(), "+10:30"u8.ToArray()), + new("AEST"u8.ToArray(), "+10:00"u8.ToArray()), + new("AEDT"u8.ToArray(), "+11:00"u8.ToArray()), + new("LHST"u8.ToArray(), "+10:30"u8.ToArray()), + new("LHDT"u8.ToArray(), "+11:00"u8.ToArray()), new("NZST"u8.ToArray(), "+12:00"u8.ToArray()), new("NZDT"u8.ToArray(), "+13:00"u8.ToArray()), - new("NPT"u8.ToArray(), "+05:45"u8.ToArray()), - new("IRST"u8.ToArray(), "+03:30"u8.ToArray()), + new("CHAST"u8.ToArray(), "+12:45"u8.ToArray()), + new("CHADT"u8.ToArray(), "+13:45"u8.ToArray()), + new("ChST"u8.ToArray(), "+10:00"u8.ToArray()), + new("TAHT"u8.ToArray(), "-10:00"u8.ToArray()), + new("MART"u8.ToArray(), "-09:30"u8.ToArray()), + new("CKT"u8.ToArray(), "-10:00"u8.ToArray()), + new("FJT"u8.ToArray(), "+12:00"u8.ToArray()), + new("TOT"u8.ToArray(), "+13:00"u8.ToArray()), + new("GILT"u8.ToArray(), "+12:00"u8.ToArray()), + new("PHOT"u8.ToArray(), "+13:00"u8.ToArray()), + new("LINT"u8.ToArray(), "+14:00"u8.ToArray()), + new("NRT"u8.ToArray(), "+12:00"u8.ToArray()), + + // Letter-only matching never selects these. Numeric ±hhmm and ±hh:mm offsets are parsed by the date patterns. new("UTC+0"u8.ToArray(), "+00:00"u8.ToArray()), new("UTC+1"u8.ToArray(), "+01:00"u8.ToArray()), new("UTC+2"u8.ToArray(), "+02:00"u8.ToArray()), diff --git a/tests/VectorNNTPD.Common.Tests/Articles/DateParser/NewsDateParserTests.cs b/tests/VectorNNTPD.Common.Tests/Articles/DateParser/NewsDateParserTests.cs index 130de77c..bb65846f 100644 --- a/tests/VectorNNTPD.Common.Tests/Articles/DateParser/NewsDateParserTests.cs +++ b/tests/VectorNNTPD.Common.Tests/Articles/DateParser/NewsDateParserTests.cs @@ -99,6 +99,223 @@ public void TryGetCanonicalUtc_WhenUnknownAbbreviationRequired_Rejects() Assert.Equal(DateParseFailureReason.UnknownTimezoneAbbreviation, failure); } + /// + /// Noon Central Standard Time is 18:00 UTC on the same calendar date. + /// RFC 1036 names CST as a North American abbreviation. The -06:00 mapping is the Issue #164 convention; the local RFC text does not state the numeric offset. + /// + [Fact] + public void TryGetCanonicalUtc_WhenCentralStandardTime_ReturnsEighteenHundredUtc() + { + var accepted = NewsDateParser.TryGetCanonicalUtc( + "Fri, 23 Aug 2024 12:00:00 CST"u8, + out var utc, + out var failure); + + Assert.True(accepted); + Assert.Equal(DateParseFailureReason.None, failure); + Assert.Equal(new DateTime(2024, 8, 23, 18, 0, 0, DateTimeKind.Utc), utc); + } + + /// + /// Noon Central Daylight Time is 17:00 UTC on the same calendar date. CDT stays -05:00. + /// + [Fact] + public void TryGetCanonicalUtc_WhenCentralDaylightTime_ReturnsSeventeenHundredUtc() + { + var accepted = NewsDateParser.TryGetCanonicalUtc( + "Fri, 23 Aug 2024 12:00:00 CDT"u8, + out var utc, + out var failure); + + Assert.True(accepted); + Assert.Equal(DateParseFailureReason.None, failure); + Assert.Equal(new DateTime(2024, 8, 23, 17, 0, 0, DateTimeKind.Utc), utc); + } + + /// + /// Each built-in letter abbreviation converts 12:00 on 23 Aug 2024 to the UTC instant of its documented offset. + /// Minutes are east of UTC. A west-of-UTC abbreviation therefore moves the result later on the same date, or onto the next date. + /// + /// Trailing timezone token. + /// Documented offset in minutes east of UTC. + [Theory] + [MemberData(nameof(KnownTimezoneAbbreviations))] + public void TryGetCanonicalUtc_WhenKnownAbbreviation_ReturnsDocumentedUtcInstant( + string abbreviation, + int offsetMinutesEast) + { + var accepted = NewsDateParser.TryGetCanonicalUtc( + Encoding.ASCII.GetBytes($"Fri, 23 Aug 2024 12:00:00 {abbreviation}"), + out var utc, + out var failure); + + var expected = new DateTime(2024, 8, 23, 12, 0, 0, DateTimeKind.Utc).AddMinutes(-offsetMinutesEast); + Assert.True(accepted); + Assert.Equal(DateParseFailureReason.None, failure); + Assert.Equal(expected, utc); + } + + /// + /// Abbreviation matching folds ASCII case, so a lowercase North American token keeps the uppercase offset. + /// + /// Mixed-case or lowercase token. + /// Documented offset in minutes east of UTC. + [Theory] + [InlineData("cst", -360)] + [InlineData("Cdt", -300)] + [InlineData("est", -300)] + [InlineData("pst", -480)] + [InlineData("aest", 600)] + [InlineData("npt", 345)] + [InlineData("chst", 600)] + public void TryGetCanonicalUtc_WhenAbbreviationCaseDiffers_ReturnsSameUtcInstant( + string abbreviation, + int offsetMinutesEast) + { + var accepted = NewsDateParser.TryGetCanonicalUtc( + Encoding.ASCII.GetBytes($"Fri, 23 Aug 2024 12:00:00 {abbreviation}"), + out var utc, + out var failure); + + var expected = new DateTime(2024, 8, 23, 12, 0, 0, DateTimeKind.Utc).AddMinutes(-offsetMinutesEast); + Assert.True(accepted); + Assert.Equal(DateParseFailureReason.None, failure); + Assert.Equal(expected, utc); + } + + /// + /// A longer trailing token is not split into a shorter known abbreviation. + /// ACST is +09:30, not Central CST. AEST is not EST. WEST and CEST are not EST. + /// WITA is not WIT. PETT is not PET. CHAST is not ChST. + /// + /// Longer trailing token. + /// Offset of that complete token, in minutes east of UTC. + [Theory] + [InlineData("ACST", 570)] + [InlineData("AEST", 600)] + [InlineData("WEST", 60)] + [InlineData("CEST", 120)] + [InlineData("WITA", 480)] + [InlineData("WIT", 540)] + [InlineData("WIB", 420)] + [InlineData("PETT", 720)] + [InlineData("PET", -300)] + [InlineData("CHAST", 765)] + [InlineData("CHADT", 825)] + [InlineData("ChST", 600)] + [InlineData("PHT", 480)] + [InlineData("PST", -480)] + [InlineData("BJT", 480)] + [InlineData("CST", -360)] + public void TryGetCanonicalUtc_WhenTokensShareLetters_UsesTheCompleteToken( + string abbreviation, + int offsetMinutesEast) + { + var accepted = NewsDateParser.TryGetCanonicalUtc( + Encoding.ASCII.GetBytes($"Fri, 23 Aug 2024 12:00:00 {abbreviation}"), + out var utc, + out var failure); + + var expected = new DateTime(2024, 8, 23, 12, 0, 0, DateTimeKind.Utc).AddMinutes(-offsetMinutesEast); + Assert.True(accepted); + Assert.Equal(DateParseFailureReason.None, failure); + Assert.Equal(expected, utc); + } + + /// + /// An abbreviation is only a trailing letter token after SP or HTAB. Letters glued to the time, or a word that merely ends in a known abbreviation, stay unknown. + /// + /// Date text that must not be rewritten as Central Standard Time. + [Theory] + [InlineData("Fri, 23 Aug 2024 12:00:00CST")] + [InlineData("Fri, 23 Aug 2024 12:00:00 FORECAST")] + public void TryGetCanonicalUtc_WhenAbbreviationIsNotATrailingToken_DoesNotApplyCst(string input) + { + var accepted = NewsDateParser.TryGetCanonicalUtc( + Encoding.ASCII.GetBytes(input), + out var utc, + out var failure); + + Assert.False(accepted); + Assert.Equal(DateParseFailureReason.ParseFailed, failure); + Assert.Equal(default, utc); + } + + /// + /// Without the strict option, an unknown letter token is left in place and exact parsing fails. + /// + [Fact] + public void TryGetCanonicalUtc_WhenUnknownAbbreviationIsTolerated_ReturnsParseFailed() + { + var accepted = NewsDateParser.TryGetCanonicalUtc( + "Fri, 23 Aug 2024 05:30:10 ZZQX"u8, + out _, + out var failure); + + Assert.False(accepted); + Assert.Equal(DateParseFailureReason.ParseFailed, failure); + } + + /// + /// Colliding abbreviations that this table refuses are unknown in strict mode, not silently assigned one region's offset. + /// + /// Omitted trailing token. + [Theory] + [InlineData("AST")] + [InlineData("ADT")] + [InlineData("GST")] + [InlineData("NST")] + [InlineData("NDT")] + [InlineData("AMT")] + [InlineData("ECT")] + [InlineData("WST")] + [InlineData("SST")] + public void TryGetCanonicalUtc_WhenOmittedCollisionIsStrict_RejectsUnknownAbbreviation(string abbreviation) + { + var options = DateParseOptions.Default with { RequireKnownTimezoneAbbreviation = true }; + var accepted = NewsDateParser.TryGetCanonicalUtc( + Encoding.ASCII.GetBytes($"Fri, 23 Aug 2024 12:00:00 {abbreviation}"), + options, + out _, + out var failure); + + Assert.False(accepted); + Assert.Equal(DateParseFailureReason.UnknownTimezoneAbbreviation, failure); + } + + /// + /// UTC+1 is not a letter token, so the abbreviation table does not rewrite it and numeric-offset parsing does not accept that spelling. + /// + [Fact] + public void TryGetCanonicalUtc_WhenUtcPlusDigitForm_IsNotAnAbbreviationMatch() + { + var options = DateParseOptions.Default with { RequireKnownTimezoneAbbreviation = true }; + var accepted = NewsDateParser.TryGetCanonicalUtc( + "Fri, 23 Aug 2024 12:00:00 UTC+1"u8, + options, + out _, + out var failure); + + Assert.False(accepted); + Assert.Equal(DateParseFailureReason.ParseFailed, failure); + } + + /// + /// A fractional numeric offset is still parsed on the numeric path and is not confused with an abbreviation. + /// + [Fact] + public void TryGetCanonicalUtc_WhenFractionalNumericOffsetPresent_ReturnsUtc() + { + var accepted = NewsDateParser.TryGetCanonicalUtc( + "Fri, 23 Aug 2024 12:00:00 +0530"u8, + out var utc, + out var failure); + + Assert.True(accepted); + Assert.Equal(DateParseFailureReason.None, failure); + Assert.Equal(new DateTime(2024, 8, 23, 6, 30, 0, DateTimeKind.Utc), utc); + } + /// /// Input one byte longer than is rejected with . /// @@ -112,6 +329,129 @@ public void TryGetCanonicalUtc_WhenTooLong_Rejects() Assert.Equal(DateParseFailureReason.TooLong, failure); } + /// + /// Built-in letter abbreviations and their documented minutes east of UTC. + /// UTC+N rows are excluded because the letter-run detector does not select them. + /// + /// Pairs of abbreviation and offset minutes. + public static IEnumerable KnownTimezoneAbbreviations() + { + (string Abbreviation, int OffsetMinutesEast)[] rows = + [ + ("UT", 0), + ("UTC", 0), + ("GMT", 0), + ("EST", -300), + ("EDT", -240), + ("CST", -360), + ("CDT", -300), + ("MST", -420), + ("MDT", -360), + ("PST", -480), + ("PDT", -420), + ("AKST", -540), + ("AKDT", -480), + ("HST", -600), + ("WET", 0), + ("WEST", 60), + ("CET", 60), + ("CEST", 120), + ("MET", 60), + ("MEST", 120), + ("EET", 120), + ("EEST", 180), + ("BST", 60), + ("MSK", 180), + ("MSD", 240), + ("TRT", 180), + ("ART", -180), + ("BRT", -180), + ("BRST", -120), + ("CLT", -240), + ("CLST", -180), + ("COT", -300), + ("PET", -300), + ("BOT", -240), + ("GYT", -240), + ("SRT", -180), + ("UYT", -180), + ("GFT", -180), + ("PMST", -180), + ("PMDT", -120), + ("WAT", 60), + ("WAST", 120), + ("CAT", 120), + ("EAT", 180), + ("SAST", 120), + ("IRST", 210), + ("IRDT", 270), + ("AFT", 270), + ("PKT", 300), + ("IST", 330), + ("NPT", 345), + ("LKT", 330), + ("MMT", 390), + ("BTT", 360), + ("IDT", 180), + ("AZT", 240), + ("AZST", 300), + ("GET", 240), + ("ICT", 420), + ("WIB", 420), + ("WITA", 480), + ("WIT", 540), + ("HKT", 480), + ("SGT", 480), + ("BJT", 480), + ("PHT", 480), + ("MYT", 480), + ("BNT", 480), + ("JST", 540), + ("KST", 540), + ("ULAT", 480), + ("HOVT", 420), + ("KGT", 360), + ("UZT", 300), + ("TMT", 300), + ("TJT", 300), + ("YEKT", 300), + ("OMST", 360), + ("NOVT", 420), + ("KRAT", 420), + ("IRKT", 480), + ("YAKT", 540), + ("VLAT", 600), + ("PETT", 720), + ("AWST", 480), + ("AWDT", 540), + ("ACST", 570), + ("ACDT", 630), + ("AEST", 600), + ("AEDT", 660), + ("LHST", 630), + ("LHDT", 660), + ("NZST", 720), + ("NZDT", 780), + ("CHAST", 765), + ("CHADT", 825), + ("ChST", 600), + ("TAHT", -600), + ("MART", -570), + ("CKT", -600), + ("FJT", 720), + ("TOT", 780), + ("GILT", 720), + ("PHOT", 780), + ("LINT", 840), + ("NRT", 720), + ]; + + foreach (var row in rows) + { + yield return new object[] { row.Abbreviation, row.OffsetMinutesEast }; + } + } + /// /// Formats with and returns the ASCII text. ///