(function() {
  define(["t5/core/dom", "t5/core/moment"], function(dom, moment) {
    var ATTR, DEFAULT_FORMAT, toMoment, updateDynamics, updateElement;
    ATTR = "data-timeinterval";
    DEFAULT_FORMAT = 'YYYY-MM-DDTHH:mm:ss.SSSZ';
    toMoment = function(s) {
      if (s) {
        return moment(s, DEFAULT_FORMAT);
      } else {
        return moment();
      }
    };
    updateElement = function(el) {
      var end, plain, start;
      start = toMoment(el.attr("data-timeinterval-start"));
      end = toMoment(el.attr("data-timeinterval-end"));
      plain = el.attr("data-timeinterval-plain");
      el.update(end.from(start, plain));
    };
    updateDynamics = function() {
      var el, i, len, ref;
      ref = dom.body.find("[" + ATTR + "=dynamic]");
      for (i = 0, len = ref.length; i < len; i++) {
        el = ref[i];
        updateElement(el);
      }
    };
    setInterval(updateDynamics, 1000);
    dom.scanner("[" + ATTR + "=true]", function(el) {
      updateElement(el);
      if ((el.attr("data-timeinterval-start")) && (el.attr("data-timeinterval-end"))) {
        el.attr(ATTR, null);
      } else {
        el.attr(ATTR, "dynamic");
      }
    });
  });

}).call(this);
