bootstrap-ui-datetime-picker icon indicating copy to clipboard operation
bootstrap-ui-datetime-picker copied to clipboard

Change in Time changes the date

Open dudedev opened this issue 9 years ago • 17 comments

Hi, If there is change in time, it changes the date part also, even if the enable-date="false".

dudedev avatar Sep 11 '15 12:09 dudedev

This is because angular-ui timePicker uses a date and it was overwriting the one selected, which isnt a problem when using both date and time pickers. I have now changed the code so when the time is changed, it will not overwrite any part of the date. Uploading this version now, which is 1.2.2

Gillardo avatar Sep 14 '15 09:09 Gillardo

Issue still remains. If you clear out the time , it clears out the date as well.

dudedev avatar Sep 14 '15 14:09 dudedev

This is correct. If you press Clear, it will clear the model

On Mon, Sep 14, 2015 at 3:11 PM, dudedev [email protected] wrote:

Issue still remains. If you clear out the time , it clears out the date as well.

— Reply to this email directly or view it on GitHub https://github.com/Gillardo/bootstrap-ui-datetime-picker/issues/47#issuecomment-140088465 .

Gillardo avatar Sep 14 '15 14:09 Gillardo

But If someone wants to clear out the time, it should not change the date.. Isn't it...? Consider someone has two different fields for date and time on screen which uses the same model, chaning one changes the other...it will annoy the user.

dudedev avatar Sep 14 '15 14:09 dudedev

But clear should clear, the change your proposing is actually to set the hours, minutes and seconds to zero, as you cannot have a a blank time in a date object.

Your best bet would be to just create a watch on your model, and if is is null, restore just the date part of it with the original value. Something like

$scope.$watch(function() {
    return ctrl.yourModel;
}, function(oldValue, newValue) {
    if (newValue == null) {
        var date = oldValue;
        date.setHours(0);
        date.setMinutes(0);
        date.setSeconds(0);
        ctrl.yourModel = date;
    }
}

Even with this in place though, your time will still not be blank, but just set to midnight.

On Mon, Sep 14, 2015 at 3:27 PM, dudedev [email protected] wrote:

But If someone wants to clear out the time, it should not change the date.. Isn't it...? Consider someone has two different fields for date and time on screen which uses the same model, chaning one changes the other...it will annoy the user.

— Reply to this email directly or view it on GitHub https://github.com/Gillardo/bootstrap-ui-datetime-picker/issues/47#issuecomment-140098415 .

Gillardo avatar Sep 14 '15 14:09 Gillardo

Yes, Exactly, This is what I expect.

dudedev avatar Sep 14 '15 14:09 dudedev

So your saying. if clear it pressed on the datepicker, it should clear it. But if clear is pressed on the timePicker is should reset the time to 00:00:00?

On Mon, Sep 14, 2015 at 3:45 PM, dudedev [email protected] wrote:

Yes, Exactly, This is what I expect.

— Reply to this email directly or view it on GitHub https://github.com/Gillardo/bootstrap-ui-datetime-picker/issues/47#issuecomment-140104020 .

Gillardo avatar Sep 14 '15 14:09 Gillardo

Yes, I think if someone wants to use datepicker and timepicker separately using your library, he should be able to do so. If you use timepicker of bootstrap you use the same date model, but with bootstrap timepicker, it changes only the time, not the date part. Isn't it.?

dudedev avatar Sep 14 '15 14:09 dudedev

There's alot of datepickers and timepickers out there why would someone who wants to use only one or the other use a datetimepicker?

Kiruwagaka avatar May 17 '16 14:05 Kiruwagaka

Because on the system i used this for fields can be configured as date, time snd datetime On 17 May 2016 15:26, "Kiruwagaka" [email protected] wrote:

There's alot of datepickers and timepickers out there why would someone who wants to use only one or the other use a datetimepicker?

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/Gillardo/bootstrap-ui-datetime-picker/issues/47#issuecomment-219734571

Gillardo avatar May 17 '16 15:05 Gillardo

Plus this directive uses controls already in the angular-ui suite so no need for a whole new package to be included

Gillardo avatar May 17 '16 16:05 Gillardo

For anyone that stumbles onto this, newValue and oldValue arguments are switched, at least in angular 1.5. The code snippet worked for me. Thanks @Gillardo !

sb8244 avatar Jul 15 '16 04:07 sb8244

Issue still remains if you specify timezone in your date format. You can see it in this Plunker if you click down through the hours selector enough times you'll see the date randomly change. http://plnkr.co/edit/Zh1J8gSQjA9s1R3K9utE?p=preview

GalitMiller avatar Aug 25 '16 17:08 GalitMiller

I am having a problem where changing the time changes the date.

  • Open datetime picker;
  • Pick a day;
  • Delete the default hour on the hours field (make the input have an empty string);
  • The previously selected date is lost (it should've kept the day/month/year selected before);

Right now I can't make a gif of it to clarify what I mean, but whenever I can I'll do.

Using a $watcher is not a feasible thing for me to do because I use the this datetime in loads of forms, and creating a $watcher for every datetime picker is boring :)

N0NamedGuy avatar Oct 26 '16 16:10 N0NamedGuy

Can u make a plunkr to replicate?

Gillardo avatar Oct 26 '16 18:10 Gillardo

No need for a plunkr. You can replicate the bug in your demo page: https://rawgit.com/Gillardo/bootstrap-ui-datetime-picker/master/example/index.html using the date and time picker example.

So, the datetime-picker starts like this: step1


After picking a date (in this case picked October 1st, which is not today) step2


Then you get to pick the time step3


And if for any reason you need to delete part of time step4


You lost the previously inserted date step5


It would also be nice if the date part was kept on the text box, to assure the user that the previously selected date wasn't lost.

Thank you for reviewing this.

N0NamedGuy avatar Oct 28 '16 09:10 N0NamedGuy

N0NamedGuy: I have the exact problem that you reported :(

luisalves00 avatar Oct 28 '16 14:10 luisalves00