Jiny pristup k vytvareni letu, polofunkcni editace letu
This commit is contained in:
@@ -4,9 +4,35 @@ export const minutesToHumanReadable = (totalMinutes) => {
|
||||
return `${hours}h ${minutes}min`
|
||||
}
|
||||
|
||||
export const formatDate = (date) => {
|
||||
export const formatDate = (date, format = "DD. MM. YYYY") => {
|
||||
if (typeof date === 'string') {
|
||||
date = new Date(date);
|
||||
date = parseDate(date);
|
||||
}
|
||||
return date.getDate()+". "+date.getMonth()+". "+date.getFullYear();
|
||||
|
||||
return format
|
||||
.replace("DD", date.getDate().toString())
|
||||
.replace("MM", (date.getMonth() + 1).toString())
|
||||
.replace("YYYY", date.getFullYear().toString());
|
||||
}
|
||||
|
||||
|
||||
export const parseDate = (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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user