52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
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_TIME = "HH:mm"
|
|
|
|
export const minutesToHumanReadable = (totalMinutes) => {
|
|
const hours = Math.round(totalMinutes / 60);
|
|
const minutes = totalMinutes % 60;
|
|
return `${hours}h ${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) => {
|
|
if (typeof datetime === 'string') {
|
|
datetime = parseDate(datetime);
|
|
}
|
|
return date.formatDate(datetime, format);
|
|
}
|