You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ISO 8601 allows for "representations with reduced accuracy," meaning that you can omit certain components of the date and time if they are not relevant or available. Here are some examples:
Date Only:
YYYY-MM-DD (complete)
YYYY-MM (reduced accuracy, no day)
YYYY (reduced accuracy, no month or day)
Time Only:
HH:MM:SS (complete)
HH:MM (reduced accuracy, no seconds)
HH (reduced accuracy, no minutes or seconds)
Combined Date and Time:
YYYY-MM-DDTHH:MM:SS (complete)
YYYY-MM-DDTHH:MM (reduced accuracy, no seconds)
YYYY-MM-DDTHH (reduced accuracy, no minutes or seconds)
Is this supported in clock? I mean, is there a way to generate ISO 8601 strings with missing components, and indicate how those missing components are represented, e.g. with an hyphen? Are clock functions' implementation, in one way or the other, always going through strftime() or strptime()? As far as I understand these functions always impute the missing values to 0. Is there any low-level parser that collects all date-time components into a list before missing elements are converted to default values?
Here are examples of ISO 8601 dates or date-times that illustrate what I would like to achieve:
From
Precision
To
December 15, 2003 13:14
Unknown seconds
2003-12-15T13:14
December 15, 2003 13
Unknown minutes and seconds
2003-12-15T13
December 15, 2003
Unknown time
2003-12-15
December, 2003
Unknown day and time
2003-12
2003
Unknown month, day, and time
2003
Between 10:00 and 10:30 on the morning of December 15, 2003
2003-12-15T10:00/2003-12-15T10:30
Between the first of this year (2003) until "now" (February 15, 2003)
2003-01-01/2003-02-15
December 15, 2003 ??:15
Unknown hour with known minutes
2003-12-15T-:15
December 15, 2003 13:??:17
Unknown minutes with known date, hours, and seconds
2003-12-15T13:-:17
The 15th of some month in 2003, time not collected
Unknown month and time with known year and day
2003---15
December 15, but can't remember the year, time not collected
Unknown year with known month and day
--12-15
7:15 of some unknown date
Unknown date with known hour and minute
-----T07:15
The text was updated successfully, but these errors were encountered:
There is two parts of your questions: 1) reduced precision and 2) missing (lower precision) components
{clock} supports formatting at reduced precision. You can also explicitly set the precision of clock datetimes and the formatting will automatically adjust although I think you can also adjust the precision in the formatting methods with a custom format string:
Maybe something has changed recently but last I checked {clock} didn't have good support for unknown components when you have a known more precise component. If this is important for you then for now you may want to look at {parttime} and/or (my own) {datetimeoffset}. In particular {datetimeoffset} has some limited support for the Extended Date/Time Format (EDTF) extension of ISO 8601:
library("datetimeoffset")
# Unknown year with known month and day
as_datetimeoffset("XXXX-12-15") |> format_edtf()
[1] "XXXX-12-15"
# Unknown month with known year and day
as_datetimeoffset("2003-XX-15") |> format_edtf()
ISO 8601 allows for "representations with reduced accuracy," meaning that you can omit certain components of the date and time if they are not relevant or available. Here are some examples:
Is this supported in clock? I mean, is there a way to generate ISO 8601 strings with missing components, and indicate how those missing components are represented, e.g. with an hyphen? Are clock functions' implementation, in one way or the other, always going through
strftime()
orstrptime()
? As far as I understand these functions always impute the missing values to 0. Is there any low-level parser that collects all date-time components into a list before missing elements are converted to default values?Here are examples of ISO 8601 dates or date-times that illustrate what I would like to achieve:
December 15, 2003 13:14
2003-12-15T13:14
December 15, 2003 13
2003-12-15T13
December 15, 2003
2003-12-15
December, 2003
2003-12
2003
2003
Between 10:00 and 10:30 on the morning of December 15, 2003
2003-12-15T10:00/2003-12-15T10:30
Between the first of this year (2003) until "now" (February 15, 2003)
2003-01-01/2003-02-15
December 15, 2003 ??:15
2003-12-15T-:15
December 15, 2003 13:??:17
2003-12-15T13:-:17
The 15th of some month in 2003, time not collected
2003---15
December 15, but can't remember the year, time not collected
Unknown year with known month and day
--12-15
7:15 of some unknown date
Unknown date with known hour and minute
-----T07:15
The text was updated successfully, but these errors were encountered: