Skip to content

Commit 76b9b71

Browse files
authored
Clarified behavior of "24:00:00" in as.ITime() (#7057)
1 parent ca65511 commit 76b9b71

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,6 @@ Authors@R: c(
102102
person("Aljaž", "Sluga", role="ctb"),
103103
person("Bill", "Evans", role="ctb"),
104104
person("Reino", "Bruner", role="ctb"),
105-
person(comment=c(github="@badasahog"), role="ctb")
105+
person(comment=c(github="@badasahog"), role="ctb"),
106+
person("Vinit", "Thakur", role="ctb")
106107
)

man/IDateTime.Rd

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ hours. Because \code{ITime} is stored in seconds, you can add it to a
137137
\code{POSIXct} object, but you should not add it to a \code{Date}
138138
object.
139139

140+
For \code{as.ITime}, note that the string \code{"24:00:00"} is parsed as \code{"00:00:00"}.
141+
This is because the conversion uses \code{as.POSIXct}, which treats \code{"24:00:00"} as midnight of the next day.
142+
This differs from ISO 8601 (which allows \code{"24:00:00"} to represent end-of-day), but aligns with POSIX standards.
143+
To represent end-of-day intervals, use \code{"23:59:59"} or arithmetic (e.g., \code{as.ITime("23:59:59") + 1L}).
144+
140145
We also provide S3 methods to convert to and from \code{Date} and \code{POSIXct}.
141146

142147
\code{ITime} is time zone-agnostic. When converting \code{ITime} and
@@ -245,6 +250,12 @@ identical(as.ITime("10:45"), methods::as("10:45", "ITime"))
245250
246251
(t <- as.ITime("10:45:04", format = "\%H:\%M:\%S"))
247252
253+
# "24:00:00" is parsed as "00:00:00"
254+
as.ITime("24:00:00")
255+
256+
# Workaround for end-of-day: add 1 second to "23:59:59"
257+
as.ITime("23:59:59") + 1L
258+
248259
as.POSIXct("2001-01-01") + as.ITime("10:45")
249260
250261
datetime <- seq(as.POSIXct("2001-01-01"), as.POSIXct("2001-01-03"), by = "5 hour")

0 commit comments

Comments
 (0)