Why do these bootstrap datepicker controls give inconsistent and incorrect time values?

Viewed 31

I have observed this odd behaviour in an Angular solution.

There is a filter section with four bsDatepicker controls - startDateFrom, startDateTo, endDateFrom and endDateto. As you can see, they have the following values (using British date format DD/MM/YYYY)

DatePicker controls

However, the actual values that are then passed back in the network payload in dev tools are very strange indeed.

Values shown in dev tools

The time portions highlighted in yellow are odd but I believe are one hour prior to the time I entered the values. The value highlighted in blue is completely incorrect - it's the selected date at midnight minus 1 hour, and therefore the date is the previous day! The bottom value seems the most correct (the correct date plus midnight).

There is no code in the angular .ts file that is amending these - they are located in a filter component and the values are simply passed to the API. Can anyone explain a possible reason for this inconsistency? Here's the markup:

<div class='col-md-3 pr-1'>
  <input autocomplete="off" id="startDateFrom" type="text" class="form-control date-input"
    placeholder="Pattern Start From (DD/MM/YYYY)" formControlName="startDateFrom" bsDatepicker
    [bsConfig]="{ dateInputFormat: 'DD/MM/YYYY', showWeekNumbers: false }" (ngModelChange)="onStartDateChange()"
    [maxDate]="filterForm.get('startDateTo') != null ? this.filterForm.get('startDateTo').value : null"
    [minDate]="minDate" windowScroll />
</div>
<div class='col-md-3 pr-1'>
  <input autocomplete="off" id="startDateTo" type="text" class="form-control date-input"
    placeholder="Pattern Start To (DD/MM/YYYY)" formControlName="startDateTo" bsDatepicker
    [attr.disabled]="!startDateEnabled ? '' : null"
    [bsConfig]="{ dateInputFormat: 'DD/MM/YYYY', showWeekNumbers: false }" (ngModelChange)="onStartDateChange()"
    [minDate]="filterForm.get('startDateFrom') != null ? this.filterForm.get('startDateFrom').value : null"
    windowScroll />
</div>
<div class='col-md-3 pr-1'>
  <input autocomplete="off" id="endDateFrom" type="text" class="form-control date-input"
    placeholder="Pattern End From (DD/MM/YYYY)" formControlName="endDateFrom" bsDatepicker
    [bsConfig]="{ dateInputFormat: 'DD/MM/YYYY', showWeekNumbers: false }" (ngModelChange)="onEndDateChange()"
    [maxDate]="filterForm.get('endDateTo') != null ? this.filterForm.get('endDateTo').value : null"
    [minDate]="minDate" windowScroll />
</div>
<div class='col-md-3'>
  <input autocomplete="off" id="endDateTo" type="text" class="form-control date-input"
    placeholder="Pattern End To (DD/MM/YYYY)" formControlName="endDateTo" bsDatepicker [bsConfig]="{ dateInputFormat: 'DD/MM/YYYY', showWeekNumbers:
    false }" (ngModelChange)="onEndDateChange()" [attr.disabled]="!endDateEnabled ? '' : null"
    [minDate]="filterForm.get('endDateFrom') != null ? this.filterForm.get('endDateFrom').value : null"
    windowScroll />
</div>
1 Answers

Turns out that this is a bug in the bsDatepicker which seems to barf for UK users around the time when BST changes to GMT (and vice versa), normally around the vernal and autumnal equinox.

Related