Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions web/system_date_time_format.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const getDateTimeFormatPattern = (options) => {
const parts = new Intl.DateTimeFormat(void 0, options).formatToParts(new Date());
const hasDayPeriod = parts.some(part => part.type == "dayPeriod");
return parts.map(part => {
switch (part.type) {
case "weekday": return "EEEE";
case "day": return "d".repeat(part.value.length);
case "month": return "M".repeat(Math.min(4, part.value.length));
case "year": return "y".repeat(part.value.length);
case "hour": return hasDayPeriod ? "h" : "HH";
case "minute": return "m".repeat(part.value.length);
case "second": return "s".repeat(part.value.length);
case "literal": return part.value;
case "dayPeriod": return "a";
default: return "";
}
})
.join("");
};

const getDateFormat = () => getDateTimeFormatPattern({ dateStyle: "short" });
const getMediumDateFormat = () => getDateTimeFormatPattern({ dateStyle: "medium" });
const getLongDateFormat = () => getDateTimeFormatPattern({ dateStyle: "long" });
const getFullDateFormat = () => getDateTimeFormatPattern({ dateStyle: "full" });
const getTimeFormat = () => getDateTimeFormatPattern({ timeStyle: "short" });
2 changes: 1 addition & 1 deletion web/system_date_time_format.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.