Thanks to xet7 !

Fixes #5782
This commit is contained in:
Lauri Ojansivu 2025-05-25 00:22:47 +03:00
parent 1979b1692d
commit aaa5f9885d
3 changed files with 7 additions and 23 deletions

View file

@ -1,4 +1,3 @@
import { Utils } from '/client/lib/utils';
import moment from 'moment/min/moment-with-locales'; import moment from 'moment/min/moment-with-locales';
import { TAPi18n } from '/imports/i18n'; import { TAPi18n } from '/imports/i18n';
import { DatePicker } from '/client/lib/datepicker'; import { DatePicker } from '/client/lib/datepicker';

View file

@ -83,8 +83,7 @@ export class DatePicker extends BlazeComponent {
{ {
'keyup .js-date-field'() { 'keyup .js-date-field'() {
// parse for localized date format in strict mode // parse for localized date format in strict mode
const normalizedValue = Utils.normalizeDigits(this.find('#date').value); const dateMoment = moment(this.find('#date').value, 'L', true);
const dateMoment = moment(normalizedValue, 'L', true);
if (dateMoment.isValid()) { if (dateMoment.isValid()) {
this.error.set(''); this.error.set('');
this.$('.js-datepicker').datepicker('update', dateMoment.toDate()); this.$('.js-datepicker').datepicker('update', dateMoment.toDate());
@ -92,9 +91,8 @@ export class DatePicker extends BlazeComponent {
}, },
'keyup .js-time-field'() { 'keyup .js-time-field'() {
// parse for localized time format in strict mode // parse for localized time format in strict mode
const normalizedValue = Utils.normalizeDigits(this.find('#time').value);
const dateMoment = moment( const dateMoment = moment(
normalizedValue, this.find('#time').value,
adjustedTimeFormat(), adjustedTimeFormat(),
true, true,
); );
@ -106,14 +104,12 @@ export class DatePicker extends BlazeComponent {
evt.preventDefault(); evt.preventDefault();
// if no time was given, init with 12:00 // if no time was given, init with 12:00
const timeValue = Utils.normalizeDigits(evt.target.time.value);
const time = const time =
timeValue || evt.target.time.value ||
moment(new Date().setHours(12, 0, 0)).format('LT'); moment(new Date().setHours(12, 0, 0)).format('LT');
const newTime = moment(time, adjustedTimeFormat(), true); const newTime = moment(time, adjustedTimeFormat(), true);
const dateValue = Utils.normalizeDigits(evt.target.date.value); const newDate = moment(evt.target.date.value, 'L', true);
const newDate = moment(dateValue, 'L', true); const dateString = `${evt.target.date.value} ${time}`;
const dateString = `${dateValue} ${time}`;
const newCompleteDate = moment( const newCompleteDate = moment(
dateString, dateString,
`L ${adjustedTimeFormat()}`, `L ${adjustedTimeFormat()}`,

View file

@ -11,17 +11,6 @@ Utils = {
currentBoard.setColor(currentBoard["background-color"]); currentBoard.setColor(currentBoard["background-color"]);
} }
}, },
// Normalize non-Western (Persian/Arabic) digits to Western Arabic (0-9)
// This helps with date parsing in non-English languages
normalizeDigits(str) {
if (!str) return str;
const persian = [/۰/g, /۱/g, /۲/g, /۳/g, /۴/g, /۵/g, /۶/g, /۷/g, /۸/g, /۹/g];
const arabic = [/٠/g, /١/g, /٢/g, /٣/g, /٤/g, /٥/g, /٦/g, /٧/g, /٨/g, /٩/g];
for (let i = 0; i < 10; i++) {
str = str.replace(persian[i], i).replace(arabic[i], i);
}
return str;
},
/** returns the current board id /** returns the current board id
* <li> returns the current board id or the board id of the popup card if set * <li> returns the current board id or the board id of the popup card if set
*/ */