From 74fae05dac079e5c0e20a57bdc47ee42427b2ef1 Mon Sep 17 00:00:00 2001 From: suresh Date: Sat, 21 Nov 2015 01:42:37 +0530 Subject: [PATCH 01/10] New options startHour and endHour --- .../static/js/bootstrap-datetimepicker.js | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/datetimewidget/static/js/bootstrap-datetimepicker.js b/datetimewidget/static/js/bootstrap-datetimepicker.js index 9ba9888..cef4ba5 100644 --- a/datetimewidget/static/js/bootstrap-datetimepicker.js +++ b/datetimewidget/static/js/bootstrap-datetimepicker.js @@ -208,6 +208,8 @@ this.setStartDate(options.startDate || this.element.data('date-startdate')); this.setEndDate(options.endDate || this.element.data('date-enddate')); this.setDaysOfWeekDisabled(options.daysOfWeekDisabled || this.element.data('date-days-of-week-disabled')); + this.startHour = (options.startHour || 0) + this.endHour = (options.endHour || 24) this.fillDow(); this.fillMonths(); this.update(); @@ -605,7 +607,7 @@ html = []; var txt = '', meridian = '', meridianOld = ''; - for (var i = 0; i < 24; i++) { + for (var i = this.startHour; i < this.endHour; i++) { var actual = UTCDate(year, month, dayMonth, i); clsName = ''; // We want the previous hour for the startDate @@ -625,7 +627,7 @@ meridianOld = meridian; txt = (i % 12 ? i % 12 : 12); html.push('' + txt + ''); - if (i == 23) { + if (i == this.endHour - 1) { html.push(''); } } else { @@ -711,7 +713,13 @@ hour = d.getUTCHours(); switch (this.viewMode) { case 0: - if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() + if (this.startHour) { + if (hour <= this.startHour) { + this.picker.find('.prev').css({visibility: 'hidden'}); + } else { + this.picker.find('.prev').css({visibility: 'visible'}); + } + } else if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth() && day <= this.startDate.getUTCDate() && hour <= this.startDate.getUTCHours()) { @@ -719,7 +727,13 @@ } else { this.picker.find('.prev').css({visibility: 'visible'}); } - if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() + if (this.endHour < 24) { + if (hour >= this.endHour-1) { + this.picker.find('.next').css({visibility: 'hidden'}); + } else { + this.picker.find('.next').css({visibility: 'visible'}); + } + } else if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth() && day >= this.endDate.getUTCDate() && hour >= this.endDate.getUTCHours()) { From 0e8b1768f5862825b1c771a7ed3af91fc8f1b946 Mon Sep 17 00:00:00 2001 From: suresh Date: Thu, 26 Nov 2015 22:39:45 +0530 Subject: [PATCH 02/10] start & end hours --- datetimewidget/static/js/bootstrap-datetimepicker.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/datetimewidget/static/js/bootstrap-datetimepicker.js b/datetimewidget/static/js/bootstrap-datetimepicker.js index cef4ba5..46c731d 100644 --- a/datetimewidget/static/js/bootstrap-datetimepicker.js +++ b/datetimewidget/static/js/bootstrap-datetimepicker.js @@ -540,6 +540,13 @@ endMonth = this.endDate !== Infinity ? this.endDate.getUTCMonth() : Infinity, currentDate = (new UTCDate(this.date.getUTCFullYear(), this.date.getUTCMonth(), this.date.getUTCDate())).valueOf(), today = new Date(); + if (hours < this.startHour) { + hours = this.startHour; + this.viewDate = UTCDate(year, month, dayMonth, hours, 0, 0); + } else if (hours >= this.endHour) { + hours = this.endHour - 1; + this.viewDate = UTCDate(year, month, dayMonth, hours, 0, 0); + } this.picker.find('.datetimepicker-days thead th:eq(1)') .text(dates[this.language].months[month] + ' ' + year); if (this.formatViewType == "time") { From 7657faf539a8dd38fad0570daecce038c524bb76 Mon Sep 17 00:00:00 2001 From: suresh Date: Tue, 29 Mar 2016 15:39:40 +0530 Subject: [PATCH 03/10] allow minuteSteps of an hour or more --- .gitignore | 1 + datetimewidget/static/js/bootstrap-datetimepicker.js | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4b6b5bc..04db668 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea *.pyc +*.*~ django_datetime_widget.egg-info diff --git a/datetimewidget/static/js/bootstrap-datetimepicker.js b/datetimewidget/static/js/bootstrap-datetimepicker.js index 46c731d..f32d5f2 100644 --- a/datetimewidget/static/js/bootstrap-datetimepicker.js +++ b/datetimewidget/static/js/bootstrap-datetimepicker.js @@ -375,6 +375,9 @@ }, setValue: function () { + if (this.minuteStep > 30) { + this.date.setUTCMinutes(0) + } var formatted = this.getFormattedDate(); if (!this.isInput) { if (this.component) { @@ -614,7 +617,11 @@ html = []; var txt = '', meridian = '', meridianOld = ''; - for (var i = this.startHour; i < this.endHour; i++) { + var incr = 1; + if (this.minuteStep > 60) { + incr = this.minuteStep / 60; + } + for (var i = this.startHour; i < this.endHour; i+=incr) { var actual = UTCDate(year, month, dayMonth, i); clsName = ''; // We want the previous hour for the startDate From d6275593452d8e1fa000c0b185ba5e1a6d863c6c Mon Sep 17 00:00:00 2001 From: suresh Date: Tue, 29 Mar 2016 23:55:54 +0530 Subject: [PATCH 04/10] all day option --- datetimewidget/static/js/bootstrap-datetimepicker.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/datetimewidget/static/js/bootstrap-datetimepicker.js b/datetimewidget/static/js/bootstrap-datetimepicker.js index f32d5f2..c334fea 100644 --- a/datetimewidget/static/js/bootstrap-datetimepicker.js +++ b/datetimewidget/static/js/bootstrap-datetimepicker.js @@ -375,7 +375,10 @@ }, setValue: function () { - if (this.minuteStep > 30) { + if (this.minuteStep == 1440) { + this.date.setUTCHours(0) + this.date.setUTCMinutes(0) + } else if (this.minuteStep > 30) { this.date.setUTCMinutes(0) } var formatted = this.getFormattedDate(); From 70bd6cdb73a4cc01cd7290ac656d701bae0d1020 Mon Sep 17 00:00:00 2001 From: suresh Date: Wed, 7 Sep 2016 16:13:34 +0530 Subject: [PATCH 05/10] support different start and end depending on day of week --- .../static/js/bootstrap-datetimepicker.js | 44 +++++++++++++++++-- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/datetimewidget/static/js/bootstrap-datetimepicker.js b/datetimewidget/static/js/bootstrap-datetimepicker.js index c334fea..af56141 100644 --- a/datetimewidget/static/js/bootstrap-datetimepicker.js +++ b/datetimewidget/static/js/bootstrap-datetimepicker.js @@ -208,8 +208,20 @@ this.setStartDate(options.startDate || this.element.data('date-startdate')); this.setEndDate(options.endDate || this.element.data('date-enddate')); this.setDaysOfWeekDisabled(options.daysOfWeekDisabled || this.element.data('date-days-of-week-disabled')); - this.startHour = (options.startHour || 0) - this.endHour = (options.endHour || 24) + this.sunStartHour = (options.sunStartHour || 0) + this.sunEndHour = (options.sunEndHour || 24) + this.monStartHour = (options.monStartHour || 0) + this.monEndHour = (options.monEndHour || 24) + this.tueStartHour = (options.tueStartHour || 0) + this.tueEndHour = (options.tueEndHour || 24) + this.wedStartHour = (options.wedStartHour || 0) + this.wedEndHour = (options.wedEndHour || 24) + this.thuStartHour = (options.thuStartHour || 0) + this.thuEndHour = (options.thuEndHour || 24) + this.friStartHour = (options.friStartHour || 0) + this.friEndHour = (options.friEndHour || 24) + this.satStartHour = (options.satStartHour || 0) + this.satEndHour = (options.satEndHour || 24) this.fillDow(); this.fillMonths(); this.update(); @@ -624,10 +636,34 @@ if (this.minuteStep > 60) { incr = this.minuteStep / 60; } - for (var i = this.startHour; i < this.endHour; i+=incr) { - var actual = UTCDate(year, month, dayMonth, i); + var actual = UTCDate(year, month, dayMonth); + var dayOfWeek = actual.getUTCDay() + if (dayOfWeek == 0) { + myStartHour = this.sunStartHour; + myEndHour = this.sunEndHour; + } else if (dayOfWeek == 1) { + myStartHour = this.monStartHour; + myEndHour = this.monEndHour; + } else if (dayOfWeek == 2) { + myStartHour = this.tueStartHour; + myEndHour = this.tueEndHour; + } else if (dayOfWeek == 3) { + myStartHour = this.wedStartHour; + myEndHour = this.wedEndHour; + } else if (dayOfWeek == 4) { + myStartHour = this.thuStartHour; + myEndHour = this.thuEndHour; + } else if (dayOfWeek == 5) { + myStartHour = this.friStartHour; + myEndHour = this.friEndHour; + } else { + myStartHour = this.satStartHour; + myEndHour = this.satEndHour; + } + for (var i = myStartHour; i < myEndHour; i+=incr) { clsName = ''; // We want the previous hour for the startDate + var actual = UTCDate(year, month, dayMonth, i); if ((actual.valueOf() + 3600000) <= this.startDate || actual.valueOf() > this.endDate) { clsName += ' disabled'; } else if (hours == i) { From ca7e4454d5d567d64a0f569a50dfd126e6f10c0c Mon Sep 17 00:00:00 2001 From: suresh Date: Wed, 7 Sep 2016 22:35:39 +0530 Subject: [PATCH 06/10] some more changes --- .../static/js/bootstrap-datetimepicker.js | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/datetimewidget/static/js/bootstrap-datetimepicker.js b/datetimewidget/static/js/bootstrap-datetimepicker.js index af56141..d073717 100644 --- a/datetimewidget/static/js/bootstrap-datetimepicker.js +++ b/datetimewidget/static/js/bootstrap-datetimepicker.js @@ -558,11 +558,34 @@ endMonth = this.endDate !== Infinity ? this.endDate.getUTCMonth() : Infinity, currentDate = (new UTCDate(this.date.getUTCFullYear(), this.date.getUTCMonth(), this.date.getUTCDate())).valueOf(), today = new Date(); - if (hours < this.startHour) { - hours = this.startHour; + var dayOfWeek = d.getUTCDay() + if (dayOfWeek == 0) { + myStartHour = this.sunStartHour; + myEndHour = this.sunEndHour; + } else if (dayOfWeek == 1) { + myStartHour = this.monStartHour; + myEndHour = this.monEndHour; + } else if (dayOfWeek == 2) { + myStartHour = this.tueStartHour; + myEndHour = this.tueEndHour; + } else if (dayOfWeek == 3) { + myStartHour = this.wedStartHour; + myEndHour = this.wedEndHour; + } else if (dayOfWeek == 4) { + myStartHour = this.thuStartHour; + myEndHour = this.thuEndHour; + } else if (dayOfWeek == 5) { + myStartHour = this.friStartHour; + myEndHour = this.friEndHour; + } else { + myStartHour = this.satStartHour; + myEndHour = this.satEndHour; + } + if (hours < myStartHour) { + hours = myStartHour this.viewDate = UTCDate(year, month, dayMonth, hours, 0, 0); - } else if (hours >= this.endHour) { - hours = this.endHour - 1; + } else if (hours >= myEndHour) { + hours = myEndHour - 1; this.viewDate = UTCDate(year, month, dayMonth, hours, 0, 0); } this.picker.find('.datetimepicker-days thead th:eq(1)') From 1d18d659a285e3f4ece7b1adb6dc38eba289fe99 Mon Sep 17 00:00:00 2001 From: suresh Date: Thu, 8 Sep 2016 11:24:12 +0530 Subject: [PATCH 07/10] daysOfWeek not being split correctly --- .../static/js/bootstrap-datetimepicker.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/datetimewidget/static/js/bootstrap-datetimepicker.js b/datetimewidget/static/js/bootstrap-datetimepicker.js index d073717..a62ce97 100644 --- a/datetimewidget/static/js/bootstrap-datetimepicker.js +++ b/datetimewidget/static/js/bootstrap-datetimepicker.js @@ -433,7 +433,7 @@ setDaysOfWeekDisabled: function (daysOfWeekDisabled) { this.daysOfWeekDisabled = daysOfWeekDisabled || []; if (!$.isArray(this.daysOfWeekDisabled)) { - this.daysOfWeekDisabled = this.daysOfWeekDisabled.split(/,\s*/); + this.daysOfWeekDisabled = this.daysOfWeekDisabled.split(''); } this.daysOfWeekDisabled = $.map(this.daysOfWeekDisabled, function (d) { return parseInt(d, 10); @@ -638,11 +638,11 @@ prevMonth.getUTCDate() == today.getDate()) { clsName += ' today'; } - if (prevMonth.valueOf() == currentDate) { + if ($.inArray(prevMonth.getUTCDay(), this.daysOfWeekDisabled) !== -1) { + clsName += ' disabled'; + } else if (prevMonth.valueOf() == currentDate) { clsName += ' active'; - } - if ((prevMonth.valueOf() + 86400000) <= this.startDate || prevMonth.valueOf() > this.endDate || - $.inArray(prevMonth.getUTCDay(), this.daysOfWeekDisabled) !== -1) { + } else if ((prevMonth.valueOf() + 86400000) <= this.startDate || prevMonth.valueOf() > this.endDate) { clsName += ' disabled'; } html.push('' + prevMonth.getUTCDate() + ''); @@ -687,7 +687,8 @@ clsName = ''; // We want the previous hour for the startDate var actual = UTCDate(year, month, dayMonth, i); - if ((actual.valueOf() + 3600000) <= this.startDate || actual.valueOf() > this.endDate) { + if ((actual.valueOf() + 3600000) <= this.startDate || actual.valueOf() > this.endDate || + $.inArray(actual.getUTCDay(), this.daysOfWeekDisabled) !== -1) { clsName += ' disabled'; } else if (hours == i) { clsName += ' active'; From 19f894c136da2579a3c91b42584dabfaf8b71756 Mon Sep 17 00:00:00 2001 From: suresh Date: Fri, 23 Feb 2018 11:40:07 +0530 Subject: [PATCH 08/10] disable nav arrows when u hit start/end hours --- .../static/js/bootstrap-datetimepicker.js | 22 ++----------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/datetimewidget/static/js/bootstrap-datetimepicker.js b/datetimewidget/static/js/bootstrap-datetimepicker.js index a62ce97..45aa802 100644 --- a/datetimewidget/static/js/bootstrap-datetimepicker.js +++ b/datetimewidget/static/js/bootstrap-datetimepicker.js @@ -790,30 +790,12 @@ hour = d.getUTCHours(); switch (this.viewMode) { case 0: - if (this.startHour) { - if (hour <= this.startHour) { - this.picker.find('.prev').css({visibility: 'hidden'}); - } else { - this.picker.find('.prev').css({visibility: 'visible'}); - } - } else if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() - && month <= this.startDate.getUTCMonth() - && day <= this.startDate.getUTCDate() - && hour <= this.startDate.getUTCHours()) { + if (hour <= myStartHour) { this.picker.find('.prev').css({visibility: 'hidden'}); } else { this.picker.find('.prev').css({visibility: 'visible'}); } - if (this.endHour < 24) { - if (hour >= this.endHour-1) { - this.picker.find('.next').css({visibility: 'hidden'}); - } else { - this.picker.find('.next').css({visibility: 'visible'}); - } - } else if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() - && month >= this.endDate.getUTCMonth() - && day >= this.endDate.getUTCDate() - && hour >= this.endDate.getUTCHours()) { + if (hour >= myEndHour-1) { this.picker.find('.next').css({visibility: 'hidden'}); } else { this.picker.find('.next').css({visibility: 'visible'}); From 1bcdec6996607888aeaa7208d1ce629ea3af6164 Mon Sep 17 00:00:00 2001 From: suresh Date: Tue, 8 May 2018 16:55:53 +0530 Subject: [PATCH 09/10] django 1.11 --- datetimewidget/widgets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datetimewidget/widgets.py b/datetimewidget/widgets.py index 908d76f..1068019 100644 --- a/datetimewidget/widgets.py +++ b/datetimewidget/widgets.py @@ -224,7 +224,7 @@ def __init__(self, attrs=None, options=None, usel10n=None, bootstrap_version=Non super(PickerWidgetMixin, self).__init__(attrs, format=self.format) def render(self, name, value, attrs=None): - final_attrs = self.build_attrs(attrs) + final_attrs = self.build_attrs(self.attrs, attrs) rendered_widget = super(PickerWidgetMixin, self).render(name, value, final_attrs) #if not set, autoclose have to be true. From a6a4c75bcb7230512da5cd8845a973b8555e835f Mon Sep 17 00:00:00 2001 From: suresh Date: Mon, 19 Oct 2020 17:36:39 +0530 Subject: [PATCH 10/10] django22 --- datetimewidget/widgets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datetimewidget/widgets.py b/datetimewidget/widgets.py index 1068019..5cf804a 100644 --- a/datetimewidget/widgets.py +++ b/datetimewidget/widgets.py @@ -223,7 +223,7 @@ def __init__(self, attrs=None, options=None, usel10n=None, bootstrap_version=Non super(PickerWidgetMixin, self).__init__(attrs, format=self.format) - def render(self, name, value, attrs=None): + def render(self, name, value, renderer=None, attrs=None): final_attrs = self.build_attrs(self.attrs, attrs) rendered_widget = super(PickerWidgetMixin, self).render(name, value, final_attrs)