ngx-bootstrap icon indicating copy to clipboard operation
ngx-bootstrap copied to clipboard

Datepicker forces time to current time

Open kragoth opened this issue 4 years ago • 5 comments

Bug description:

The datepicker is forcing the time portion of values to be the current time. I believe this behaviour was introduced by PR: https://github.com/valor-software/ngx-bootstrap/pull/6275. Specifically if the config has "withTimepicker: false,", then the following logic will apply when initializing the value:

bs-datepicker-inline.component.ts:99 (set bsValue function)

    if (!this._bsValue && value && !this._config.withTimepicker) {
       const now = new Date();
       copyTime(value, now);
     }

This means if I'm trying to deal with dates that do not have a time component, I no longer receve 00:00:00.000 as the time. Instead I receive the current time in the time portion of the date.

Now, I figured all I need to do was add "initCurrentTime: false" to my config but, as you can see above that logic ignores the "initCurrentTime" configuration.

I think the above logic should honour the "initCurrentTime" configuration and not override the time if that is set to false.

I can't seem to get Stackblitz to see version 7.1.2 so I can't create one.

kragoth avatar Oct 01 '21 03:10 kragoth

I have a similar issue. Here's a simple repro demonstrating how the value of the form control is set to the current time. You can see the value of the form control printed below the input. Happening in 7.10, 7.1.1, 7.1.2.

Edit: not happening with version 6.2.0

garethdn avatar Oct 04 '21 15:10 garethdn

this got fixed Got fixed to latest https://github.com/valor-software/ngx-bootstrap/pull/6288

mukuljai avatar Oct 06 '21 04:10 mukuljai

The issue persists in a similar manner: When you change the date while inline datepicker is present, during the rendering, the datepicker writes into current date (mutates the Date object) setting the previously set time.

It happens in the reducer: https://github.com/valor-software/ngx-bootstrap/blob/e93950bd9f3477c99886d2db0a725bf645c66943/src/datepicker/reducer/bs-datepicker.reducer.ts#L93-L98

kvetis avatar Oct 22 '21 11:10 kvetis

This issue is back it seems. From what i can see has #6288 been overwritten. The datepicker component will not use the "initCurrentTime" value.

https://github.com/valor-software/ngx-bootstrap/blob/6be9fc4d0214aa641f0a0c46c12efb3b65e0278c/src/datepicker/bs-datepicker.component.ts#L144-L151

Dwightojo avatar Apr 08 '22 14:04 Dwightojo

Any update on this issue? Or anyone came up with a workaround by any chance? Thanks

leandro-galluppi avatar May 16 '23 22:05 leandro-galluppi