123 lines
2 KiB
TypeScript
123 lines
2 KiB
TypeScript
|
|
/**
|
|
*/
|
|
namespace _zeitbild.helpers
|
|
{
|
|
|
|
/**
|
|
* @todo timezone
|
|
*/
|
|
function ical_datetime_to_own_datetime(
|
|
ical_datetime : lib_plankton.ical.type_datetime
|
|
) : lib_plankton.pit.type_datetime
|
|
{
|
|
return {
|
|
"timezone_shift": 0,
|
|
"date": {
|
|
"year": ical_datetime.date.year,
|
|
"month": ical_datetime.date.month,
|
|
"day": ical_datetime.date.day,
|
|
},
|
|
"time": (
|
|
(ical_datetime.time === null)
|
|
?
|
|
null
|
|
:
|
|
{
|
|
"hour": ical_datetime.time.hour,
|
|
"minute": ical_datetime.time.minute,
|
|
"second": ical_datetime.time.second,
|
|
}
|
|
)
|
|
};
|
|
}
|
|
|
|
|
|
/**
|
|
* @todo timezone
|
|
*/
|
|
export function ical_dt_to_own_datetime(
|
|
ical_dt: lib_plankton.ical.type_dt
|
|
) : lib_plankton.pit.type_datetime
|
|
{
|
|
return {
|
|
"timezone_shift": 0,
|
|
"date": ical_dt.value.date,
|
|
"time": (
|
|
(ical_dt.value.time === null)
|
|
?
|
|
null
|
|
:
|
|
{
|
|
"hour": ical_dt.value.time.hour,
|
|
"minute": ical_dt.value.time.minute,
|
|
"second": ical_dt.value.time.second,
|
|
}
|
|
)
|
|
};
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
var _template_cache : Record<string, string> = {};
|
|
|
|
|
|
/**
|
|
* @todo caching
|
|
*/
|
|
export async function template_coin(
|
|
name : string,
|
|
data : Record<string, string>
|
|
) : Promise<string>
|
|
{
|
|
let content : string;
|
|
if (! (name in _template_cache)) {
|
|
content = (
|
|
(
|
|
await lib_plankton.file.read(
|
|
lib_plankton.string.coin(
|
|
"templates/{{name}}.html.tpl",
|
|
{
|
|
"name": name,
|
|
}
|
|
)
|
|
)
|
|
)
|
|
.toString()
|
|
);
|
|
_template_cache[name] = content;
|
|
}
|
|
else {
|
|
content = _template_cache[name];
|
|
}
|
|
return Promise.resolve<string>(
|
|
lib_plankton.string.coin(
|
|
content,
|
|
data
|
|
)
|
|
);
|
|
}
|
|
|
|
|
|
/**
|
|
* @todo outsource
|
|
*/
|
|
export async function promise_row<type_result>(
|
|
members : Array<
|
|
() => Promise<type_result>
|
|
>
|
|
) : Promise<
|
|
Array<
|
|
type_result
|
|
>
|
|
>
|
|
{
|
|
let results : Array<type_result> = [];
|
|
for await (const member of members) {
|
|
results.push(await member());
|
|
}
|
|
return Promise.resolve<Array<type_result>>(results);
|
|
}
|
|
|
|
}
|