Skip to content

Commit fa99f62

Browse files
committed
Convert parsed dates with offsets to UTC
Without this, they're reported in local time.
1 parent b5b1d98 commit fa99f62

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

MetadataExtractor/DirectoryExtensions.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,15 @@ public static DateTime GetDateTime(this Directory directory, int tagType /*, Tim
617617
};
618618

619619
/// <summary>Attempts to return the specified tag's value as a DateTime.</summary>
620-
/// <remarks>If the underlying value is a <see cref="string"/>, then attempts will be made to parse it.</remarks>
620+
/// <remarks>
621+
/// <para>
622+
/// If the underlying value is a <see cref="string"/>, then attempts will be made to parse it.
623+
/// </para>
624+
/// <para>
625+
/// If that string contains a time-zone offset, the returned <see cref="DateTime"/> will have kind <see cref="DateTimeKind.Utc"/>,
626+
/// otherwise it will be <see cref="DateTimeKind.Unspecified"/>.
627+
/// </para>
628+
/// </remarks>
621629
/// <returns><c>true</c> if a DateTime was returned, otherwise <c>false</c>.</returns>
622630
[Pure]
623631
public static bool TryGetDateTime(this Directory directory, int tagType /*, TimeZoneInfo? timeZone = null*/, out DateTime dateTime)
@@ -643,8 +651,10 @@ public static bool TryGetDateTime(this Directory directory, int tagType /*, Time
643651

644652
if (s != null)
645653
{
646-
if (DateTime.TryParseExact(s, _datePatterns, null, DateTimeStyles.AllowWhiteSpaces, out dateTime))
654+
if (DateTime.TryParseExact(s, _datePatterns, null, DateTimeStyles.AllowWhiteSpaces | DateTimeStyles.AdjustToUniversal, out dateTime))
655+
{
647656
return true;
657+
}
648658

649659
dateTime = default;
650660
return false;

0 commit comments

Comments
 (0)