mdehoog / Semantic-UI-Calendar

Calendar module for Semantic UI
MIT License
805 stars 127 forks source link

Conflict between day and month #103

Open yaayes opened 6 years ago

yaayes commented 6 years ago

Hi, I have a page that use SUI-calendar, and I parse time from database with format YYYY-mm-dd HH:SS, I parse it to an input when calendar load, date like 2017-07-06 00:00 changed to 2017-06-07 00:00, he replace day by month only for some date, for example date like 2017-07-16 00:00 still no error, I think because 16 is not a valid month.

And this how i load Semantic-UI-Calendar:

// Load datetime Picker
  let config = {
    ampm: false,
    monthFirst: false,
    formatter: {
      date: function (date, settings) {
        if (!date) return '';
        var day = date.getDate();
        var month = date.getMonth() + 1;
        var year = date.getFullYear();
        return year + '-' + month + '-' + day;
      }
    },
    text: {
      days: ['الأحد', 'الإثنين', 'الثلاثاء', 'الأربعاء', 'الخميس', 'الجمعة', 'السبت'],
      months: ['يناير', 'فبراير', 'مارس', 'ابريل', 'ماي', 'يونيو', 'يوليوز', 'غشت', 'سبتمبر', 'أكتوبر', 'نوفمبر', 'ديسمبر'],
      monthsShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
      today: 'اليوم',
      now: 'الان'
    }
  }
  $('.post-date-picker').calendar(config);

CC @mdehoog

ghost commented 6 years ago

Hi, I had a similar problem today. I think is because you don't have a parser in your config object. Try to add this:

parser: {
      date: function (text, settings) {
        //return a date parsed from 'text'
      }
    }

Regards