Prepracovana prace s datem, lepsi input na datetime
This commit is contained in:
@@ -1,10 +1,17 @@
|
||||
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 formatDate = (date, format = "DD. MM. YYYY") => {
|
||||
export const formatDatetimeNative = (date, format = "DD. MM. YYYY") => {
|
||||
if (typeof date === 'string') {
|
||||
date = parseDate(date);
|
||||
}
|
||||
@@ -12,27 +19,37 @@ export const formatDate = (date, format = "DD. MM. YYYY") => {
|
||||
return format
|
||||
.replace("DD", date.getDate().toString())
|
||||
.replace("MM", (date.getMonth() + 1).toString())
|
||||
.replace("YYYY", date.getFullYear().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 parseDate = (datetime) => {
|
||||
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);
|
||||
const now = new Date();
|
||||
const dateObject = new Date(timestamp);
|
||||
// dateObject.setHours(dateObject.getHours() + now.getTimezoneOffset());
|
||||
// console.log("date", date);
|
||||
// console.log("time", time);
|
||||
// console.log("month", month, dateObject.getMonth(), dateObject.getUTCMonth());
|
||||
// console.log("day", day, dateObject.getDate(), dateObject.getUTCDate());
|
||||
|
||||
return dateObject;
|
||||
return new Date(timestamp);
|
||||
}
|
||||
|
||||
|
||||
export const parseDate = (datetimeStr, format = FORMAT_ISO) => {
|
||||
return date.extractDate(datetimeStr, format)
|
||||
}
|
||||
|
||||
export const formatDatetime = (datetime, format = FORMAT_DATETIME_LONG) => {
|
||||
console.log("orignal ", datetime);
|
||||
if (typeof datetime === 'string') {
|
||||
datetime = parseDate(datetime);
|
||||
}
|
||||
|
||||
console.log(datetime);
|
||||
|
||||
return date.formatDate(datetime, format);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user