webdav_xml/properties/
creationdate.rs

1// SPDX-FileCopyrightText: d-k-bo <d-k-bo@mailbox.org>
2//
3// SPDX-License-Identifier: MIT OR Apache-2.0
4
5use time::{format_description::well_known::Rfc3339, OffsetDateTime};
6
7use crate::{Element, Error, Value, DAV_NAMESPACE, DAV_PREFIX};
8
9/// The `creationdate` property as defined in [RFC 4918](http://webdav.org/specs/rfc4918.html#PROPERTY_creationdate).
10#[derive(Clone, Debug, PartialEq)]
11pub struct CreationDate(pub OffsetDateTime);
12
13impl Element for CreationDate {
14    const NAMESPACE: &'static str = DAV_NAMESPACE;
15    const PREFIX: &'static str = DAV_PREFIX;
16    const LOCAL_NAME: &'static str = "creationdate";
17}
18
19impl TryFrom<&Value> for CreationDate {
20    type Error = Error;
21
22    fn try_from(value: &Value) -> Result<Self, Self::Error> {
23        OffsetDateTime::parse(value.to_str()?, &Rfc3339)
24            .map(Self)
25            .map_err(Error::other)
26    }
27}
28
29impl From<CreationDate> for Value {
30    fn from(CreationDate(datetime): CreationDate) -> Value {
31        datetime.format(&Rfc3339).unwrap().into()
32    }
33}