<commit_before>const HTML = DOM.find("html");
const DEFAULT_LANGUAGE = HTML.get("lang") || void 0;
const globalFormatters = {};
const DateTimeFormat = window.Intl.DateTimeFormat;

if (DateTimeFormat) {
    DOM.findAll("meta[name^='data-format:']").forEach(meta => {
        const key = meta.get("name").split(":").pop();
        const formatOptions = meta.get("content");

        try {
            globalFormatters[key] = new DateTimeFormat(DEFAULT_LANGUAGE, JSON.parse(formatOptions));
        } catch(err) {}
    });
}

DOM.extend("local-time", {
    constructor() {
        const lang = this.get("lang") || DEFAULT_LANGUAGE;
        const dateValue = new Date(this.get("datetime"));
        const formatOptions = this.get("data-format");

        this.value(this._formatDate(dateValue, lang, formatOptions));
    },
    _formatDate(dateValue, lang, formatOptions) {
        const formatter = globalFormatters[formatOptions];

        try {
            if (formatter && lang === DEFAULT_LANGUAGE) {
                return formatter.format(dateValue);
            } else {
                return dateValue.toLocaleString(lang, formatOptions ? JSON.parse(formatOptions) : {});
            }
        } catch (err) {
            return dateValue.toLocaleString();
        }<commit_msg>various bug fixes<commit_after>const HTML = DOM.find("html");
const DEFAULT_LANGUAGE = HTML.get("lang") || void 0;
const globalFormatters = DOM.findAll("meta[name^='data-format:']").reduce((globalFormatters, meta) => {
    const key = meta.get("name").split(":")[1];
    const formatOptions = JSON.parse(meta.get("content"));
    if (key) {
        try {
            globalFormatters[key] = new window.Intl.DateTimeFormat(DEFAULT_LANGUAGE, formatOptions);
        } catch(err) {}
    }
    return globalFormatters;
}, {});

DOM.extend("local-time", {
    constructor() {
        const lang = this.get("lang") || DEFAULT_LANGUAGE;
        const dateValue = new Date(this.get("datetime"));
        const formatOptions = this.get("data-format");

        this.value(this._formatDate(dateValue, lang, formatOptions));
    },
    _formatDate(dateValue, lang, formatOptions) {
        const formatter = globalFormatters[formatOptions];

        try {
            if (formatter && lang === DEFAULT_LANGUAGE) {
                return formatter.format(dateValue);
            } else {
                return dateValue.toLocaleString(lang, formatOptions ? JSON.parse(formatOptions) : {});
            }
        } catch (err) {
            return dateValue.toLocaleString();
        }
{'fraction_non_alphanumeric': 0.1443097379741885, 'fraction_numerical': 0.0011732499022291747, 'mean_word_length': 2.778434268833087, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1912217', 'n_tokens_mistral': 731, 'n_tokens_neox': 715, 'n_words': 134}