Skip to content

Commit 1905e89

Browse files
committed
logic
1 parent 197dfd7 commit 1905e89

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

R/IDateTime.R

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,13 @@ as.ITime.numeric = function(x, ms = 'truncate', ...) {
171171
}
172172

173173
as.ITime.character = function(x, format, ...) {
174+
nm = names(x)
174175
x = unclass(x)
175-
if (!missing(format)) return(as.ITime(strptime(x, format = format, ...), ...))
176+
if (!missing(format)) {
177+
ans = as.ITime(strptime(x, format = format, ...), ...)
178+
if (!is.null(nm)) setattr(ans, "names", nm)
179+
return(ans)
180+
}
176181
# else allow for mixed formats, such as test 1189 where seconds are caught despite varying format
177182
y = strptime(x, format = "%H:%M:%OS", ...)
178183
w = which(is.na(y))
@@ -192,12 +197,18 @@ as.ITime.character = function(x, format, ...) {
192197
w = w[!nna]
193198
}
194199
}
195-
as.ITime(y, ...)
200+
ans = as.ITime(y, ...)
201+
if (!is.null(nm)) setattr(ans, "names", nm)
202+
ans
196203
}
197204

198205
as.ITime.POSIXlt = function(x, ms = 'truncate', ...) {
206+
nm = names(x)
199207
secs = clip_msec(x$sec, ms)
200-
(setattr(with(x, secs + min * 60L + hour * 3600L), "class", "ITime")) # () wrap to return visibly
208+
ans = with(x, secs + min * 60L + hour * 3600L)
209+
setattr(ans, "class", "ITime")
210+
if (!is.null(nm)) setattr(ans, "names", nm)
211+
ans
201212
}
202213

203214
as.ITime.times = function(x, ms = 'truncate', ...) {

0 commit comments

Comments
 (0)