Skip to content

Commit 69c3285

Browse files
committed
Add more date parse patterns with time-zone offsets
1 parent fa99f62 commit 69c3285

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

MetadataExtractor.Tests/DirectoryTest.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,28 @@ public void SetAndGetIntArray()
9191
[InlineData("2002:01:30 23:59", 2002, 1, 30, 23, 59, 0, 0, DateTimeKind.Unspecified)]
9292
[InlineData("2002-01-30 23:59:59", 2002, 1, 30, 23, 59, 59, 0, DateTimeKind.Unspecified)]
9393
[InlineData("2002-01-30 23:59", 2002, 1, 30, 23, 59, 0, 0, DateTimeKind.Unspecified)]
94-
// [InlineData("2002-01-30T23:59:59.099-08:00", 2002, 1, 30, 23, 59, 59, 99, DateTimeKind.Unspecified)]
94+
[InlineData("2002-01-30T23:59:59.099-08:00", 2002, 1, 31, 7, 59, 59, 99, DateTimeKind.Utc)]
95+
[InlineData("2002-01-30T23:59:59.9", 2002, 1, 30, 23, 59, 59,900, DateTimeKind.Unspecified)]
96+
[InlineData("2002-01-30T23:59:59.09", 2002, 1, 30, 23, 59, 59, 90, DateTimeKind.Unspecified)]
9597
[InlineData("2002-01-30T23:59:59.099", 2002, 1, 30, 23, 59, 59, 99, DateTimeKind.Unspecified)]
96-
// [InlineData("2002-01-30T23:59:59-08:00", 2002, 1, 30, 23, 59, 59, 0, DateTimeKind.Unspecified)]
98+
[InlineData("2002-01-30T23:59:59-08:00", 2002, 1, 31, 7, 59, 59, 0, DateTimeKind.Utc)]
9799
[InlineData("2002-01-30T23:59:59", 2002, 1, 30, 23, 59, 59, 0, DateTimeKind.Unspecified)]
98-
// [InlineData("2002-01-30T23:59-08:00", 2002, 1, 30, 23, 59, 0, 0, DateTimeKind.Unspecified)]
100+
[InlineData("2002-01-30T23:59:59+0100", 2002, 1, 30, 22, 59, 59, 0, DateTimeKind.Utc)]
101+
[InlineData("2002-01-30T23:59-08:00", 2002, 1, 31, 7, 59, 0, 0, DateTimeKind.Utc)]
99102
[InlineData("2002-01-30T23:59", 2002, 1, 30, 23, 59, 0, 0, DateTimeKind.Unspecified)]
100103
[InlineData("2002-01-30", 2002, 1, 30, 0, 0, 0, 0, DateTimeKind.Unspecified)]
101104
[InlineData("2002-01", 2002, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)]
102105
[InlineData("2002", 2002, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)]
103106
#pragma warning restore format
104107
public void SetStringAndGetDate(string str, int year, int month, int day, int hour, int minute, int second, int milli, DateTimeKind kind)
105108
{
109+
_directory.Set(1, str);
110+
106111
var expected = new DateTime(year, month, day, hour, minute, second, milli, kind);
112+
var actual = _directory.GetDateTime(1);
107113

108-
_directory.Set(1, str);
109-
Assert.Equal(expected, _directory.GetDateTime(1));
114+
Assert.Equal(expected.Kind, actual.Kind);
115+
Assert.Equal(expected, actual);
110116

111117
// TODO revisit these commented cases and introduce GetDateTimeOffset impl/test
112118
}

MetadataExtractor/DirectoryExtensions.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,18 +597,29 @@ public static DateTime GetDateTime(this Directory directory, int tagType /*, Tim
597597
private static readonly string[] _datePatterns =
598598
{
599599
"yyyy:MM:dd HH:mm:ss.fff",
600+
"yyyy:MM:dd HH:mm:ss.fffzzz",
600601
"yyyy:MM:dd HH:mm:ss",
602+
"yyyy:MM:dd HH:mm:sszzz",
601603
"yyyy:MM:dd HH:mm",
604+
"yyyy:MM:dd HH:mmzzz",
605+
"yyyy-MM-dd HH:mm:ss.fff",
606+
"yyyy-MM-dd HH:mm:ss.fffzzz",
602607
"yyyy-MM-dd HH:mm:ss",
608+
"yyyy-MM-dd HH:mm:sszzz",
603609
"yyyy-MM-dd HH:mm",
610+
"yyyy-MM-dd HH:mmzzz",
604611
"yyyy.MM.dd HH:mm:ss",
612+
"yyyy.MM.dd HH:mm:sszzz",
605613
"yyyy.MM.dd HH:mm",
614+
"yyyy.MM.dd HH:mmzzz",
606615
"yyyy-MM-ddTHH:mm:ss.fff",
616+
"yyyy-MM-ddTHH:mm:ss.fffzzz",
607617
"yyyy-MM-ddTHH:mm:ss.ff",
608618
"yyyy-MM-ddTHH:mm:ss.f",
609619
"yyyy-MM-ddTHH:mm:ss",
610620
"yyyy-MM-ddTHH:mm:sszzz",
611621
"yyyy-MM-ddTHH:mm",
622+
"yyyy-MM-ddTHH:mmzzz",
612623
"yyyy:MM:dd",
613624
"yyyy-MM-dd",
614625
"yyyy-MM",

0 commit comments

Comments
 (0)