install and use luxon for date and tz functions
This commit is contained in:
@ -10,7 +10,9 @@ import { bgBG } from '../x-date-pickers/locales/bgBG';
|
||||
import { ToastContainer } from 'react-toastify';
|
||||
const common = require('src/helpers/common');
|
||||
//todo import Availability type from prisma schema
|
||||
import { isBefore, addMinutes, isAfter, isEqual, set, getHours, getMinutes, getSeconds } from 'date-fns';
|
||||
import { isBefore, addMinutes, isAfter, isEqual, set, getHours, getMinutes, getSeconds } from 'date-fns'; //ToDo obsolete
|
||||
|
||||
const { DateTime, FixedOffsetZone } = require('luxon');
|
||||
|
||||
|
||||
|
||||
@ -187,15 +189,34 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o
|
||||
|
||||
// Common function to set shared properties
|
||||
function setSharedAvailabilityProperties(availability, group, timeSlots) {
|
||||
let startTime = new Date(availability.startTime || day);
|
||||
startTime.setHours(group[0].startTime.getHours(), group[0].startTime.getMinutes(), group[0].startTime.getSeconds(), 0);
|
||||
// Define a fixed offset for Sofia (+2 hours from UTC, ignoring DST)
|
||||
const fixedZone = FixedOffsetZone.instance(120); // Offset in minutes
|
||||
|
||||
let endTime = new Date(availability.endTime || day);
|
||||
endTime.setHours(group[group.length - 1].endTime.getHours(), group[group.length - 1].endTime.getMinutes(), group[group.length - 1].endTime.getSeconds(), 0);
|
||||
// availability.startTime = group[0].startTime;
|
||||
// availability.endTime = group[group.length - 1].endTime;
|
||||
// Adjust start time
|
||||
let startTime = DateTime.fromJSDate(group[0].startTime, { zone: 'utc' })
|
||||
.setZone(fixedZone, { keepLocalTime: true });
|
||||
startTime = startTime.set({
|
||||
hour: group[0].startTime.getUTCHours(),
|
||||
minute: group[0].startTime.getUTCMinutes(),
|
||||
second: group[0].startTime.getUTCSeconds()
|
||||
});
|
||||
|
||||
availability.startTime = startTime;
|
||||
availability.endTime = endTime;
|
||||
availability.name = common.getTimeFomatted(startTime) + "-" + common.getTimeFomatted(endTime);
|
||||
// Adjust end time
|
||||
let endTime = DateTime.fromJSDate(group[group.length - 1].endTime, { zone: 'utc' })
|
||||
.setZone(fixedZone, { keepLocalTime: true });
|
||||
endTime = endTime.set({
|
||||
hour: group[group.length - 1].endTime.getUTCHours(),
|
||||
minute: group[group.length - 1].endTime.getUTCMinutes(),
|
||||
second: group[group.length - 1].endTime.getUTCSeconds()
|
||||
});
|
||||
|
||||
// Update the availability object with the new times
|
||||
availability.startTime = startTime.toJSDate();
|
||||
availability.endTime = endTime.toJSDate();
|
||||
|
||||
availability.name = common.getTimeFomatted(group[0].startTime) + "-" + common.getTimeFomatted(group[group.length - 1].endTime);
|
||||
|
||||
availability.isWithTransportIn = group[0].isFirst && timeSlots[0].isWithTransport;
|
||||
availability.isWithTransportOut = group[group.length - 1].isLast && timeSlots[timeSlots.length - 1].isWithTransport;
|
||||
@ -209,7 +230,7 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o
|
||||
} else {
|
||||
availability.type = "OneTime"
|
||||
availability.repeatWeekly = false;
|
||||
availability.dayOfMonth = startTime.getDate();
|
||||
availability.dayOfMonth = availability.startTime.getDate();
|
||||
availability.endDate = null;
|
||||
}
|
||||
availability.isFromPreviousMonth = false;
|
||||
@ -286,7 +307,8 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o
|
||||
const slots = [];
|
||||
let currentTime = start;
|
||||
|
||||
const baseDate = new Date(Date.UTC(2000, 0, 1, 0, 0, 0));
|
||||
//const baseDate = new Date(Date.UTC(2000, 0, 1, 0, 0, 0));
|
||||
const baseDate = new Date(start);
|
||||
|
||||
while (isBefore(currentTime, end)) {
|
||||
let slotStart = normalizeTime(currentTime, baseDate);
|
||||
|
Reference in New Issue
Block a user