Struct xmp_toolkit::XmpDateTime
source · pub struct XmpDateTime {
pub date: Option<XmpDate>,
pub time: Option<XmpTime>,
}
Expand description
Represents the concept of date and time as expressed in XMP.
XMP understands a close variant of the ISO8601 format, where date, time,
and time zone are all optional fields. These possibilities are expressed
using Option
s.
All of the fields are signed 32 bit integers, even though most could be 8 bit. (The same is true in the underlying C++ XMP Toolkit.) This avoids overflow when doing carries for arithmetic or normalization.
The DateTime
struct in the chrono
crate
is similar to this struct, but does not provide a way to express
the optionality of date, time, and time zone in a single struct. For that
reason, we did not use it in this crate.
Enable crate feature chrono
to enable conversions between this struct
and chrono::DateTime<FixedOffset>
.
Fields§
§date: Option<XmpDate>
The date, if known.
time: Option<XmpTime>
The time, if known.
Implementations§
source§impl XmpDateTime
impl XmpDateTime
sourcepub fn current() -> XmpResult<Self>
pub fn current() -> XmpResult<Self>
Creates a new date-time struct reflecting the current time.
sourcepub fn set_local_time_zone(&mut self) -> XmpResult<()>
pub fn set_local_time_zone(&mut self) -> XmpResult<()>
Sets the time zone to the local time zone.
Can only be used when there is a time with no existing time zone
(i.e. self.time.time_zone.is_none()
). It is an error to call this
function with an existing time zone.
In that case, the time zone value is replaced with the local time zone. The other date/time fields are not adjusted in any way.
sourcepub fn convert_to_local_time(&mut self) -> XmpResult<()>
pub fn convert_to_local_time(&mut self) -> XmpResult<()>
Translate the value to the local time zone.
If the time zone is not the local zone, the time is adjusted and the time zone set to be local. The value is not modified if the time zone is already the local zone or if the value has no time zone.
sourcepub fn convert_to_utc(&mut self) -> XmpResult<()>
pub fn convert_to_utc(&mut self) -> XmpResult<()>
Translates the value to UTC (Coordinated Universal Time).
If the time zone is not UTC, the time is adjusted and the time zone set to be UTC. The value is not modified if the time zone is already UTC or if the value has no time zone.
Trait Implementations§
source§impl Clone for XmpDateTime
impl Clone for XmpDateTime
source§fn clone(&self) -> XmpDateTime
fn clone(&self) -> XmpDateTime
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for XmpDateTime
impl Debug for XmpDateTime
source§impl Default for XmpDateTime
impl Default for XmpDateTime
source§fn default() -> XmpDateTime
fn default() -> XmpDateTime
source§impl Display for XmpDateTime
impl Display for XmpDateTime
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats a date according to the ISO 8601 profile in https://www.w3.org/TR/NOTE-datetime.
The format will be one of the following:
YYYY
YYYY-MM-DD
YYYY-MM-DDThh:mmTZD
YYYY-MM-DDThh:mm:ssTZD
YYYY-MM-DDThh:mm:ss.sTZD
Where:
YYYY
= four-digit yearMM
= two-digit month (01=January)DD
= two-digit day of month (01 through 31)hh
= two digits of hour (00 through 23)mm
= two digits of minute (00 through 59)ss
= two digits of second (00 through 59)s
= one or more digits representing a decimal fraction of a secondTZD
= time zone designator (Z
or+hh:mm
or-hh:mm
)
XMP allows time-only values (date
= None
). In this case, the date
portion of the output will be 0000-01-01
.
NOTE: ISO 8601 does not allow years less than 1000 or greater than
9999. XmpDateTime
allows any year, even negative ones. The W3C
profile also requires a time zone designator if a time is present;
since XmpDateTime
has an explicit notion of zone-less time, the
TZD
will not appear in that case.
source§impl From<&DateTime<FixedOffset>> for XmpDateTime
impl From<&DateTime<FixedOffset>> for XmpDateTime
source§fn from(dt: &DateTime<FixedOffset>) -> Self
fn from(dt: &DateTime<FixedOffset>) -> Self
source§impl From<DateTime<FixedOffset>> for XmpDateTime
impl From<DateTime<FixedOffset>> for XmpDateTime
source§fn from(dt: DateTime<FixedOffset>) -> Self
fn from(dt: DateTime<FixedOffset>) -> Self
source§impl PartialEq for XmpDateTime
impl PartialEq for XmpDateTime
source§fn eq(&self, other: &XmpDateTime) -> bool
fn eq(&self, other: &XmpDateTime) -> bool
self
and other
values to be equal, and is used
by ==
.