Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue with flooring and ceiling dates #645

Closed
bart1 opened this issue Feb 22, 2018 · 5 comments
Closed

issue with flooring and ceiling dates #645

bart1 opened this issue Feb 22, 2018 · 5 comments

Comments

@bart1
Copy link

@bart1 bart1 commented Feb 22, 2018

I noticed some strange results where ceiling date sometimes does not produce a rounded date (see the example where the time becomes 1 am)

> a<-structure(631166450, class = c("POSIXct", "POSIXt"), tzone = "")
> a
[1] "1990-01-01 05:00:50 CET"
> floor_date(a,'days');ceiling_date(a,'days')
[1] "1990-01-01 CET"
[1] "1990-01-02 01:00:00 CET"
> 
> a<-structure(631166450, class = c("POSIXct", "POSIXt"), tzone = "CET")
> a
[1] "1990-01-01 05:00:50 CET"
> floor_date(a,'days');ceiling_date(a,'days')
[1] "1990-01-01 CET"
[1] "1990-01-02 CET"
> 
> Sys.timezone()
[1] "Europe/Zurich"
> sessionInfo()
R version 3.4.2 (2017-09-28)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: OS X El Capitan 10.11.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libLAPACK.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
 [1] lubridate_1.7.2 browMod_0.1     Rcpp_0.12.15    move_3.0.3      rgdal_1.2-16    raster_2.6-7    sp_1.2-7        geosphere_1.5-7 mgcv_1.8-23    
[10] nlme_3.1-131   

loaded via a namespace (and not attached):
 [1] compiler_3.4.2     pillar_1.1.0       plyr_1.8.4         tools_3.4.2        digest_0.6.15      memoise_1.1.0      tibble_1.4.2       gtable_0.2.0      
 [9] lattice_0.20-35    rlang_0.1.6        Matrix_1.2-12      yaml_2.1.16        parallel_3.4.2     gridExtra_2.3      httr_1.3.1         stringr_1.2.0     
[17] xml2_1.2.0         stats4_3.4.2       grid_3.4.2         inline_0.3.14      R6_2.2.2           rstan_2.17.3       ggplot2_2.2.1      magrittr_1.5      
[25] splines_3.4.2      scales_0.5.0       codetools_0.2-15   StanHeaders_2.17.2 colorspace_1.3-2   stringi_1.1.6      lazyeval_0.2.1     munsell_0.4.3     
@bart1
Copy link
Author

@bart1 bart1 commented Feb 22, 2018

Not sure if it relates to #642 but here is the test code anyway

> Sys.timezone()
[1] "Europe/Zurich"
> Sys.getenv("TZ")
[1] ""
> lubridate:::C_local_tz()
[1] "raster465"
> as.POSIXct("2017-08-13", tz = "")
[1] "2017-08-13 CEST"
> ymd("2017-08-13", tz = "")
[1] "2017-08-13 02:00:00 CEST"
> force_tz(as.POSIXct("2017-08-13", tz = ""), "UTC")
[1] "2017-08-12 22:00:00 UTC"
> 
> t1 <- as.POSIXct("2018-02-28 20:10:00")
> lubridate::minute(t1) <- 0
> t1
[1] "2018-02-28 21:00:00 CET"
> as.POSIXct("2017-07-01", format = "%Y-%m-%d") + days(1)
[1] "2017-06-02 02:00:00 CEST"

Loading

@vspinu
Copy link
Member

@vspinu vspinu commented Feb 22, 2018

lubridate:::C_local_tz()
[1] "raster465"

Ok. This is messed up :( I am surprised you are not seeing explicit TZ errors with this.

For now setting Sys.setenv(TZ="Europe/Zurich") should fix this.

Loading

@vspinu
Copy link
Member

@vspinu vspinu commented Feb 22, 2018

Would you mind checking the github version?

Loading

@bart1
Copy link
Author

@bart1 bart1 commented Feb 27, 2018

I just installed the devel version from github and it seems to work
at least for the ceiling example

> Sys.timezone()
[1] "Europe/Zurich"
> Sys.getenv("TZ")
[1] ""
> lubridate:::C_local_tz()
[1] "Europe/Zurich"
> as.POSIXct("2017-08-13", tz = "")
[1] "2017-08-13 CEST"
> ymd("2017-08-13", tz = "")
[1] "2017-08-13 CEST"
> force_tz(as.POSIXct("2017-08-13", tz = ""), "UTC")
[1] "2017-08-13 UTC"
> 
> t1 <- as.POSIXct("2018-02-28 20:10:00")
> lubridate::minute(t1) <- 0
> t1
[1] "2018-02-28 20:00:00 CET"
> as.POSIXct("2017-07-01", format = "%Y-%m-%d") + days(1)
[1] "2017-07-02 CEST"
> 
> a<-structure(631166450, class = c("POSIXct", "POSIXt"), tzone = "")
> a
[1] "1990-01-01 05:00:50 CET"
> floor_date(a,'days');ceiling_date(a,'days')
[1] "1990-01-01 CET"
[1] "1990-01-02 CET"
> 
> a<-structure(631166450, class = c("POSIXct", "POSIXt"), tzone = "CET")
> a
[1] "1990-01-01 05:00:50 CET"
> floor_date(a,'days');ceiling_date(a,'days')
[1] "1990-01-01 CET"
[1] "1990-01-02 CET"
> 
> sessionInfo()
R version 3.4.2 (2017-09-28)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: OS X El Capitan 10.11.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libLAPACK.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] lubridate_1.7.2

