Skip to content

Conversation

@DavisVaughan
Copy link
Member

Closes #230

It turns out this was not actually a date bug. I misunderstood how %NS was supposed to work. Really this is only useful for cases where you need to parse seconds that might have more than one leading zero, like 007. It should be extremely rare to ever use N. I have completely redocumented how that is supposed to work.

date considers parsing a string with fractional seconds into a coarser time point, like one with second precision, to be unsupported behavior (a similar argument is made when parsing a string with hours into a day precision time point). I was unaware of this, and thought that %NS was used for this exact case, which is not true. Instead you should use a precision that is at least as precise as the string you are parsing. So a string with milliseconds should be parsed as millisecond, microsecond or nanosecond precision.

This impacts the way the Date and POSIXct parsers work. Because we treat POSIXct as second precision, it is no longer considered correct behavior to ever parse a string with fractional seconds using date_time_parse(). Instead, you should parse into a naive-time that can handle fractional seconds, round, then convert to POSIXct (this is shown in multiple help files, and the NEWS bullet).

@DavisVaughan DavisVaughan merged commit 0d6a03e into master May 10, 2021
@DavisVaughan DavisVaughan deleted the fix/second-parsing branch May 10, 2021 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

naive_time_parse() can fail when rounding up to 60 seconds

2 participants