Today's date indicator does not work properly when utcOffset is used
Hi,
I'm using the datepicker v0.37.0 with offset, like this: <DatePicker utcOffset={userUtcOffset()} ...
Let's say it's 6pm browser time and offset is set to 600. It means that there's 1day difference between local today and today with offset.
Today's button works correctly. It set's the right date (1 day after browser time). However today's indicator in the popup - red border and bold font - points to browser time.
Thanks, Marek Adamek
Hello,
Just a fallow-up. Is this bug scheduled for fixing? Is there an estimated date for release with the fix?
Thanks, Marek
I think this is because of this
https://github.com/Hacker0x01/react-datepicker/blob/master/src/date_utils.js#L5
This is because moment.utc().isSame(moment.utc().utcOffset(xx), 'day') returns always true
So i think the function isSameDay doesn't work properly in this specific case
Just an update. The issue is still present in v0.60.2
https://hacker0x01.github.io/react-datepicker/#example-9 seems to be working for me... (Tested at 2017-11-14 14:20 UTC, with CST local time and UTC offset +10:00: It correctly highlights and selects 2017-11-15 as "today".)
@marekadamek Could you provide steps to reproduce? What time zone are you in? In your original report, did you test at 6pm local time or 6pm UTC? Does the issue appear on the example page, or are you doing something different?
Ok. I did some investigation and found solution working for me. The datepicker definition I have looks like this:
<DatePicker
utcOffset={userUtcOffset() / 60}
name={name}
placeholderText={placeholder}
dateFormat={displayDateFormat}
todayButton={msg('buttons.today.label')}
selected={selectedDate}
openToDate={openToDate}
onBlur={this.handleBlur}
onChange={this.handleChange}
onFocus={onFocus}
minDate={minDate}
maxDate={maxDate}
startDate={type && (type === 'start' ? selectedDate : minDate)}
endDate={type && (type === 'end' ? selectedDate : maxDate)}
selectsStart={type && type === 'start'}
selectsEnd={type && type === 'end'}
className={form-control ${this.props.className}}
disabled={disabled}
showMonthDropdown
showYearDropdown
dropdownMode="select"
isClearable={clearable}
/>
I noticed that I was passing dates with different utc offsets. and in case of openToDate, startDate and endDate the provided offset was overriding the value provided in utcOffset prop.
I changed the code to always provide dates with the offset matching utcOffset and and problem disappeared. I'll leave it up to you to decide whether it is a bug or feature.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.