loaded via a namespace (and not attached):
 [1] httr_1.3.1      compiler_3.4.2  magrittr_1.5    R6_2.2.2        tools_3.4.2     withr_2.1.1     curl_3.1        yaml_2.1.16    
 [9] Rcpp_0.12.15    memoise_1.1.0   stringi_1.1.6   knitr_1.20      git2r_0.21.0    stringr_1.3.0   digest_0.6.15   devtools_1.13.5

Loading

@vspinu
Copy link
Member

@vspinu vspinu commented Feb 27, 2018

Ok. Perfect. Will release asap. Thanks for the report!

Loading

@bart1 bart1 closed this Feb 27, 2018
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue May 30, 2021
Version 1.7.10
==============

### NEW FEATURES

* `fast_strptime()` and `parse_date_time2()` now accept multiple formats and apply them in turn

### BUG FIXES

* [#926](tidyverse/lubridate#926) Fix incorrect division of intervals by months involving leap years
* Fix incorrect skipping of digits during parsing of the `%z` format

Version 1.7.9.2
===============

### NEW FEATURES

* [#914](tidyverse/lubridate#914) New `rollforward()` function
* [#928](tidyverse/lubridate#928) On startup lubridate now resets TZDIR to a proper directory when it is set to non-dir values like "internal" or "macOS" (a change introduced in R4.0.2)
* [#630](tidyverse/lubridate#630) New parsing functions `ym()` and `my()`

### BUG FIXES

* [#930](tidyverse/lubridate#930) `as.period()` on intervals now returns valid Periods with double fields (not integers)



Version 1.7.9
=============

### NEW FEATURES

* [#871](tidyverse/lubridate#893) Add `vctrs` support


### BUG FIXES

* [#890](tidyverse/lubridate#890) Correctly compute year in `quarter(..., with_year = TRUE)`
* [#893](tidyverse/lubridate#893) Fix incorrect parsing of abbreviated months in locales with trailing dot (regression in v1.7.8)
* [#886](tidyverse/lubridate#886) Fix `with_tz()` for POSIXlt objects
* [#887](tidyverse/lubridate#887) Error on invalid numeric input to `month()`
* [#889](tidyverse/lubridate#889) Export new dmonth function

Version 1.7.8
=============

### NEW FEATURES

* (breaking) Year and month durations now assume 365.25 days in a year consistently in conversion and constructors. Particularly `dyears(1) == years(1)` is now `TRUE`.
* Format and print methods for 0-length objects are more consistent.
* New duration constructor `dmonths()` to complement other duration constructors.
*
* `duration()` constructor now accepts `months` and `years` arguments.
* [#629](tidyverse/lubridate#629) Added `format_ISO8601()` methods.
* [#672](tidyverse/lubridate#672) Eliminate all partial argument matches
* [#674](tidyverse/lubridate#674) `as_date()` now ignores the `tz` argument
* [#675](tidyverse/lubridate#675) `force_tz()`, `with_tz()`, `tz<-` convert dates to date-times
* [#681](tidyverse/lubridate#681) New constants `NA_Date_` and `NA_POSIXct_` which parallel built-in primitive constants.
* [#681](tidyverse/lubridate#681) New constructors `Date()` and `POSIXct()` which parallel built-in primitive constructors.
* [#695](tidyverse/lubridate#695) Durations can now be compared with numeric vectors.
* [#707](tidyverse/lubridate#707) Constructors return 0-length inputs when called with no arguments
* [#713](tidyverse/lubridate#713) (breaking) `as_datetime()` always returns a `POSIXct()`
* [#717](tidyverse/lubridate#717) Common generics are now defined in `generics` dependency package.
* [#719](tidyverse/lubridate#719) Negative Durations are now displayed with leading `-`.
* [#829](tidyverse/lubridate#829) `%within%` throws more meaningful messages when applied on unsupported classes
* [#831](tidyverse/lubridate#831) Changing hour, minute or second of Date object now yields POSIXct.
* [#869](tidyverse/lubridate#869) Propagate NAs to all internal components of a Period object

### BUG FIXES

* [#682](tidyverse/lubridate#682) Fix quarter extraction with small `fiscal_start`s.
* [#703](tidyverse/lubridate#703) `leap_year()` works with objects supported by `year()`.
* [#778](tidyverse/lubridate#778) `duration()/period()/make_difftime()` work with repeated units
* `c.Period` concatenation doesn't fail with empty components.
* Honor `exact = TRUE` argument in `parse_date_time2`, which was so far ignored.

Version 1.7.4
=============

### NEW FEATURES

* [#658](tidyverse/lubridate#658) `%within%` now accepts a list of intervals, in which case an instant is checked if it occurs within any of the supplied intervals.

### CHANGES

* [#661](tidyverse/lubridate#661) Throw error on invalid multi-unit rounding.
* [#633](tidyverse/lubridate#633) `%%` on intervals relies on `%m+` arithmetic and doesn't produce NAs when intermediate computations result in non-existent dates.
* `tz()` always returns "UTC" when `tzone` attribute cannot be inferred.

### BUG FIXES

* [#664](tidyverse/lubridate#664) Fix lookup of period functions in `as.period`
* [#649](tidyverse/lubridate#664) Fix system timezone memoization

Version 1.7.3
=============

### BUG FIXES

* [#643](tidyverse/lubridate#643), [#640](tidyverse/lubridate#640), [#645](tidyverse/lubridate#645) Fix faulty caching of system timezone.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants