From a0fa54238cfb09905cce5c538ee97c060675e230 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Luthi?= Date: Mon, 9 May 2022 17:24:49 +0200 Subject: [PATCH 1/3] Add a test covering parsing of local time Currently, the test case with hour == 0 fails with the following exception: > Tomlyn.TomlException : (1,8) : error : Unable to parse the date time/offset `048:32:00.000` --- src/Tomlyn.Tests/BasicTests.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Tomlyn.Tests/BasicTests.cs b/src/Tomlyn.Tests/BasicTests.cs index d8c742d..06f86db 100644 --- a/src/Tomlyn.Tests/BasicTests.cs +++ b/src/Tomlyn.Tests/BasicTests.cs @@ -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() { From f888717e4041ca9f42963648f0acab16d2245bf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Luthi?= Date: Mon, 9 May 2022 17:36:41 +0200 Subject: [PATCH 2/3] Fix parsing of local time starting with "0" --- src/Tomlyn/Parsing/Lexer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tomlyn/Parsing/Lexer.cs b/src/Tomlyn/Parsing/Lexer.cs index c10a4d3..c98f7c1 100644 --- a/src/Tomlyn/Parsing/Lexer.cs +++ b/src/Tomlyn/Parsing/Lexer.cs @@ -525,7 +525,7 @@ private void ReadNumberOrDate(char32? signPrefix = null, TextPosition? signPrefi previousCharIsDigit = _c == '0'; if (previousCharIsDigit) { - _textBuilder.Append(_c); + _textBuilder.Append(_c.ToString()); zeroDigit++; } end = _position; From b07f3889e9b75930f324b8db1467b9e8137b523d Mon Sep 17 00:00:00 2001 From: Alexandre Mutel Date: Mon, 9 May 2022 19:51:47 +0200 Subject: [PATCH 3/3] Update src/Tomlyn/Parsing/Lexer.cs --- src/Tomlyn/Parsing/Lexer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tomlyn/Parsing/Lexer.cs b/src/Tomlyn/Parsing/Lexer.cs index c98f7c1..5497851 100644 --- a/src/Tomlyn/Parsing/Lexer.cs +++ b/src/Tomlyn/Parsing/Lexer.cs @@ -525,7 +525,7 @@ private void ReadNumberOrDate(char32? signPrefix = null, TextPosition? signPrefi previousCharIsDigit = _c == '0'; if (previousCharIsDigit) { - _textBuilder.Append(_c.ToString()); + _textBuilder.Append((char)_c); zeroDigit++; } end = _position;