Skip to content

Commit e22066e

Browse files
committed
Fix %C format (c++98 standard) [skip ci]
1 parent 23aeebc commit e22066e

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

StrftimeParser/Strftime.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,12 @@ public static DateTime Parse(string input, string format, CultureInfo culture)
108108
// Year divided by 100
109109
if (elements.YearDividedBy100 != null)
110110
{
111-
var yearDivided = Formatter.ParseYearDividedBy100(elements.YearDividedBy100);
112-
if (year != null && !yearDivided.Equals(year / 100)) throw new FormatException("Incoherent year");
113-
year = yearDivided * 100;
111+
if (year == null) year = 1970;
112+
else
113+
{
114+
var yearDivided = Formatter.ParseYearDividedBy100(elements.YearDividedBy100);
115+
if (year != null && !yearDivided.Equals(year / 100)) throw new FormatException("Incoherent year");
116+
}
114117
}
115118

116119
// Day of the month

test/StrftimeParserTest/ParserTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ public void ParseShortYyyyMmDd(string input, string format, int year, int month,
155155
}
156156

157157
[Theory]
158-
[InlineData("20", "%C", 2000)]
159-
[InlineData("23", "%C", 2300)]
160-
[InlineData("19", "%C", 1900)]
161-
[InlineData("03", "%C", 300)]
162-
[InlineData("20 2023", "%C %Y", 2000)]
163-
[InlineData("19 1975", "%C %Y", 1900)]
158+
[InlineData("20", "%C", 1970)]
159+
[InlineData("23", "%C", 1970)]
160+
[InlineData("19", "%C", 1970)]
161+
[InlineData("03", "%C", 1970)]
162+
[InlineData("20 2023", "%C %Y", 2023)]
163+
[InlineData("19 1975", "%C %Y", 1975)]
164164
public void ParseYearDividedBy100(string input, string format, int expectedYear)
165165
{
166166
var res = Strftime.Parse(input, format, _culture);

0 commit comments

Comments
 (0)