Bug 16856 - Addition of millisecond adds a second
Summary: Addition of millisecond adds a second
Status: UNCONFIRMED
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
URL:
Depends on:
Blocks:
 
Reported: 2016-04-27 18:21 UTC by email.rhydar
Modified: 2018-08-02 08:18 UTC (History)
2 users (show)

See Also:


Attachments

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.

example:
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)
Comment 2 Mikko Korpela 2018-08-02 08:18:17 UTC
For what it's worth, the additional second can also be seen on Windows with a recent R-devel.

> 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
> sessionInfo()
R Under development (unstable) (2018-07-30 r75016)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=Finnish_Finland.1252  LC_CTYPE=Finnish_Finland.1252
[3] LC_MONETARY=Finnish_Finland.1252 LC_NUMERIC=C
[5] LC_TIME=Finnish_Finland.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] compiler_3.6.0