Angular -pickadate time zone - selectedDate - the day before the modal date for other time zones

angular -pickadate works for my local time. To check global time, I changed my time zone to America / Denver. Now, the selected date is taken the day before today's date (the modal date has passed), so it uses the pickadate-active class yesterday. I tried passing modal dates with local timezone as well as UTC timezone. I don't know why dateHelper.parseDate calls again with the timezone value previously accepted disabled, now my understanding is $ locale, which converts the stripped date, assuming it is a UTC date for the local date. Therefore, being GMT-06: 00, the selected date approaches one date earlier.

HTML DIV - <div pickadate ng-model="vm.date" ng-model-options="{ debounce: 0 }" header="true" select="true" date-highlight-list="vm.dateList" ></div>

Controller - vm.date = moment().tz(timeZoneName).format();

can anyone suggest a way to handle different time zones using angular -pickadate ?? Thank you
GIT Directive URL - https://github.com/restorando/angular-pickadate

+5
source share
1 answer

The parseDate function gave the date object in accordance with the GMT time zone, so the date became one day less. Therefore, I removed this condition, which directly returned the GMT date for past date strings with a time zone.

 if (angular.isDate(dateString) || angular.isDate(new Date(dateString))) { new Date(dateString); } 

Now it moves on to the next one if the block formats the date with a regular expression and adds this condition for processing date strings and date objects -

 if(typeof dateString == 'object') { dateString = (dateString['_d'])? dateString['_d']: dateString['_i']; // being private (_d, _i) should be avoided but only way in mine case if(typeof dateString == 'object') // returns Object by dateString['_d'] else string dateString = dateString.getDate() +'-'+ dateString.getMonth() +'-' +dateString.getFullYear(); } dateParts = dateString.split(separator); // separator was "-" every time so making dateString with "-" in case it was object 
+3
source

Source: https://habr.com/ru/post/1268799/


All Articles