Bug 16856 - Addition of millisecond adds a second
Summary: Addition of millisecond adds a second
Alias: None
Product: R
Classification: Unclassified
Component: Accuracy (show other bugs)
Version: R-devel (trunk)
Hardware: x86_64/x64/amd64 (64-bit) OS X Yosemite
: P5 normal
Assignee: R-core
Depends on:
Reported: 2016-04-27 18:21 UTC by email.rhydar
Modified: 2016-04-27 22:01 UTC (History)
1 user (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description email.rhydar 2016-04-27 18:21:52 UTC
When adding fractional seconds to a POSIXct object an additional second is shown in the resulting time series.

as.POSIXct(strptime("1970-01-01 00:00:00.000", "%Y-%m-%d %H:%M:%OS")) + 0.25 gives the following result:

[1] "1970-01-01 00:00:01.25 SAST"
Comment 1 Simon Urbanek 2016-04-27 22:01:00 UTC
This seems to be specific to your TZ setting (which you didn't share) since the underlying condition seems to be negative fractional POSIX time (your time was -7199.25). I cannot reproduce the output you have shown, but I can see a one-second shift when converting POSIXct to POSIXlt for negative, fractional POSIX values:

> as.POSIXlt(.POSIXct(-.25, "GMT"))
[1] "1970-01-01 00:00:00 GMT"
> unlist(as.POSIXlt(.POSIXct(-.25, "GMT")))
  sec   min  hour  mday   mon  year  wday  yday isdst 
 0.75  0.00  0.00  1.00  0.00 70.00  4.00  0.00  0.00 

Strictly speaking POSIX times are undefined before 1970/1/1 GMT and so are negative values, thus I'm not sure if this is expected behavior and/or may be system-specific behavior for undefined values. The behavior is different on Linux:

> unlist(as.POSIXlt(.POSIXct(-.25, "GMT")))
   sec    min   hour   mday    mon   year   wday   yday  isdst 
 59.75  59.00  23.00  31.00  11.00  69.00   3.00 364.00   0.00 

(both tested on R-devel; OS X 10.11.4 and Debian 8 respectively)