fix rotation/override updating

This commit is contained in:
Maxim 2022-08-29 14:11:44 +03:00
parent 47045aaaf9
commit 25dc2eb3e5
4 changed files with 16 additions and 10 deletions

View file

@ -82,11 +82,11 @@ const Rotation: FC<RotationProps> = (props) => {
const dayOffset = Math.floor((x / width) * 7);
console.log('event.offsetX', event.offsetX);
/* console.log('event.offsetX', event.offsetX);
console.log('event.nativeEvent', event.nativeEvent);
console.log('event.currentTarget', event.currentTarget);
console.log('dayOffset', dayOffset);
*/
onClick(startMoment.add(dayOffset, 'day'));
};

View file

@ -213,10 +213,10 @@ const RotationForm: FC<RotationFormProps> = observer((props) => {
useEffect(() => {
if (shift) {
setRotationStart(getDateTime(shift.rotation_start));
setRotationEnd(getDateTime(shift.until));
setShiftStart(getDateTime(shift.shift_start));
setShiftEnd(getDateTime(shift.shift_end));
setRotationStart(getDateTime(shift.rotation_start, currentTimezone));
setRotationEnd(getDateTime(shift.until, currentTimezone));
setShiftStart(getDateTime(shift.shift_start, currentTimezone));
setShiftEnd(getDateTime(shift.shift_end, currentTimezone));
setEndless(!shift.until);
setRepeatEveryValue(shift.interval);

View file

@ -140,8 +140,8 @@ const ScheduleOverrideForm: FC<RotationFormProps> = (props) => {
useEffect(() => {
if (shift) {
setShiftStart(getDateTime(shift.shift_start));
setShiftEnd(getDateTime(shift.shift_end));
setShiftStart(getDateTime(shift.shift_start, currentTimezone));
setShiftEnd(getDateTime(shift.shift_end, currentTimezone));
setUserGroups(shift.rolling_users);
}

View file

@ -679,10 +679,16 @@ export const getUTCString = (moment: dayjs.Dayjs | DateTime, timezone: Timezone)
.format('YYYY-MM-DDTHH:mm:ss.000Z');
};
export const getDateTime = (date: string) => {
export const getDateTime = (date: string, timezone: Timezone) => {
const browserTimezone = dayjs.tz.guess();
const browserTimezoneOffset = dayjs().tz(browserTimezone).utcOffset();
const timezoneOffset = dayjs().tz(timezone).utcOffset();
return dateTime(dayjs(date).subtract(browserTimezoneOffset, 'minutes').format('YYYY-MM-DDTHH:mm:ss.000Z'));
return dateTime(
dayjs(date)
.subtract(browserTimezoneOffset, 'minutes')
.add(timezoneOffset, 'minutes')
.format('YYYY-MM-DDTHH:mm:ss.000Z')
);
};