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

Bug: Timezone issue in 'connection()' and 'intermodal_route()' #94

Closed
munterfi opened this issue Dec 17, 2020 · 1 comment · Fixed by #105 or #107
Closed

Bug: Timezone issue in 'connection()' and 'intermodal_route()' #94

munterfi opened this issue Dec 17, 2020 · 1 comment · Fixed by #105 or #107
Assignees
Labels
bug Something isn't working

Comments

@munterfi
Copy link
Owner

munterfi commented Dec 17, 2020

Since the fix of the timezone issue in isoline() (see #85), there is now an incorrect shift in the arrival and departure time of connection() and intermodal_route(). This occurs due the change in .encode_datetime, which now encodes the timezone instead of converting to UTC before sending the request. The connection() and intermodal_route() functions still assume a timestamp in timezone UTC in the response from the API. So there occurs a shift in time:

library(sf)
#> Linking to GEOS 3.8.1, GDAL 3.2.0, PROJ 7.2.0
library(hereR)

# Timestamp with different timezone as my local CET
(datetime = as.POSIXct("2020-12-17 08:00:00", tz = "Europe/Moscow"))
#> [1] "2020-12-17 08:00:00 MSK"

connection(poi[1, ], poi[2, ], datetime = datetime)$departure[1]
#> [1] "2020-12-17 09:53:00 MSK"

intermodal_route(poi[1, ], poi[2, ], datetime = datetime)$departure[1]
#> [1] "2020-12-17 09:53:00 MSK"

The functions route(), route_matrix() and isoline() are handling the timestamps correctly (as they are not taking the timestamp from the the API response):

route(poi[1, ], poi[2, ], datetime = datetime)$departure[1]
#> [1] "2020-12-17 08:00:00 MSK"

route_matrix(poi[1, ], poi[2, ], datetime = datetime)$departure[1]
#> [1] "2020-12-17 08:00:00 MSK"

isoline(poi[1, ], datetime = datetime)$departure[1]
#> [1] "2020-12-17 08:00:00 MSK"

The .parse_datetime() helper function that causes the problem can not be replaced, as other functions (incident() and weather()) still use older API versions and receive UTC timestamps. Adding a .parse_datetime_tz() that also parses the timezone information would solve the problem.

Session info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 4.0.3 (2020-10-10)
#>  os       macOS Catalina 10.15.7      
#>  system   x86_64, darwin17.0          
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  ctype    en_US.UTF-8                 
#>  tz       Europe/Zurich               
#>  date     2020-12-17                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package      * version date       lib source        
#>  assertthat     0.2.1   2019-03-21 [1] CRAN (R 4.0.0)
#>  callr          3.5.1   2020-10-13 [1] CRAN (R 4.0.2)
#>  class          7.3-17  2020-04-26 [1] CRAN (R 4.0.3)
#>  classInt       0.4-3   2020-04-07 [1] CRAN (R 4.0.0)
#>  cli            2.2.0   2020-11-20 [1] CRAN (R 4.0.2)
#>  crayon         1.3.4   2017-09-16 [1] CRAN (R 4.0.0)
#>  curl           4.3     2019-12-02 [1] CRAN (R 4.0.1)
#>  data.table     1.13.2  2020-10-19 [1] CRAN (R 4.0.3)
#>  DBI            1.1.0   2019-12-15 [1] CRAN (R 4.0.2)
#>  desc           1.2.0   2018-05-01 [1] CRAN (R 4.0.0)
#>  devtools       2.3.2   2020-09-18 [1] CRAN (R 4.0.2)
#>  digest         0.6.27  2020-10-24 [1] CRAN (R 4.0.2)
#>  dplyr          1.0.2   2020-08-18 [1] CRAN (R 4.0.2)
#>  e1071          1.7-4   2020-10-14 [1] CRAN (R 4.0.2)
#>  ellipsis       0.3.1   2020-05-15 [1] CRAN (R 4.0.0)
#>  evaluate       0.14    2019-05-28 [1] CRAN (R 4.0.0)
#>  fansi          0.4.1   2020-01-08 [1] CRAN (R 4.0.0)
#>  flexpolyline   0.2.0   2020-12-09 [1] local         
#>  fs             1.5.0   2020-07-31 [1] CRAN (R 4.0.2)
#>  generics       0.1.0   2020-10-31 [1] CRAN (R 4.0.2)
#>  glue           1.4.2   2020-08-27 [1] CRAN (R 4.0.2)
#>  hereR        * 0.5.2   2020-11-26 [1] CRAN (R 4.0.3)
#>  htmltools      0.5.0   2020-06-16 [1] CRAN (R 4.0.2)
#>  jsonlite       1.7.1   2020-09-07 [1] CRAN (R 4.0.2)
#>  KernSmooth     2.23-18 2020-10-29 [1] CRAN (R 4.0.2)
#>  knitr          1.30    2020-09-22 [1] CRAN (R 4.0.2)
#>  lifecycle      0.2.0   2020-03-06 [1] CRAN (R 4.0.0)
#>  magrittr       2.0.1   2020-11-17 [1] CRAN (R 4.0.2)
#>  memoise        1.1.0   2017-04-21 [1] CRAN (R 4.0.0)
#>  pillar         1.4.7   2020-11-20 [1] CRAN (R 4.0.2)
#>  pkgbuild       1.1.0   2020-07-13 [1] CRAN (R 4.0.2)
#>  pkgconfig      2.0.3   2019-09-22 [1] CRAN (R 4.0.0)
#>  pkgload        1.1.0   2020-05-29 [1] CRAN (R 4.0.2)
#>  prettyunits    1.1.1   2020-01-24 [1] CRAN (R 4.0.0)
#>  processx       3.4.4   2020-09-03 [1] CRAN (R 4.0.2)
#>  ps             1.4.0   2020-10-07 [1] CRAN (R 4.0.2)
#>  purrr          0.3.4   2020-04-17 [1] CRAN (R 4.0.0)
#>  R6             2.5.0   2020-10-28 [1] CRAN (R 4.0.2)
#>  Rcpp           1.0.5   2020-07-06 [1] CRAN (R 4.0.2)
#>  remotes        2.2.0   2020-07-21 [1] CRAN (R 4.0.2)
#>  rlang          0.4.9   2020-11-26 [1] CRAN (R 4.0.3)
#>  rmarkdown      2.5     2020-10-21 [1] CRAN (R 4.0.2)
#>  rprojroot      2.0.2   2020-11-15 [1] CRAN (R 4.0.2)
#>  sessioninfo    1.1.1   2018-11-05 [1] CRAN (R 4.0.0)
#>  sf           * 0.9-6   2020-09-13 [1] CRAN (R 4.0.3)
#>  stringi        1.5.3   2020-09-09 [1] CRAN (R 4.0.2)
#>  stringr        1.4.0   2019-02-10 [1] CRAN (R 4.0.2)
#>  testthat       3.0.0   2020-10-31 [1] CRAN (R 4.0.2)
#>  tibble         3.0.4   2020-10-12 [1] CRAN (R 4.0.2)
#>  tidyselect     1.1.0   2020-05-11 [1] CRAN (R 4.0.0)
#>  units          0.6-7   2020-06-13 [1] CRAN (R 4.0.2)
#>  usethis        1.6.3   2020-09-17 [1] CRAN (R 4.0.2)
#>  vctrs          0.3.5   2020-11-17 [1] CRAN (R 4.0.2)
#>  withr          2.3.0   2020-09-22 [1] CRAN (R 4.0.2)
#>  xfun           0.19    2020-10-30 [1] CRAN (R 4.0.2)
#>  yaml           2.2.1   2020-02-01 [1] CRAN (R 4.0.0)
#> 
#> [1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library
@munterfi munterfi added the bug Something isn't working label Dec 17, 2020
@munterfi munterfi self-assigned this Dec 17, 2020
@munterfi
Copy link
Owner Author

Timezone and time are now correct:

library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
library(hereR)

# Timestamp with different timezone as my local CET
(datetime = as.POSIXct("2020-12-17 08:00:00", tz = "Europe/Moscow"))
#> [1] "2020-12-17 08:00:00 MSK"

connection(poi[1, ], poi[2, ], datetime = datetime)$departure[1]
#> Sending 1 request(s) to: 'https://transit.router.hereapi.com/v8/routes?...'
#> Received 1 response(s) with total size: 118.7 Kb
#> [1] "2020-12-17 08:53:00 MSK"

intermodal_route(poi[1, ], poi[2, ], datetime = datetime)$departure[1]
#> Sending 1 request(s) to: 'https://intermodal.router.hereapi.com/v8/routes?...'
#> Received 1 response(s) with total size: 59.5 Kb
#> [1] "2020-12-17 08:53:00 MSK"

route(poi[1, ], poi[2, ], datetime = datetime)$departure[1]
#> Sending 1 request(s) to: 'https://route.ls.hereapi.com/routing/7.2/calculateroute.json?...'
#> Received 1 response(s) with total size: 49.9 Kb
#> [1] "2020-12-17 08:00:00 MSK"

route_matrix(poi[1, ], poi[2, ], datetime = datetime)$departure[1]
#> Sending 1 request(s) to: 'https://matrix.route.ls.hereapi.com/routing/7.2/calculatematrix.json?...'
#> Received 1 response(s) with total size: 712 bytes
#> [1] "2020-12-17 08:00:00 MSK"

isoline(poi[1, ], datetime = datetime)$departure[1]
#> Sending 1 request(s) to: 'https://isoline.router.hereapi.com/v8/isolines?...'
#> Received 1 response(s) with total size: 9.7 Kb
#> [1] "2020-12-17 08:00:00 MSK"

# Timestamp with my local timezone (CET)
(datetime = as.POSIXct("2020-12-17 08:00:00", tz = "Europe/Zurich"))
#> [1] "2020-12-17 08:00:00 CET"

connection(poi[1, ], poi[2, ], datetime = datetime)$departure[1]
#> Sending 1 request(s) to: 'https://transit.router.hereapi.com/v8/routes?...'
#> Received 1 response(s) with total size: 119.8 Kb
#> [1] "2020-12-17 08:49:00 CET"

intermodal_route(poi[1, ], poi[2, ], datetime = datetime)$departure[1]
#> Sending 1 request(s) to: 'https://intermodal.router.hereapi.com/v8/routes?...'
#> Received 1 response(s) with total size: 74.1 Kb
#> [1] "2020-12-17 08:49:00 CET"

route(poi[1, ], poi[2, ], datetime = datetime)$departure[1]
#> Sending 1 request(s) to: 'https://route.ls.hereapi.com/routing/7.2/calculateroute.json?...'
#> Received 1 response(s) with total size: 49.9 Kb
#> [1] "2020-12-17 08:00:00 CET"

route_matrix(poi[1, ], poi[2, ], datetime = datetime)$departure[1]
#> Sending 1 request(s) to: 'https://matrix.route.ls.hereapi.com/routing/7.2/calculatematrix.json?...'
#> Received 1 response(s) with total size: 712 bytes
#> [1] "2020-12-17 08:00:00 CET"

isoline(poi[1, ], datetime = datetime)$departure[1]
#> Sending 1 request(s) to: 'https://isoline.router.hereapi.com/v8/isolines?...'
#> Received 1 response(s) with total size: 8.6 Kb
#> [1] "2020-12-17 08:00:00 CET"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant