From eeccaf99b6cd886389e1f9bce7bcdc440f60c183 Mon Sep 17 00:00:00 2001 From: lkassianik Date: Fri, 15 Apr 2016 13:52:00 -0700 Subject: [PATCH] When scrolling forward a month in calendar date picker from 1/31, next chosen date should be 2/29, not 3/1. Summary: Fixes T9295 Test Plan: Create event, open datepicker for start date, choose 1/31/2016, open datepicker again, click right button to scroll month. New suggested date should be 2/29/2016 Reviewers: chad, epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin Maniphest Tasks: T9295 Differential Revision: https://secure.phabricator.com/D15727 --- resources/celerity/map.php | 18 +++++++++--------- .../rsrc/js/core/behavior-fancy-datepicker.js | 9 +++++++++ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/resources/celerity/map.php b/resources/celerity/map.php index 5cc7b4c250..087103c912 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -479,7 +479,7 @@ return array( 'rsrc/js/core/behavior-device.js' => 'b5b36110', 'rsrc/js/core/behavior-drag-and-drop-textarea.js' => '4f6a4b4e', 'rsrc/js/core/behavior-error-log.js' => '6882e80a', - 'rsrc/js/core/behavior-fancy-datepicker.js' => '8ae55229', + 'rsrc/js/core/behavior-fancy-datepicker.js' => '568931f3', 'rsrc/js/core/behavior-file-tree.js' => '88236f00', 'rsrc/js/core/behavior-form.js' => '5c54cbf3', 'rsrc/js/core/behavior-gesture.js' => '3ab51e2c', @@ -622,7 +622,7 @@ return array( 'javelin-behavior-editengine-reorder-fields' => 'b59e1e96', 'javelin-behavior-error-log' => '6882e80a', 'javelin-behavior-event-all-day' => '38dcf3c8', - 'javelin-behavior-fancy-datepicker' => '8ae55229', + 'javelin-behavior-fancy-datepicker' => '568931f3', 'javelin-behavior-global-drag-and-drop' => 'c8e57404', 'javelin-behavior-herald-rule-editor' => '7ebaeed3', 'javelin-behavior-high-security-warning' => 'a464fe03', @@ -1301,6 +1301,13 @@ return array( 'phabricator-drag-and-drop-file-upload', 'javelin-workboard-board', ), + '568931f3' => array( + 'javelin-behavior', + 'javelin-util', + 'javelin-dom', + 'javelin-stratcom', + 'javelin-vector', + ), '56a1ca03' => array( 'javelin-behavior', 'javelin-behavior-device', @@ -1554,13 +1561,6 @@ return array( 'javelin-install', 'javelin-dom', ), - '8ae55229' => array( - 'javelin-behavior', - 'javelin-util', - 'javelin-dom', - 'javelin-stratcom', - 'javelin-vector', - ), '8bdb2835' => array( 'phui-fontkit-css', ), diff --git a/webroot/rsrc/js/core/behavior-fancy-datepicker.js b/webroot/rsrc/js/core/behavior-fancy-datepicker.js index 4c58974fc5..d3cdb1a8d3 100644 --- a/webroot/rsrc/js/core/behavior-fancy-datepicker.js +++ b/webroot/rsrc/js/core/behavior-fancy-datepicker.js @@ -264,6 +264,7 @@ JX.behavior('fancy-datepicker', function(config, statics) { function getValidDate() { var written_date = new Date(value_y, value_m-1, value_d); + if (isNaN(written_date.getTime())) { return new Date(); } else { @@ -272,6 +273,14 @@ JX.behavior('fancy-datepicker', function(config, statics) { value_y += 2000; written_date = new Date(value_y, value_m-1, value_d); } + + // adjust for a date like February 31 + var adjust = 1; + while (written_date.getMonth() !== value_m-1) { + written_date = new Date(value_y, value_m-1, value_d-adjust); + adjust++; + } + return written_date; } }