Skip to content

Commit

Permalink
Merge pull request #36 from 0xced/fix-local-time-parsing
Browse files Browse the repository at this point in the history
Fix parsing of local time starting with "0"
  • Loading branch information
xoofx committed May 9, 2022
2 parents e16e8aa + b07f388 commit ff0296f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/Tomlyn.Tests/BasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ public void TestHelloWorld()
Assert.AreEqual(new TomlArray() { 4, 5, 6 }, list);
}

[Test]
[TestCase(7, 32, 0, 0)]
[TestCase(7, 32, 0, 999)]
[TestCase(0, 32, 0, 0)]
public void TestLocalTime(int hour, int minute, int second, int millisecond)
{
var toml = $@"time = {hour:D2}:{minute:D2}:{second:D2}.{millisecond:D3}";
var localTime = (TomlDateTime)Toml.ToModel(toml)["time"];

Assert.AreEqual(hour, localTime.DateTime.Hour);
Assert.AreEqual(minute, localTime.DateTime.Minute);
Assert.AreEqual(second, localTime.DateTime.Second);
Assert.AreEqual(millisecond, localTime.DateTime.Millisecond);
}

[Test]
public void TestHelloWorldWithCustomModel()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Tomlyn/Parsing/Lexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ private void ReadNumberOrDate(char32? signPrefix = null, TextPosition? signPrefi
previousCharIsDigit = _c == '0';
if (previousCharIsDigit)
{
_textBuilder.Append(_c);
_textBuilder.Append((char)_c);
zeroDigit++;
}
end = _position;
Expand Down

0 comments on commit ff0296f

Please sign in to comment.