Add DateUtil.getTimeElement()
authorMatthias Schmidt <gravatronics@live.com>
Mon, 15 May 2017 17:28:23 +0000 (19:28 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Mon, 15 May 2017 17:28:23 +0000 (19:28 +0200)
wcfsetup/install/files/js/WoltLabSuite/Core/Date/Util.js

index 5447d740144380590b66f0ab5e3c3e4da9e65d4a..3dc51a2b7f461ba2bca06bbecbc4b9dd7754fc7a 100644 (file)
@@ -220,6 +220,34 @@ define(['Language'], function(Language) {
                        ) / 1000);
                },
                
+               /**
+                * Returns a `time` element based on the given date just like a `time`
+                * element created by `wcf\system\template\plugin\TimeModifierTemplatePlugin`.
+                * 
+                * Note: The actual content of the element is empty and is expected
+                * to be automatically updated by `WoltLabSuite/Core/Date/Time/Relative`
+                * after the DOM change listener has been triggered.
+                * 
+                * @param       {Date}          date    displayed date
+                * @return      {HTMLElement}   `time` element
+                */
+               getTimeElement: function(date) {
+                       var time = elCreate('time');
+                       time.classList = 'datetime';
+                       
+                       elAttr(time, 'datetime', this.format(date, 'c'));
+                       elData(time, 'timestamp', (date.getTime() - date.getMilliseconds()) / 1000);
+                       elData(time, 'date', this.formatDate(date));
+                       elData(time, 'time', this.formatTime(date));
+                       elData(time, 'offset', date.getTimezoneOffset() * 60); // PHP returns minutes, JavaScript returns seconds
+                       
+                       if (date.getTime() > new Date().getTime()) {
+                               elData(time, 'is-future-date', 'true');
+                       }
+                       
+                       return time;
+               },
+               
                /**
                 * Returns a Date object with precise offset (including timezone and local timezone).
                 *