import {date} from "quasar"; export const FORMAT_ISO = "YYYY-MM-DDTHH:mm:ss"; export const FORMAT_DATETIME_LONG = "DD. MM. YYYY, HH:mm"; export const FORMAT_DATE = "DD. MM. YYYY"; export const FORMAT_DATE_ISO = "YYYY-MM-DD"; export const FORMAT_TIME = "HH:mm" export const minutesToHumanReadable = (totalMinutes) => { const hours = Math.floor(totalMinutes / 60); const minutes = totalMinutes % 60; const hoursPart = hours > 0 ? `${hours}h ` : ""; return `${hoursPart}${minutes}min` } export const formatDatetimeNative = (date, format = "DD. MM. YYYY") => { if (typeof date === 'string') { date = parseDate(date); } return format .replace("DD", date.getDate().toString()) .replace("MM", (date.getMonth() + 1).toString()) .replace("YYYY", date.getFullYear().toString()) // todo: doplnit pocatecni nuly .replace("hh", date.getHours().toString()) .replace("mm", date.getMinutes().toString()) .replace("ss", date.getSeconds().toString()); } export const parseDateNative = (datetime) => { // const [date, time] = datetime.split("T"); // const [year, month, day] = date.split("-"); // const [hour, minute] = time.split(":"); // const dateObject = new Date(year, month, day, hour, minute, 0); // ^ tohle funguje ok const timestamp = Date.parse(datetime); return new Date(timestamp); } export const parseDate = (datetimeStr, format = FORMAT_ISO) => { return date.extractDate(datetimeStr, format) } export const formatDatetime = (datetime, format = FORMAT_DATETIME_LONG, inputFormat = FORMAT_ISO) => { if (typeof datetime === 'string') { datetime = parseDate(datetime, inputFormat); } return date.formatDate(datetime, format); }