date-time-picker icon indicating copy to clipboard operation
date-time-picker copied to clipboard

Using UTC Makes Today wrong

Open Dedme opened this issue 5 years ago • 2 comments

I am using UTC, because we only use Dates, no times, and its much easier to work through multiple layers of things when its all established as UTC.

however, the issue is that the 'today' circle is wrong, as it uses UTC also... (so maybe its 'correct'). it would be good if it used the local time, or provided another option to use local time for today.

i am in Australia (+9.5 or +10.5), this means anytime a user tries to use the system before 10:30 at the moment, the 'today' circle is in the previous day.

To me, the Today date should always be local, but i happy with a flag i can overwrite to not break others.

Dedme avatar Oct 27 '20 03:10 Dedme

Sorry i had massive head fog when i wrote the above. i fixed this in a patch for me by changing the Moment Adapter. /adapter/moment-adapter/moment-date-time-adapter.class.ts line 162


    public isSameDay( dateLeft: Moment, dateRight: Moment ): boolean {

        if (dateLeft && dateRight) {
            // PREVIOUS return this.clone(dateLeft).isSame(this.clone(dateRight), 'day');
            return dateLeft.isSame(this.clone(dateRight), 'day');
        }

        return dateLeft === dateRight;
    }

and then passing in local time in the Month component: https://github.com/danielmoncada/date-time-picker/blob/master/projects/picker/src/lib/date-time/calendar-month-view.component.ts line 517

                // check if the date is today
                if (
                    this.dateTimeAdapter.isSameDay(
                        //PREVIOUS: this.dateTimeAdapter.now(),
                        _moment(),
                        date
                    )
                ) {
                    this.todayDate = daysDiff + 1;
                }

of course this is the hacky fix, and would require something more robust and thought out, but i thought i would point you in the direction of the trouble spots.

Dedme avatar Oct 27 '20 05:10 Dedme

@Dedme thanks, appreciate the feedback. Will look into

danielmoncada avatar Nov 06 '20 06:11 danielmoncada