From 09c5ea8df5e1365a16fe4d6428187dc47cdfbb74 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Wed, 29 Jan 2014 10:18:07 +0000 Subject: [PATCH] fixed datetime widget returns march, if selecting febuary on a current date with a day >28 --- etemplate/js/et2_widget_date.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/etemplate/js/et2_widget_date.js b/etemplate/js/et2_widget_date.js index b39cb644bc..8f94d7db5c 100644 --- a/etemplate/js/et2_widget_date.js +++ b/etemplate/js/et2_widget_date.js @@ -82,7 +82,6 @@ var et2_date = et2_inputWidget.extend( // Update internal value when changed var self = this; this.input_date.datepicker("option","onSelect", function(text,inst) { - var d = new Date(); var date_inst = null; if(inst.inst && inst.inst.selectedYear) { @@ -92,12 +91,17 @@ var et2_date = et2_inputWidget.extend( { date_inst = inst; } + var d; // Date could be in different places, if it's a datetime or just date if(date_inst) { - d.setYear(date_inst.selectedYear); - d.setMonth(date_inst.selectedMonth); - d.setDate(date_inst.selectedDay); + // calling setYear(), setMonth() and setDate() one after the other can lead to unexpected results, + // if day is not valid for selected month, eg. setMonth(1/*=Feb*/) on a date-object with day>28 gives March + d = new Date(date_inst.selectedYear, date_inst.selectedMonth, date_inst.selectedDay); + } + else + { + d = new Date(); } if(inst && typeof inst.hour != 'undefined') {