diff --git a/app/assets/javascripts/discourse/app/lib/public-js-versions.js b/app/assets/javascripts/discourse/app/lib/public-js-versions.js
index a8ced62efaa..f807c36c3f4 100644
--- a/app/assets/javascripts/discourse/app/lib/public-js-versions.js
+++ b/app/assets/javascripts/discourse/app/lib/public-js-versions.js
@@ -10,5 +10,5 @@ export const PUBLIC_JS_VERSIONS = {
"diffhtml.min.js": "diffhtml/1.0.0-beta.20/diffhtml.min.js",
"jquery.magnific-popup.min.js":
"magnific-popup/1.1.0/jquery.magnific-popup.min.js",
- "pikaday.js": "pikaday/1.8.0/pikaday.js",
+ "pikaday.js": "pikaday/1.8.2/pikaday.js",
};
diff --git a/package.json b/package.json
index 7ca44b41886..8366ebe15b9 100644
--- a/package.json
+++ b/package.json
@@ -18,7 +18,7 @@
"magnific-popup": "1.1.0",
"moment": "2.29.4",
"moment-timezone": "0.5.39",
- "pikaday": "1.8.0",
+ "pikaday": "1.8.2",
"squoosh": "discourse/squoosh#dc9649d",
"workbox-cacheable-response": "^4.3.1",
"workbox-core": "^4.3.1",
diff --git a/public/javascripts/pikaday/1.8.0/pikaday.js b/public/javascripts/pikaday/1.8.2/pikaday.js
similarity index 93%
rename from public/javascripts/pikaday/1.8.0/pikaday.js
rename to public/javascripts/pikaday/1.8.2/pikaday.js
index 8dae8382cde..61642454d18 100755
--- a/public/javascripts/pikaday/1.8.0/pikaday.js
+++ b/public/javascripts/pikaday/1.8.2/pikaday.js
@@ -99,8 +99,8 @@
isLeapYear = function(year)
{
- // solution by Matti Virkkunen: http://stackoverflow.com/a/4881951
- return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
+ // solution lifted from date.js (MIT license): https://github.com/datejs/Datejs
+ return ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0);
},
getDaysInMonth = function(year, month)
@@ -183,7 +183,7 @@
// automatically show/hide the picker on `field` focus (default `true` if `field` is set)
bound: undefined,
- // data-attribute on the input field with an aria assistance tekst (only applied when `bound` is set)
+ // data-attribute on the input field with an aria assistance text (only applied when `bound` is set)
ariaLabel: 'Use the arrow keys to pick a date',
// position of the datepicker, relative to the field (default to bottom & left)
@@ -212,6 +212,10 @@
// first day of week (0: Sunday, 1: Monday etc)
firstDay: 0,
+ // minimum number of days in the week that gets week number one
+ // default ISO 8601, week 01 is the week with the first Thursday (4)
+ firstWeekOfYearMinDays: 4,
+
// the default flag for moment's strict date parsing
formatStrict: false,
@@ -349,11 +353,35 @@
'';
},
- renderWeek = function (d, m, y) {
- // Lifted from http://javascript.about.com/library/blweekyear.htm, lightly modified.
- var onejan = new Date(y, 0, 1),
- weekNum = Math.ceil((((new Date(y, m, d) - onejan) / 86400000) + onejan.getDay()+1)/7);
- return '
' + weekNum + '
';
+ isoWeek = function(date, firstWeekOfYearMinDays) {
+ // Ensure we're at the start of the day.
+ date.setHours(0, 0, 0, 0);
+
+ // Thursday in current week decides the year because January 4th
+ // is always in the first week according to ISO8601.
+ var yearDay = date.getDate(),
+ weekDay = date.getDay(),
+ dayInFirstWeek = firstWeekOfYearMinDays,
+ dayShift = dayInFirstWeek - 1, // counting starts at 0
+ daysPerWeek = 7,
+ prevWeekDay = function(day) { return (day + daysPerWeek - 1) % daysPerWeek; };
+
+ // Adjust to Thursday in week 1 and count number of weeks from date to week 1.
+ date.setDate(yearDay + dayShift - prevWeekDay(weekDay));
+
+ var jan4th = new Date(date.getFullYear(), 0, dayInFirstWeek),
+ msPerDay = 24 * 60 * 60 * 1000,
+ daysBetween = (date.getTime() - jan4th.getTime()) / msPerDay,
+ weekNum = 1 + Math.round((daysBetween - dayShift + prevWeekDay(jan4th.getDay())) / daysPerWeek);
+
+ return weekNum;
+ },
+
+ renderWeek = function (d, m, y, firstWeekOfYearMinDays) {
+ var date = new Date(y, m, d),
+ week = hasMoment ? moment(date).isoWeek() : isoWeek(date, firstWeekOfYearMinDays);
+
+ return '
' + week + '
';
},
renderRow = function(days, isRTL, pickWholeWeek, isRowSelected)
@@ -393,7 +421,7 @@
for (arr = [], i = 0; i < 12; i++) {
arr.push('');
}
@@ -524,7 +552,6 @@
}
break;
case 37:
- e.preventDefault();
self.adjustDate('subtract', 1);
break;
case 38:
@@ -536,10 +563,26 @@
case 40:
self.adjustDate('add', 7);
break;
+ case 8:
+ case 46:
+ self.setDate(null);
+ break;
}
}
};
+ self._parseFieldValue = function()
+ {
+ if (opts.parse) {
+ return opts.parse(opts.field.value, opts.format);
+ } else if (hasMoment) {
+ var date = moment(opts.field.value, opts.format, opts.formatStrict);
+ return (date && date.isValid()) ? date.toDate() : null;
+ } else {
+ return new Date(Date.parse(opts.field.value));
+ }
+ };
+
self._onInputChange = function(e)
{
var date;
@@ -547,15 +590,7 @@
if (e.firedBy === self) {
return;
}
- if (opts.parse) {
- date = opts.parse(opts.field.value, opts.format);
- } else if (hasMoment) {
- date = moment(opts.field.value, opts.format, opts.formatStrict);
- date = (date && date.isValid()) ? date.toDate() : null;
- }
- else {
- date = new Date(Date.parse(opts.field.value));
- }
+ date = self._parseFieldValue();
if (isDate(date)) {
self.setDate(date);
}
@@ -640,11 +675,7 @@
addEvent(opts.field, 'change', self._onInputChange);
if (!opts.defaultDate) {
- if (hasMoment && opts.field.value) {
- opts.defaultDate = moment(opts.field.value, opts.format).toDate();
- } else {
- opts.defaultDate = new Date(Date.parse(opts.field.value));
- }
+ opts.defaultDate = self._parseFieldValue();
opts.setDefaultDate = true;
}
}
@@ -825,6 +856,14 @@
}
},
+ /**
+ * clear and reset the date
+ */
+ clear: function()
+ {
+ this.setDate(null);
+ },
+
/**
* change view to a specific date
*/
@@ -1004,9 +1043,8 @@
}
}
- randId = 'pika-title-' + Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 2);
-
for (var c = 0; c < opts.numberOfMonths; c++) {
+ randId = 'pika-title-' + Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 2);
html += '