diff --git a/src/ImageSharp/Metadata/Profiles/IPTC/IptcProfile.cs b/src/ImageSharp/Metadata/Profiles/IPTC/IptcProfile.cs index cd3c8eb93..a46d2745f 100644 --- a/src/ImageSharp/Metadata/Profiles/IPTC/IptcProfile.cs +++ b/src/ImageSharp/Metadata/Profiles/IPTC/IptcProfile.cs @@ -199,8 +199,8 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Iptc /// A time value will be formatted as HHMMSS±HHMM. /// /// The tag of the iptc value. - /// The datetime. - public void SetDateTimeValue(IptcTag tag, DateTime dateTime) + /// The datetime. + public void SetDateTimeValue(IptcTag tag, DateTimeOffset dateTimeOffset) { if (!tag.IsDate() && !tag.IsTime()) { @@ -208,8 +208,9 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Iptc } var formattedDate = tag.IsDate() - ? dateTime.ToString("yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture) - : dateTime.ToString("HHmmsszzzz", System.Globalization.CultureInfo.InvariantCulture).Replace(":", string.Empty); + ? dateTimeOffset.ToString("yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture) + : dateTimeOffset.ToString("HHmmsszzzz", System.Globalization.CultureInfo.InvariantCulture) + .Replace(":", string.Empty); this.SetValue(tag, Encoding.UTF8, formattedDate); } diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/IPTC/IptcProfileTests.cs b/tests/ImageSharp.Tests/Metadata/Profiles/IPTC/IptcProfileTests.cs index 9d5db439a..d9f44cef9 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/IPTC/IptcProfileTests.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/IPTC/IptcProfileTests.cs @@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.IPTC { // arrange var profile = new IptcProfile(); - var datetime = new DateTime(1994, 3, 17); + var datetime = new DateTimeOffset(new DateTime(1994, 3, 17)); // act profile.SetDateTimeValue(tag, datetime); @@ -70,14 +70,15 @@ namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.IPTC { // arrange var profile = new IptcProfile(); - DateTime datetime = new DateTimeOffset(new DateTime(1994, 3, 17, 14, 15, 16), new TimeSpan(1, 0, 0)).DateTime; + var dateTimeUtc = new DateTime(1994, 3, 17, 14, 15, 16, DateTimeKind.Utc); + DateTimeOffset dateTimeOffset = new DateTimeOffset(dateTimeUtc).ToOffset(TimeSpan.FromHours(2)); // act - profile.SetDateTimeValue(tag, datetime); + profile.SetDateTimeValue(tag, dateTimeOffset); // assert IptcValue actual = profile.GetValues(tag).First(); - Assert.Equal("141516+0100", actual.Value); + Assert.Equal("161516+0200", actual.Value); } [Theory]