Search code examples
xmldateformaticloudcaldav

Date format in CalDav Propfind response - How to change it?


I am trying to set up a CalDav Client vor iCloud. I am using the following PROPFIND http curl:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<d:propfind xmlns:d="DAV:" xmlns:cs="http://calendarserver.org/ns/">

  <d:prop>
    <d:displayname/>
    <cs:getctag/>
    <d:resource-class/>
    <d:getlastmodified/>
  </d:prop>

</d:propfind>

The response is something like this:

    <getlastmodified>Mon, 22 Jan 2018 20:03:49 GMT</getlastmodified>
    <creationdate>2013-04-02T20:12:23Z</creationdate>
    <auto-provisioned xmlns="urn:mobileme:server-to-server"/>

I know want to know if I can get the format of the tag in a different format? Best would be something like 2013-04-02T20:12:23Z.

Thank you very much!


Solution

  • I assume by "tag" you mean the getlastmodified property, which returns this date:

    Mon, 22 Jan 2018 20:03:49 GMT
    

    and you are asking whether you can make the server return that date in a different format. No you can't, the format of the getlastmodified WebDAV property is standardized to be a rfc1123-date in the WebDAV RFC (4918).

    IMPORTANT: getlastmodified is not a tag! If you need a tag to do synchronization, use the ETag. The Building a CalDAV client document explains this well.

    What you can do is parse and reformat your curl output in the shell. You could use xmlstarlet or another tool to do this:

    lastmod=$(curl ... | xmlstarlet sel -N x="DAV:" -t -v "//x:getlastmodified")
    date -jf \
      "%a, %d %b %Y %H:%M:%S GMT" \
      +"%Y-%M-%dT%H:%M:%SZ" \
      "${lastmod}"
    

    ... adjust to your needs.