[mod] date formatting [mod] caldav resource integration

This commit is contained in:
Fenris Wolf 2024-11-01 13:35:49 +01:00
parent 431f1a1847
commit 530c0ce116
5 changed files with 42 additions and 162 deletions

View file

@ -4,6 +4,7 @@
}, },
"tree": { "tree": {
"common.timezone_shift": "Zeitzonen-Verschiebung", "common.timezone_shift": "Zeitzonen-Verschiebung",
"common.timezone_indicator": "ZZ:",
"common.date": "Datum", "common.date": "Datum",
"common.time": "Uhrzeit", "common.time": "Uhrzeit",
"common.weekday.monday": "Mo", "common.weekday.monday": "Mo",
@ -23,6 +24,7 @@
"access_level.admin": "voll", "access_level.admin": "voll",
"event.event": "Termin", "event.event": "Termin",
"event.name": "Name", "event.name": "Name",
"event.when": "Zeit",
"event.begin": "Anfang", "event.begin": "Anfang",
"event.end": "Ende", "event.end": "Ende",
"event.location": "Ort", "event.location": "Ort",

View file

@ -4,6 +4,7 @@
}, },
"tree": { "tree": {
"common.timezone_shift": "Timezone shift", "common.timezone_shift": "Timezone shift",
"common.timezone_indicator": "TZ:",
"common.date": "date", "common.date": "date",
"common.time": "time", "common.time": "time",
"common.weekday.monday": "Mon", "common.weekday.monday": "Mon",
@ -23,6 +24,7 @@
"access_level.admin": "full", "access_level.admin": "full",
"event.event": "event", "event.event": "event",
"event.name": "name", "event.name": "name",
"event.when": "time",
"event.begin": "begin", "event.begin": "begin",
"event.end": "end", "event.end": "end",
"event.location": "location", "event.location": "location",

View file

@ -75,106 +75,6 @@ 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
*/
export function datetime_format(
datetime : (null | lib_plankton.pit.type_datetime)
) : string
{
if (datetime === null) {
return "-";
}
else {
return lib_plankton.string.coin(
"{{date}}{{macro_time}}",
{
"date": date_format(datetime.date),
"macro_time": (
(datetime.time === null)
?
""
:
lib_plankton.string.coin(
",{{time}}",
{
"time": time_format(datetime.time),
}
)
),
}
);
}
}
/**
*/
export function timespan_format(
from : lib_plankton.pit.type_datetime,
to : (null | lib_plankton.pit.type_datetime)
) : string
{
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;
}
/** /**
*/ */
export function input_access_level( export function input_access_level(

View file

@ -144,7 +144,15 @@ namespace _zeitbild.frontend_web.widgets.listview
{ {
"name_value": entry.event_object.name, "name_value": entry.event_object.name,
"calendar_value": entry.calendar_name, "calendar_value": entry.calendar_name,
"when_value": _zeitbild.frontend_web.helpers.timespan_format(entry.event_object.begin, entry.event_object.end), "when_value": lib_plankton.pit.timespan_format(
entry.event_object.begin,
entry.event_object.end,
{
"timezone_indicator": lib_plankton.translate.get("common.timezone_indicator"),
"adjust_to_ce": true,
"show_timezone": false,
}
),
"location_label": lib_plankton.translate.get("event.location"), "location_label": lib_plankton.translate.get("event.location"),
"location_extra_classes": ( "location_extra_classes": (
(entry.event_object.location === null) (entry.event_object.location === null)

View file

@ -127,65 +127,16 @@ namespace _zeitbild.frontend_web.widgets.weekview
lib_plankton.string.coin( lib_plankton.string.coin(
"{{label}}: {{value}}\n", "{{label}}: {{value}}\n",
{ {
"label": lib_plankton.translate.get("event.begin"), "label": lib_plankton.translate.get("event.when"),
"value": lib_plankton.string.coin( "value": lib_plankton.pit.timespan_format(
"{{hour}}:{{minute}}", event_object.begin,
event_object.end,
{ {
"hour": event_object.begin.time.hour.toFixed(0).padStart(2, "0"), "timezone_indicator": lib_plankton.translate.get("common.timezone_indicator"),
"minute": event_object.begin.time.minute.toFixed(0).padStart(2, "0"), "adjust_to_ce": true,
"show_timezone": true,
"omit_date": true,
} }
), // TODO: outsource
}
)
:
""
)
+
(
(event_object.end !== null)
?
lib_plankton.string.coin(
"{{label}}: {{value}}\n",
{
"label": lib_plankton.translate.get("event.end"),
"value": (
[
(
(
(event_object.end.date.year !== event_object.begin.date.year)
||
(event_object.end.date.month !== event_object.begin.date.month)
||
(event_object.end.date.day !== event_object.begin.date.day)
)
?
lib_plankton.string.coin(
"{{year}}-{{month}}-{{day}}",
{
"year": event_object.end.date.year.toFixed(0).padStart(4, "0"),
"month": event_object.end.date.month.toFixed(0).padStart(2, "0"),
"day": event_object.end.date.day.toFixed(0).padStart(2, "0"),
}
)
:
null
),
(
(event_object.end.time !== null)
?
lib_plankton.string.coin(
"{{hour}}:{{minute}}",
{
"hour": event_object.end.time.hour.toFixed(0).padStart(2, "0"),
"minute": event_object.end.time.minute.toFixed(0).padStart(2, "0"),
}
)
:
null
),
]
.filter(x => (x !== null))
.join(",")
), ),
} }
) )
@ -438,7 +389,24 @@ namespace _zeitbild.frontend_web.widgets.weekview
.forEach( .forEach(
(entry) => { (entry) => {
const distance_seconds : int = ( const distance_seconds : int = (
lib_plankton.pit.from_datetime(entry.event_object.begin) lib_plankton.pit.from_datetime(
/**
* so that events without a start time will be put in the correct box
*/
{
"timezone_shift": entry.event_object.begin.timezone_shift,
"date": entry.event_object.begin.date,
"time": (
entry.event_object.begin.time
??
{
"hour": 12,
"minute": 0,
"second": 0
}
),
}
)
- -
from_pit from_pit
); );
@ -626,7 +594,7 @@ namespace _zeitbild.frontend_web.widgets.weekview
"title": lib_plankton.call.convey( "title": lib_plankton.call.convey(
cell.pit, cell.pit,
[ [
lib_plankton.pit.to_datetime, lib_plankton.pit.to_datetime_ce,
(x : lib_plankton.pit.type_datetime) => lib_plankton.string.coin( (x : lib_plankton.pit.type_datetime) => lib_plankton.string.coin(
"{{year}}-{{month}}-{{day}}", "{{year}}-{{month}}-{{day}}",
{ {
@ -640,7 +608,7 @@ namespace _zeitbild.frontend_web.widgets.weekview
"day": lib_plankton.call.convey( "day": lib_plankton.call.convey(
cell.pit, cell.pit,
[ [
lib_plankton.pit.to_datetime, lib_plankton.pit.to_datetime_ce,
(x : lib_plankton.pit.type_datetime) => lib_plankton.string.coin( (x : lib_plankton.pit.type_datetime) => lib_plankton.string.coin(
"{{day}}", "{{day}}",
{ {
@ -654,7 +622,7 @@ namespace _zeitbild.frontend_web.widgets.weekview
"rel": lib_plankton.call.convey( "rel": lib_plankton.call.convey(
cell.pit, cell.pit,
[ [
lib_plankton.pit.to_datetime, lib_plankton.pit.to_datetime_ce,
(x : lib_plankton.pit.type_datetime) => lib_plankton.string.coin( (x : lib_plankton.pit.type_datetime) => lib_plankton.string.coin(
"{{year}}-{{month}}-{{day}}", "{{year}}-{{month}}-{{day}}",
{ {