[mod] helpers:date formatting

This commit is contained in:
Fenris Wolf 2024-10-03 11:07:39 +02:00
parent d7aaeb153a
commit 801eddb661

View file

@ -75,6 +75,42 @@ namespace _zeitbild.frontend_web.helpers
}
/**
* @todo timezone
*/
export function date_format(
date : lib_plankton.pit.type_date
) : string
{
return lib_plankton.string.coin(
"{{year}}-{{month}}-{{day}}",
{
"year": date.year.toFixed(0).padStart(4, "0"),
"month": date.month.toFixed(0).padStart(2, "0"),
"day": date.day.toFixed(0).padStart(2, "0"),
}
);
}
/**
* @todo timezone
*/
export function time_format(
time : lib_plankton.pit.type_time
) : string
{
return lib_plankton.string.coin(
"{{hour}}:{{minute}}",
{
"hour": time.hour.toFixed(0).padStart(2, "0"),
"minute": time.minute.toFixed(0).padStart(2, "0"),
"second": time.second.toFixed(0).padStart(2, "0"),
}
);
}
/**
* @todo timezone
*/
@ -89,14 +125,7 @@ namespace _zeitbild.frontend_web.helpers
return lib_plankton.string.coin(
"{{date}}{{macro_time}}",
{
"date": lib_plankton.string.coin(
"{{year}}-{{month}}-{{day}}",
{
"year": datetime.date.year.toFixed(0).padStart(4, "0"),
"month": datetime.date.month.toFixed(0).padStart(2, "0"),
"day": datetime.date.day.toFixed(0).padStart(2, "0"),
}
),
"date": date_format(datetime.date),
"macro_time": (
(datetime.time === null)
?
@ -105,14 +134,7 @@ namespace _zeitbild.frontend_web.helpers
lib_plankton.string.coin(
",{{time}}",
{
"time": lib_plankton.string.coin(
"{{hour}}:{{minute}}",
{
"hour": datetime.time.hour.toFixed(0).padStart(2, "0"),
"minute": datetime.time.minute.toFixed(0).padStart(2, "0"),
"second": datetime.time.second.toFixed(0).padStart(2, "0"),
}
),
"time": time_format(datetime.time),
}
)
),
@ -129,24 +151,28 @@ namespace _zeitbild.frontend_web.helpers
to : (null | lib_plankton.pit.type_datetime)
) : string
{
return lib_plankton.string.coin(
"{{from}}{{macro_to}}",
{
"from": datetime_format(from),
"macro_to": (
(to === null)
?
""
:
lib_plankton.string.coin(
" - {{to}}",
{
"to": datetime_format(to),
let result : string = "";
result += datetime_format(from);
if (to === null) {
// do nothing
}
)
),
else {
result += " - ";
if (
(from.date.year === to.date.year)
&&
(from.date.month === to.date.month)
&&
(from.date.day === to.date.day)
) {
// only time
result += time_format(to.time);
}
);
else {
result += datetime_format(to);
}
}
return result;
}
/**