angular-datepicker icon indicating copy to clipboard operation
angular-datepicker copied to clipboard

Time is reset when selecting date

Open dmbjsn opened this issue 8 years ago • 0 comments

Hi,

Assuming date-picker="data.someModel" and min-view="date", when date is selected, data.someModel gets the time 00:00. I have another directive (a slider) to handle time, so I don't want this behaviour. If the view stops at date-level, it makes no sense that the time is affected. Until I figure out something better, I am using this hack in angular-datepicker.js to preserve the existing time:

function setDate(date) {
    if (date) {
        // Hack because time was set to 00:00
        if (moment.isMoment(scope.model)) {
            date.hour(scope.model.hour());
            date.minutes(scope.model.minutes());
        }
        // END Hack

        scope.model = date;
        if (ngModel) {
            ngModel.$setViewValue(date);
        }
    }
    scope.$emit('setDate', scope.model, scope.view);

    //This is duplicated in the new functionality.
    if (scope.callbackOnSetDate) {
        scope.callbackOnSetDate(attrs.datePicker, scope.date);
    }
}

dmbjsn avatar Feb 04 '16 14:02 dmbjsn