Files
BeWoPlaner/BeWoPlanerMobil/Scripts/ownSoft-Scripts/utils/dateUtils.js

88 lines
2.4 KiB
JavaScript
Raw Normal View History

function parseTimeInputToIntegerArray(timeString) {
2025-03-28 15:44:19 +01:00
const hoursToMinutes = timeString.split(":");
const hours = parseInt(hoursToMinutes[0]);
const minutes = parseInt(hoursToMinutes[1]);
return [hours, minutes];
2022-02-15 17:22:14 +01:00
}
function dateToShortDateString(date) {
try {
if (isValidDate(date)) {
2025-03-28 15:44:19 +01:00
const ddNum = date.getDate();
const mmNum = date.getMonth();
const yyyyNum = date.getFullYear();
2022-02-15 17:22:14 +01:00
2025-03-28 15:44:19 +01:00
let dd = ddNum.toString();
let mm = mmNum.toString();
let yyyy = yyyyNum.toString();
2022-02-15 17:22:14 +01:00
if (ddNum < 10) {
2025-03-28 15:44:19 +01:00
dd = `0${dd}`;
2022-02-15 17:22:14 +01:00
}
if (mmNum < 10) {
2025-03-28 15:44:19 +01:00
mm = `0${mm}`;
2022-02-15 17:22:14 +01:00
}
if (yyyyNum < 10) {
2025-03-28 15:44:19 +01:00
yyyy = `000${yyyyNum}`;
2022-02-15 17:22:14 +01:00
} else if (yyyyNum < 100) {
2025-03-28 15:44:19 +01:00
yyyy = `00${yyyyNum}`;
2022-02-15 17:22:14 +01:00
} else if (yyyyNum < 1000) {
2025-03-28 15:44:19 +01:00
yyyy = `0${yyyyNum}`;
2022-02-15 17:22:14 +01:00
}
return dd + "." + mm + "." + yyyy;
}
} catch (error) {
2025-03-28 15:44:19 +01:00
window.showErrorPopup(error);
2022-02-15 17:22:14 +01:00
}
}
function mergeDateAndTime(date, time) {
var result = new Date();
try {
if(isValidDate(date) && isValidDate(time)) {
2025-03-28 15:44:19 +01:00
const day = date.getDate();
const month = date.getMonth();
const year = date.getFullYear();
const hours = time.getHours();
const minutes = time.getMinutes();
2022-02-15 17:22:14 +01:00
result = new Date(year, month, day, hours, minutes, 0, 0);
}
} catch(error) {
2025-03-28 15:44:19 +01:00
window.showErrorPopup(error);
2022-02-15 17:22:14 +01:00
} finally {
return result;
}
}
2023-02-09 15:17:33 +01:00
// ToDo: Löst Exception aus bei einem Wert von z.B. "06.02.2023".
2022-02-15 17:22:14 +01:00
function isValidDate(date) {
return Object.prototype.toString.call(date) === "[object Date]" && !isNaN(date);
}
2025-03-28 15:44:19 +01:00
function ddMMyyyyToyyyyMMdd(dateString) {
if (dateString === undefined || dateString === null || typeof dateString != "string" || dateString.length !== 10) {
return null;
}
2025-03-28 15:44:19 +01:00
const dayMonthYear = dateString.split(".");
if(dayMonthYear.length !== 3) {
return null;
}
2025-03-28 15:44:19 +01:00
const dd = dayMonthYear[0];
const mm = dayMonthYear[1];
const yyyy = dayMonthYear[2];
return `${yyyy}-${mm}-${dd}`;
}
function toStringWithSeconds(date) {
return `${date.getDate()}.${date.getMonth()}.${date.getFullYear()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
}