From 1b54afdce56520414d8f20157054141cb09c7166 Mon Sep 17 00:00:00 2001 From: Dmitri Iouchtchenko Date: Sun, 13 Jun 2021 14:37:28 -0400 Subject: [PATCH] Saturate day of month in datepicker Summary: The datepicker could step by the wrong number of months, due to the date rolling over to the next month when the number of days in the month is exceeded. For example, going forward from January 31 would jump to March 3, while going backward from July 31 would only go to July 1. Push the date back to ensure that the datepicker stays in the correct month when switching. Test Plan: Changed months starting from an assortment of dates. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: artms, Korvin Differential Revision: https://secure.phabricator.com/D21673 --- resources/celerity/map.php | 18 +++++++++--------- .../rsrc/js/core/behavior-fancy-datepicker.js | 7 +++++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/resources/celerity/map.php b/resources/celerity/map.php index 309e698272..01ad9da370 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -481,7 +481,7 @@ return array( 'rsrc/js/core/behavior-detect-timezone.js' => '78bc5d94', 'rsrc/js/core/behavior-device.js' => 'ac2b1e01', 'rsrc/js/core/behavior-drag-and-drop-textarea.js' => '7ad020a5', - 'rsrc/js/core/behavior-fancy-datepicker.js' => '956f3eeb', + 'rsrc/js/core/behavior-fancy-datepicker.js' => '36821f8d', 'rsrc/js/core/behavior-form.js' => '55d7b788', 'rsrc/js/core/behavior-gesture.js' => 'b58d1a2a', 'rsrc/js/core/behavior-global-drag-and-drop.js' => '1cab0e9a', @@ -635,7 +635,7 @@ return array( 'javelin-behavior-editengine-reorder-configs' => '4842f137', 'javelin-behavior-editengine-reorder-fields' => '0ad8d31f', 'javelin-behavior-event-all-day' => '0b1bc990', - 'javelin-behavior-fancy-datepicker' => '956f3eeb', + 'javelin-behavior-fancy-datepicker' => '36821f8d', 'javelin-behavior-global-drag-and-drop' => '1cab0e9a', 'javelin-behavior-harbormaster-log' => 'b347a301', 'javelin-behavior-herald-rule-editor' => '0922e81d', @@ -1229,6 +1229,13 @@ return array( 'aphront-typeahead-control-css', 'phui-tag-view-css', ), + '36821f8d' => array( + 'javelin-behavior', + 'javelin-util', + 'javelin-dom', + 'javelin-stratcom', + 'javelin-vector', + ), '3829a3cf' => array( 'javelin-behavior', 'javelin-uri', @@ -1781,13 +1788,6 @@ return array( 'javelin-vector', 'javelin-stratcom', ), - '956f3eeb' => array( - 'javelin-behavior', - 'javelin-util', - 'javelin-dom', - 'javelin-stratcom', - 'javelin-vector', - ), '9623adc1' => array( 'javelin-behavior', 'javelin-stratcom', diff --git a/webroot/rsrc/js/core/behavior-fancy-datepicker.js b/webroot/rsrc/js/core/behavior-fancy-datepicker.js index afd5ff25ad..8059e214fe 100644 --- a/webroot/rsrc/js/core/behavior-fancy-datepicker.js +++ b/webroot/rsrc/js/core/behavior-fancy-datepicker.js @@ -424,6 +424,13 @@ JX.behavior('fancy-datepicker', function(config, statics) { value_m += 12; value_y--; } + // This relies on months greater than 11 rolling over into the next + // year and days less than 1 rolling back into the previous month. + var last_date = new Date(value_y, value_m, 0); + if (value_d > last_date.getDate()) { + // The date falls outside the new month, so stuff it back in. + value_d = last_date.getDate(); + } break; case 'd': // User clicked a day.