/// <summary> /// Makes sure the datetime is formatted according to the iptc specification. /// <example> /// A date will be formatted as CCYYMMDD, e.g. "19890317" for 17 March 1989. /// A time value will be formatted as HHMMSS±HHMM, e.g. "090000+0200" for 9 o'clock Berlin time, /// two hours ahead of UTC. /// </example> /// </summary> /// <param name="tag">The tag of the iptc value.</param> /// <param name="dateTimeOffset">The datetime.</param> public void SetValue(IptcTag tag, DateTimeOffset dateTimeOffset) { var isDate = IptcTagHelper.IsDate(tag); if (!isDate && !IptcTagHelper.IsTime(tag)) { throw new ArgumentException("iptc tag is not a time or date type", nameof(tag)); } var formattedDate = isDate ? dateTimeOffset.ToString("yyyyMMdd", CultureInfo.InvariantCulture) : dateTimeOffset.ToString("HHmmsszzzz", CultureInfo.InvariantCulture).Replace(":", string.Empty); SetValue(tag, formattedDate); }
/// <summary> /// Sets the value of the specified tag. /// </summary> /// <param name="tag">The tag of the iptc value.</param> /// <param name="value">The value.</param> public void SetValue(IptcTag tag, string value) { Initialize(); if (!IptcTagHelper.IsRepeatable(tag)) { foreach (var iptcValue in _values) { if (iptcValue.Tag == tag) { iptcValue.Value = value; return; } } } _values.Add(new IptcValue(tag, value)); }