javascript - The angular datepicker totally mis-behavior as expectation -


i ran deadly chaos on datepicker issues.

who can solve problem can give 100 point return.

when click calendar on 2016-08-23 show me 2016-08-22 date value.

furthermore, date value in angular model not correct.

i want make output can consistent.

to reproduce buggy issue, change timezone between la , tokyo

inline

demo site: https://test.jiyubi.com/tour_package/home

inline

controller js

app.controller('tourpackagestartdatepickerctrl',     function ($scope) {          $scope.initstartdate = function () {            $scope.startdate = $scope.startdate || null;         };         $scope.initstartdate();           $scope.dateoptions = {             basedate: $scope.startdate,             mindate: $scope.startdate || moment.utc().todate(),         };          $scope.openstartdateclick = function () {             $scope.startdatepopup.opened = true;         };       });  app.controller('tourpackageenddatepickerctrl',     function ($scope, $rootscope) {          $scope.clear = function () {             $scope.enddate = null;         };          $scope.enddateoptions = {             datedisabled: disableddays,             basedate: new date(),         };          $scope.openenddateclick = function () {             $scope.enddatepopup.opened = true;         };           $scope.$watch("enddate", function (new_val, old_val) {             if (new_val && moment(new_val).isvalid()) {                 settraveldaterange($scope.startdate, $scope.enddate);             }         }, true)          function settraveldaterange(startdate, enddate) {             var start_date = moment_with_taipei_tz(startdate).format("yyyy/mm/dd");             var end_date = moment_with_taipei_tz(enddate).format("yyyy/mm/dd");             moment(startdate.todatestring()).tz("asia/taipei").format("yyyy/mm/dd");             $scope.q_param.startdate = start_date;             $scope.q_param.date_range = start_date + "-" + end_date;         }       }); 

helper.js

    function moment_with_taipei_tz(time){        return moment(time).tz("asia/taipei");     }      function moment_with_local(time){        return moment(time).local();     }      function discard_timezone(value) {        return moment.utc(value).format(default_moment_time_format);     }      function getyyyymmdd(value) {        return moment.utc(value).format("yyyy/mm/dd");     }      function date_without_timezone(value) {        return moment.utc(value).todate();     } 

it's may because timezone issue. youe please try convert date without considering timezone

this.converttodatewithouttimezone = function (date) {             if (date.tostring().match(/(\d\d\d\d)-(\d\d)-(\d\d)/)) {                 var year = $filter('date')(date.slice(0, 10), 'yyyy'),                     month = $filter('date')(date.slice(0, 10), 'mm'),                     day = $filter('date')(date.slice(0, 10), 'dd');                 return new date(year, month - 1, day);             }             else {                 return new date(date);             } 

};


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -