Skip to content
Snippets Groups Projects
Verified Commit 910c9388 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

feat: new datetimeformat

parent 2166be37
No related branches found
No related tags found
No related merge requests found
......@@ -673,6 +673,25 @@ function transform(value) {
throw new Error(`unsupported locale or missing format (${e.message})`);
}
case "datetimeformat":
date = new Date(value);
if (isNaN(date.getTime())) {
throw new Error("invalid date");
}
const options = {
dateStyle: args.shift() || "medium",
timeStyle: args.shift() || "medium",
};
try {
locale = getLocaleOfDocument();
return new Intl.DateTimeFormat(locale, options).format(date)
} catch (e) {
throw new Error(`unsupported locale or missing format (${e.message})`);
}
case "datetime":
date = new Date(value);
if (isNaN(date.getTime())) {
......
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Popper Button</title>
<script src="main.mjs" type="module"></script>
</head>
<body id="mybody">
<h1>Monday</h1>
<monster-monday data-monster-script-host="mybody" id="monday" data-monster-option-a-b-c="ddddddd"></monster-monday>
</body>
import {CustomElement,registerCustomElement} from "../../../application/source/dom/customelement.mjs"
class Monday extends CustomElement {
static getTag() {
return "monster-monday"
}
get defaults() {
return Object.assign({}, super.defaults, {
templates: {
main: myHtml()
},
a : {
b : {
c:"hallo"
}
}})}
}
function myHtml() {
return '<div data-monster-replace="path:a.b.c "></div>'
}
const o=document.querySelector("monster-monday")
o.initCustomControlCallback = (elem) => {
elem.setOption("a.b.c","xxxx")
}
registerCustomElement(Monday)
......@@ -28,6 +28,9 @@ describe('Transformer', function () {
describe('Transformer.run()', function () {
[
['datetimeformat', "2023-02-04 08:02:01", "04.02.2023, 08:02:01"],
['datetimeformat:long:short', "2023-02-04 08:02:01","4. Februar 2023 um 08:02"],
['datetimeformat:short:short', "2023-02-04 08:02:01", "04.02.23, 08:02"],
['equals:a', "a", true],
['equals:a', "b", false],
['equals:3', 3, true],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment