fix(dm): abbott truck time corrections
This commit is contained in:
@@ -1,34 +1,60 @@
|
||||
import { getJsDateFromExcel } from "excel-date-to-js";
|
||||
|
||||
export const excelDateStuff = (serial: number, time: any = 0) => {
|
||||
// console.log(serial);
|
||||
// add 5 hours or the offset to utc
|
||||
// export const excelDateStuff = (serial: number, time?: any) => {
|
||||
// // add 5 hours or the offset to utc
|
||||
|
||||
// get the local timezone
|
||||
const localoffset = new Date().getTimezoneOffset() / 60; // then divide by 60 to get the true number;
|
||||
// // get the local timezone
|
||||
// const localoffset = new Date().getTimezoneOffset() / 60; // then divide by 60 to get the true number;
|
||||
|
||||
if (serial % 1 === 0) {
|
||||
time = 800;
|
||||
}
|
||||
// if (!time) {
|
||||
// time = 800;
|
||||
// }
|
||||
|
||||
const addHours = serial + localoffset / 24;
|
||||
//console.log(getJsDateFromExcel(addHours));
|
||||
if (typeof serial !== "number" || serial <= 0) {
|
||||
return "invalid Date";
|
||||
}
|
||||
// const addHours = serial + localoffset / 24;
|
||||
// //console.log(getJsDateFromExcel(addHours));
|
||||
// if (typeof serial !== "number" || serial <= 0) {
|
||||
// return "invalid Date";
|
||||
// }
|
||||
|
||||
const date = getJsDateFromExcel(addHours); // base date from Excel serial
|
||||
// const date = getJsDateFromExcel(addHours); // base date from Excel serial
|
||||
|
||||
if (time != 0) {
|
||||
// convert the time over to hour and min
|
||||
const hours = Math.floor(time / 100);
|
||||
const minutes = time % 100;
|
||||
date.setHours(hours);
|
||||
date.setMinutes(minutes);
|
||||
}
|
||||
//console.log(date.toLocaleString("en-US"), getJsDateFromExcel(addHours));
|
||||
// if (time != 0) {
|
||||
// // convert the time over to hour and min
|
||||
// const hours = Math.floor(time / 100);
|
||||
// const minutes = time % 100;
|
||||
// date.setHours(hours);
|
||||
// date.setMinutes(minutes);
|
||||
// }
|
||||
// //console.log(date.toLocaleString("en-US"), getJsDateFromExcel(addHours));
|
||||
|
||||
//console.log(serial);
|
||||
//console.log(date.toISOString());
|
||||
return date.toISOString(); //.toLocaleString("en-US"); // or .toISOString() if preferred
|
||||
// //console.log(serial);
|
||||
// console.log(date.toISOString(), serial, time);
|
||||
// return date.toISOString(); //.toLocaleString("en-US"); // or .toISOString() if preferred
|
||||
// };
|
||||
|
||||
export const excelDateStuff = (serial: number, time?: any) => {
|
||||
if (typeof serial !== "number" || serial <= 0) {
|
||||
return "invalid Date";
|
||||
}
|
||||
|
||||
// Default time to 8:00 AM if not provided
|
||||
if (!time) {
|
||||
time = 800;
|
||||
}
|
||||
|
||||
// Get base date from Excel serial (this gives you UTC midnight)
|
||||
const date = getJsDateFromExcel(serial);
|
||||
|
||||
const localOffset = new Date().getTimezoneOffset() / 60;
|
||||
const hours = Math.floor(time / 100);
|
||||
const minutes = time % 100;
|
||||
|
||||
// Set the time in UTC
|
||||
date.setUTCHours(hours + localOffset);
|
||||
date.setUTCMinutes(minutes);
|
||||
date.setUTCSeconds(0);
|
||||
date.setUTCMilliseconds(0);
|
||||
|
||||
//console.log(date.toISOString(), serial, time);
|
||||
return date.toISOString();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user