danielmoncada / date-time-picker

Angular Date Time Picker (Responsive Design)
https://daniel-projects.firebaseapp.com/owlng/date-time-picker
MIT License
141 stars 61 forks source link

Using UTC Makes Today wrong #85

Open Dedme opened 3 years ago

Dedme commented 3 years ago

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 commented 3 years ago

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.

danielmoncada commented 3 years ago

@Dedme thanks, appreciate the feedback. Will look into