import moment from "moment";

// load locale files
import de from "moment/locale/de";

// initialize locale
moment.locale("de");

const transforms = [];

function transform_now(index = null) {
    if(index) {
        transforms[index]();
    } else {
        transforms.forEach((transform) => transform());
    }
}

function add_transform(transform) {
    const index = transforms.push(transform) - 1;
    transform_now(index);
    return transform;
}

function transform_from(el, opts) {
    return () => {
        el.innerHTML = moment(el.getAttribute("datetime")).from(opts.conf.ref || new Date());
    };
}

function create_transform(el, opts) {
    if(opts.is_type("from")) {
        return add_transform(transform_from(el, opts));
    }
}

setInterval(transform_now, 60 * 1000);

export default create_transform;

@@ -618,120 +618,790 @@
 ion 
-create_transform(el, opts) %7B%0A    if(opts.is_type(%22from%22)) %7B%0A        return add_transform(transform_from(el, opts
+transform_to(el, opts) %7B%0A    return () =%3E %7B%0A        el.innerHTML = moment(opts.conf.ref %7C%7C new Date()).to(el.getAttribute(%22datetime%22));%0A    %7D;%0A%7D%0A%0Afunction transform_days_until(el, opts) %7B%0A    return () =%3E %7B%0A        const days = moment(el.getAttribute(%22datetime%22)).diff(opts.conf.ref %7C%7C new Date(), %22days%22);%0A        el.setAttribute(%22data-days%22, days);%0A        el.innerHTML = moment(el.getAttribute(%22datetime%22)).diff(opts.conf.ref %7C%7C new Date(), %22days%22);%0A    %7D;%0A%7D%0A%0Afunction create_transform(el, opts) %7B%0A    if(opts.is_type(%22from%22)) %7B%0A        return add_transform(transform_from(el, opts));%0A    %7D%0A%0A    if(opts.is_type(%22to%22)) %7B%0A        return add_transform(transform_to(el, opts));%0A    %7D%0A%0A    if(opts.is_type(%22days-until%22)) %7B%0A        return add_transform((transform_days_until(el, opts)
 ));%0A

add new modes to time component