WhatSock / apex

Apex 4X: The Comprehensive ARIA Development Suite
MIT License
29 stars 9 forks source link

Datepicker / Calendar and UTC time #37

Closed mfs-bldmghty closed 1 year ago

mfs-bldmghty commented 1 year ago

I have an array of dates:

e.g. arrNew = [ '20230111', '20230125', '20230208', '20230222']

These are dates that are selectable, everything else is going to be disabled.

What I'm doing, at least currently, is using a forEach():

        getAllDates(new Date(), new Date(maxDate)).forEach(function(date){
           // remove '-' from date string
            let dateStr = date.toISOString().slice(0,10).replace(/-/g, '');
            if ( ! arrNew[dateStr] ) {
                dsDP.setMonthDisabled(dsDP, date, true);
                dsDP.setDayDisabled(dsDP, date, true);
            } else {
                dsDP.setDayDisabled(dsDP, date, false);
                dsDP.setDayMarked(dsDP, date, 'isMarked');
            }
        });

However, I believe I'm running into an issue with UTC time, maybe? (Note: I understand you're not here for JS support but since there might be secrets / magic you're familiar with from working with the datepicker, I wanted to ask. You can say, "No, sorry. Can't help." )

In any case, over the past week or so, I've worked later a couple of days. (Past 7.00 pm Eastern Time). At that point, I believe it's tomorrow in UTC time, and that throw off everything. For example, instead of '20230111' being available, '20230110' is. All my available days shift forward one day.

Any thoughts / suggestions would be welcomed and appreciated.

Otherwise, so far so good. I've gottne more comfortable with the options and being able to style the FE. It's coming along nicely, sans this time of day issue :(

p.s. Happy New Year

mfs-bldmghty commented 1 year ago

Along the same lines, is there was way to manually - in the config / setting object - set the current date? Else, and perhaps I'm wrong new Date()'s current will be in UTM and since UTM will eventually be tomorrow when it's still today today - If you know what I mean :) - I need to be able to say my my today is, not new Date()'s UTM "now".

accdc commented 1 year ago

Hi, that is odd. I've used my own version of the datepicker many times leading up to midnight on my own machine and it always sets the correct disabled dates. I'll look into this some more and see if I can identify the problem. Happy new year to you as well. :)

accdc commented 1 year ago

Hi, It looks like the time offset issue you are having is occurring because of the "toISOString()" method.

According to: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString "The timezone is always zero UTC offset, as denoted by the suffix Z."

About your second question about setting a specific start date, yes of course.

// Allow a date that isn't today to be set as the initial date. If unset, this value is initialised to today's date initialDate: new Date(),

mfs-bldmghty commented 1 year ago

I can do the current date as the browser's date. If that works, I don't want to fix it :) Thanks.

However, ultimately, I need to schedule (i.e., allow pickable dates) relative to a specific timezone. A timezone that comes from settings in the backend (that are passed to the FE).

I don't want to (read: can't) assume the user will be in the same time zone as the region we're scheduling for.

Let me look at this some more today. Thanks again for your help.

mfs-bldmghty commented 1 year ago

Thinking out load...I think what I need to do is use the brower's timezone and then offset that against the desired time zone.

I wish I was a time traveler, this would an easier model to construct in my head. lol