From 20329feb7fadd433138ed30c85f3da87329a9ebc Mon Sep 17 00:00:00 2001 From: Alan Dipert Date: Tue, 26 Mar 2019 17:52:47 -0700 Subject: [PATCH] Improve bootstrap-datepicker update tools, add docs --- .../datepicker/js/bootstrap-datepicker.js | 12 +++++- tools/README.md | 24 ++++++++++++ tools/applyDatepickerPatches.R | 18 +++++++++ tools/updateBootstrapDatepicker.R | 39 +++++++------------ 4 files changed, 68 insertions(+), 25 deletions(-) create mode 100755 tools/applyDatepickerPatches.R diff --git a/inst/www/shared/datepicker/js/bootstrap-datepicker.js b/inst/www/shared/datepicker/js/bootstrap-datepicker.js index 76a99fc274..97f5c08608 100644 --- a/inst/www/shared/datepicker/js/bootstrap-datepicker.js +++ b/inst/www/shared/datepicker/js/bootstrap-datepicker.js @@ -529,7 +529,17 @@ }, _utc_to_local: function(utc){ - return utc && new Date(utc.getTime() + (utc.getTimezoneOffset()*60000)); + + if (!utc) return utc; + + var local = new Date(utc.getTime() + (utc.getTimezoneOffset() * 60000)); + + if (local.getTimezoneOffset() != utc.getTimezoneOffset()) + { + local = new Date(utc.getTime() + (local.getTimezoneOffset() * 60000)); + } + + return utc && local; }, _local_to_utc: function(local){ return local && new Date(local.getTime() - (local.getTimezoneOffset()*60000)); diff --git a/tools/README.md b/tools/README.md index 73f5b61c96..bbdcb72220 100644 --- a/tools/README.md +++ b/tools/README.md @@ -92,3 +92,27 @@ To update the version of babel-polyfill: * Run `yarn add --dev babel-polyfill --exact`. * Edit R/shinyui.R. The `renderPage` function has an `htmlDependency` for `babel-polyfill`. Update this to the new version number. + +# Updating and patching `bootstrap-datepicker` + +## Updating + +[bootstrap-datepicker](https://github.com/uxsolutions/bootstrap-datepicker) can be updated with the script `updateBootstrapDatepicker.R`. + +After updating, our patches to `bootstrap-datepicker` must be applied using the script `applyDatepickerPatches.R` + +After updating and applying patches, `yarn grunt` should be run per the instructions above. + +## Making a new patch + +To create a new patch: + +1. Make any necessary changes to files in `inst/www/shared/datepicker` +1. **Do not commit your changes.** +1. Instead, create a patch with a command like `git diff > tools/datepicker-patches/012-a-description.patch` +1. Add the new `.patch` file to the repo with a descriptive commit message +1. Revert `bootstrap-datepicker` to its unpatched state by running `updateBootstrapDatepicker.R` +1. Apply all patches, including the one you just made, by running `applyDatepickerPatches.R` +1. Run `yarn grunt` +1. Test your changes +1. `git add` the new `.patch` and any resulting changes diff --git a/tools/applyDatepickerPatches.R b/tools/applyDatepickerPatches.R new file mode 100755 index 0000000000..874bd73241 --- /dev/null +++ b/tools/applyDatepickerPatches.R @@ -0,0 +1,18 @@ +#!/usr/bin/env Rscript +# Applies patches stored in tools/datepicker-patches +# Should be run after running tools/updateBootstrapDatepicker.R + +library(rprojroot) + +patch_dir <- rprojroot::find_package_root_file("tools/datepicker-patches") + +for (patch in list.files(patch_dir, full.names = TRUE)) { + tryCatch({ + message(sprintf("Applying %s", basename(patch))) + system(sprintf("git apply '%s'", patch)) + }, + error = function(e) { + quit(save = "no", status = 1) + } + ) +} diff --git a/tools/updateBootstrapDatepicker.R b/tools/updateBootstrapDatepicker.R index c541e72621..4e49efc967 100755 --- a/tools/updateBootstrapDatepicker.R +++ b/tools/updateBootstrapDatepicker.R @@ -1,33 +1,24 @@ #!/usr/bin/env Rscript # Retrieves a particular version of bootstrap-datepicker: # https://github.com/uxsolutions/bootstrap-datepicker -# After retrieving, applies the series of patches contained -# in tools/datepicker-patches to inst/www/shared/datepicker/ +# After retrieving, you can apply patches stored in +# tools/datepicker-patches with applyDatepickerPatches.R library(rprojroot) version <- "1.6.4" -patch_dir <- rprojroot::find_package_root_file("tools/datepicker-patches") dest_dir <- rprojroot::find_package_root_file("inst/www/shared/datepicker") +tag <- paste0("v", version) +dest_file <- file.path(tempdir(), paste0("bootstrap-datepicker-", version, ".zip")) +url <- sprintf("https://github.com/uxsolutions/bootstrap-datepicker/releases/download/%s/bootstrap-datepicker-%s-dist.zip", tag, version) -fetch_datepicker <- function() { - tag <- paste0("v", version) - dest_file <- file.path(tempdir(), paste0("bootstrap-datepicker-", version, ".zip")) - url <- sprintf("https://github.com/uxsolutions/bootstrap-datepicker/releases/download/%s/bootstrap-datepicker-%s-dist.zip", tag, version) - download.file(url, dest_file) - unzip( - dest_file, - files = c( - "js/bootstrap-datepicker.js", - "css/bootstrap-datepicker3.css", - "css/bootstrap-datepicker3.min.css" - ), - exdir = dest_dir - ) -} - -apply_patches <- function() { -} - -fetch_datepicker() -apply_patches() +download.file(url, dest_file) +unzip( + dest_file, + files = c( + "js/bootstrap-datepicker.js", + "css/bootstrap-datepicker3.css", + "css/bootstrap-datepicker3.min.css" + ), + exdir = dest_dir +)