Browse Source

Merge pull request #5774 from valhalla-creator/bugfix/fix-due-date

Bugfix/fix due date
Lauri Ojansivu 2 weeks ago
parent
commit
6b36e126ab
3 changed files with 23 additions and 7 deletions
  1. 1 0
      client/components/cards/cardDate.js
  2. 11 7
      client/lib/datepicker.js
  3. 11 0
      client/lib/utils.js

+ 1 - 0
client/components/cards/cardDate.js

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

+ 11 - 7
client/lib/datepicker.js

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

+ 11 - 0
client/lib/utils.js

@@ -11,6 +11,17 @@ Utils = {
       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
    * <li> returns the current board id or the board id of the popup card if set
    */