Browse Source

SetDateTimeValue now uses DateTimeOffset

pull/1574/head
Brian Popow 6 years ago
parent
commit
8f94e08b58
  1. 9
      src/ImageSharp/Metadata/Profiles/IPTC/IptcProfile.cs
  2. 9
      tests/ImageSharp.Tests/Metadata/Profiles/IPTC/IptcProfileTests.cs

9
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.
/// </summary>
/// <param name="tag">The tag of the iptc value.</param>
/// <param name="dateTime">The datetime.</param>
public void SetDateTimeValue(IptcTag tag, DateTime dateTime)
/// <param name="dateTimeOffset">The datetime.</param>
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);
}

9
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]

Loading…
Cancel
Save