-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timezone Switching and TimeGutter Slots #1478
Comments
Here's a codesandbox that shows exactly what I'm talking about. Timezone will default to user current timezone, and you can switch timezones using the Select at the top of the screen. Event start and end times adjust accordingly, but you'll notice the timeslot min/max switch out as well. |
I figured out the magic sauce for getting the utils.js
Scheduler.component.js
Hope this helps someone else fight the good fight. I created a GitHub project too. |
@jquense I sent you an email, a few weeks back, asking about sponsoring full timezone support in RBC. Did you receive it? |
@cutterbl My guess is that the issue is the date manipulation library doesn't preserve or handle TZs correctly. One possible approach to fixing that is abstract manipulation (optionally) into the localizers, so that |
@cutterbl Hi, any updates? |
@egorkavin I haven't had any time to look into this myself. It's on my radar to take a pass at it in the future, if somebody doesn't get there first. |
@cutterbl Hi. Thank you for your efforts of supporting time zones. This is really hard work. Do you have any issues with dates where DST begins/ends? Let me try to explain I have I have the following code chunk:
And it gives me wrong 1-hour back shift on the calendar because time zone calculation going through DST shift on the 7th of Nov. The shift issue is under the moment package responsibility. I checked out moment docs and it says:
But
https://momentjs.com/docs/#/manipulating/add/ It looks correct for math calculation but for human schedule where people need to get up at 7am every morning doesn't. So we don't have a way to add minutes to the beginning of the day (the day when DST begins/ends) with preserving hours. Maybe you have ran into similar issue? Thanks |
@nlevchuk Moment-Timezone automatically handles offset shifts for DST changes in math calculations. While you are trying to set the import moment from 'moment-timezone'; // I'd use a specific 'data' set here
moment.tz.setDefault('Canada/Mountain');
momentLocalizer(moment);
...
// Moment is not immutable, so adjustments would be cumulative.
// Always clone a base prior to applying an adjustment
const currentDate = moment('2021-11-07T05:00:00-06:00').startOf('day');
const min = moment(currentDate).hour(7).toDate(); // => 7:00am
const max = moment(currentDate).hour(14).toDate(); // => 2:00pm
<Calendar
...
localizer={localizer}
min={min}
max={max}
/> |
I store some meaningful data as minutes since the beginning of a day. I need either to convert it to hours and minutes every time when I do some math calculation or revise my architecture. Anyway thanks for reply! PS |
Yeah, I have to say that Luxon is better for those cross TZ calculations, though it does require a flag. Can't remember all of the details though. |
Thanks |
Is it possible to stop overlapping of multiple events in single time slot? |
@Gaurav7004 Yes, using the dayLayoutAlgorithm prop |
So, I'm trying to write support for timezone switching for my calendar. I have a lot of things working, based on comments in an issue. The one thing I cannot get though is the proper min/max time display in the TimeGutter, and a current
now
. I'm using the momentLocalizer like so:This covers a good chunk of what I'm trying to do. When I switch timezones, my events shift accordingly to their proper timeslot. What fails is in using
min
andmax
to set the starting and ending hour timeslots on myday
andweek
views. These take JS date objects, even though it only appears to need the 'time' (and really the 24 hourhour
). Initially I set these like so:I also use
getNow
to set the current datetime at render. This also takes a JS date object, and thoughts were that you needed to convert this to the timezone as well:That didn't do it either. I then saw someone referenced using
defaultDate
instead ofgetNow
:No such luck. What I see is that 'right now' it's October 3rd in Chicago, but 'right now' is October 4th in Japan. No matter what I do the highlighted date is always 'my' (Chicago) 'right now'.
So back to times. I then thought that maybe I needed to convert my
min
andmax
, using the timezone, and then set thehour
:and that caused complete chaos. Seems to be unnecessary. Especially once I started looking at code...
I got into
TimeGrid
and found thatdates.merge()
was going to create a new Date object to pass to theTimeGutter
, and in theTimeGutter
I found that theslotMetrics
set up each group. So I went to find out how theslotMetrics
were built and found how it adjusted for DST offset (which is based on the JS Date object, and always relative to current browser date in it's offset).So, my localizer couldn't help me. Or, if it can I have no idea how. The localizer isn't used for any of these calculations, so they become moot. Or so it seems. If there is a way to do this, I haven't found it yet. Can anyone help? What combination of settings and localizer solve all of these issues?
General Real-World Use Case:
I have an organization that manages scheduling clinic appointments for multiple clinics in multiple timezones. The scheduler managing that scheduling must see a clinic's schedule in that clinic's timezone. So if the clinic is in Knoxville (Eastern Time), and is open from 7AM to 5PM, the scheduler (sitting in Memphis, which is Central Time) must see that clinic's hours as 7AM - 5AM.
Should Happen: user views Knoxville clinic schedule, and hours are 7am-5pm
Currently Happens: user views Knoxville clinic (which automatically switches tz to Eastern time) and the hours show 8am - 4pm
The text was updated successfully, but these errors were encountered: