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

Excel leap day bug #422

Merged
merged 7 commits into from
Jan 19, 2021
Merged

Excel leap day bug #422

merged 7 commits into from
Jan 19, 2021

Conversation

billdenney
Copy link
Collaborator

29 Feb 1900 is not a real date (it does not exist on real calendars), but it does exist in Excel. This makes it a warning to have an Excel numeric date of 29 Feb 1900 and converts the value to NA. (Applied on top of #421 since there is an interaction.)

@codecov
Copy link

codecov bot commented Jan 15, 2021

Codecov Report

Merging #422 (1e60a7b) into master (6f4a800) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #422   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           22        22           
  Lines          950       958    +8     
=========================================
+ Hits           950       958    +8     
Impacted Files Coverage Δ
R/excel_dates.R 100.00% <100.00%> (ø)

@billdenney
Copy link
Collaborator Author

Hmm, Windows and Mac work while Linux does not. This will take some investigation.

@billdenney
Copy link
Collaborator Author

billdenney commented Jan 15, 2021

Fix #420

@sfirke
Copy link
Owner

sfirke commented Jan 18, 2021

Looks good to me, thank you for fixing both of these! Edge cases to be sure, but also definitely incorrect behavior (thanks Microsoft). I will see if I can poke at the Linux test failure and get anywhere.

@sfirke
Copy link
Owner

sfirke commented Jan 18, 2021

Indeed, those tests fail for me on my Ubuntu machine. This works, when it shouldn't:

> excel_numeric_to_date(43170.09, include_time=TRUE, tz="America/New_York")
[1] "2018-03-11 03:09:36 EDT"

And this errors before the comparison it is part of can be executed;

>     as.POSIXct(NA_real_, tz="America/New_York")
Error in as.POSIXct.numeric(NA_real_, tz = "America/New_York") : 
  'origin' must be supplied

@billdenney
Copy link
Collaborator Author

I think that this is a subtle bug in as.POSIXct.numeric() where all NA inputs should return NA rather than requiring the origin. (I'm kinda surprised that we discovered a base R bug...) We should probably just add an origin argument for now, and report it. I'll try those out and push a change.

@billdenney
Copy link
Collaborator Author

billdenney commented Jan 19, 2021

I found a few issues with as.POSIXct and as.POSIXlt while working through this. A simpler solution may be to add lubridate as a dependency and use its date creation which seems to work correctly for daylight savings times.

What do you think about a lubridate dependency?

@sfirke
Copy link
Owner

sfirke commented Jan 19, 2021

Relying on lubridate to sweat the details around dates sounds wise to me! 🦉 No worries about adding that dependency, virtually everyone using this package will have it installed as part of tidyverse anyway.

@billdenney
Copy link
Collaborator Author

It turns out that we already had lubridate as a dependency due to convert_to_date() and convert_to_datetime(). Also, I brought up the as.POSIX issues here: https://stat.ethz.ch/pipermail/r-help/2021-January/469943.html.

@sfirke
Copy link
Owner

sfirke commented Jan 19, 2021

Looks great, thank you for digging in to sort this out so carefully 🙏

@sfirke sfirke merged commit 2d1a1a6 into sfirke:master Jan 19, 2021
@sfirke
Copy link
Owner

sfirke commented Jan 19, 2021

I think this closes #420, is that right?

@billdenney
Copy link
Collaborator Author

It does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants