Skip to content

Commit

Permalink
Pass format provider through to formatter
Browse files Browse the repository at this point in the history
When using the default format string, callers still want to be able to
specify a formatter to make sure that dates are formatted in their
preferred way.
  • Loading branch information
nzbart authored and axunonb committed Nov 3, 2024
1 parent a110b33 commit d27dd56
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Ical.Net.Tests/CalDateTimeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ public static IEnumerable<ITestCaseData> ToStringTestCases()
yield return new TestCaseData(new DateTime(2022, 8, 30), "o", null)
.Returns("2022-08-30T00:00:00.0000000+12:00 Pacific/Auckland")
.SetName("Date and time formatted using format string with no culture returns string using BCL formatter");

yield return new TestCaseData(new DateTime(2022, 8, 30, 10, 30, 0), null, CultureInfo.InvariantCulture)
.Returns("08/30/2022 10:30:00 Pacific/Auckland")
.SetName("Date and time with format provider");

yield return new TestCaseData(new DateTime(2022, 8, 30), null, CultureInfo.InvariantCulture)
.Returns("08/30/2022 Pacific/Auckland")
.SetName("Date only with current format provider");
}
}
}
4 changes: 2 additions & 2 deletions Ical.Net/DataTypes/CalDateTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -538,13 +538,13 @@ public string ToString(string format, IFormatProvider formatProvider)
}
if (HasTime && HasDate)
{
return Value + tz;
return Value.ToString(formatProvider) + tz;
}
if (HasTime)
{
return Value.TimeOfDay + tz;
}
return Value.ToString("d") + tz;
return Value.ToString("d", formatProvider) + tz;
}
}
}

0 comments on commit d27dd56

Please sign in to comment.