Skip to content

Feature request: option to use "Z" tz label in format_ISO8601() output #941

@francisbarton

Description

@francisbarton

This suggestion references @billdenney 's comment in #629, with the addition of a specific use case.

Bill wrote:

I didn't do the additional formatting for adding Z instead of -0000 for UTC because that would have added a notable amount more code. I can do it, but the longer-term maintenance didn't seem like it was worthwhile. If you'd like Z, I can make that update.

Example use case

The Twitter API v2 (example) currently only accepts YYYY-MM-DDTHH:mm:ssZ format for the start_time and end_time query parameters. Passing in YYYY-MM-DDTHH:mm:ss+0000 format results in a HTTP 400 Bad Request error. This makes it incompatible with lubridate::format_ISO8601()'s output.

lubridate::format_ISO8601(
  lubridate::make_datetime(2019),
  usetz = TRUE)
#> [1] "2019-01-01T00:00:00+0000"

It's not difficult for me to construct the "Z" format locally within my script and use that, but it would be great if this could be made part of lubridate's capability. Something like:

# pseudocode
lubridate::format_ISO8601(
  lubridate::make_datetime(2019),
  use_z_format = TRUE)
#> [1] "2019-01-01T00:00:00Z"

This option obviously is only appropriate when the tz is UTC, or more realistically, where no timezone is stipulated. Would require some thought as to how it would work in cases when a date with a timezone is passed in. Just return an error, I suppose.

I'm happy to work on a PR to try to provide this feature, but I haven't looked into the code yet.

PS I'm adding the inverse feature suggestion on Twitter's API feedback forum - that they should accept all valid ISO8601 datetime formats, but we don't have much control over what they do!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions