]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
webui: Added custom date format field in config tab
authorpablozg <pablozg@gmail.com>
Tue, 24 Apr 2018 19:20:01 +0000 (21:20 +0200)
committerperexg <perex@perex.cz>
Thu, 7 Jun 2018 16:07:14 +0000 (18:07 +0200)
src/config.c
src/config.h
src/webui/comet.c
src/webui/static/app/epg.js
src/webui/static/app/idnode.js
src/webui/static/app/tvheadend.js

index ce899a744acfd2b659f3a75f7eb4601b0393a005..a6c02424954f8bd10275fcd233e609782e15b82a 100644 (file)
@@ -1704,6 +1704,7 @@ config_boot
   config.theme_ui = strdup("blue");
   config.chname_num = 1;
   config.iptv_tpool_count = 2;
+  config.date_mask = strdup("");
 
   idclass_register(&config_class);
 
@@ -1839,6 +1840,7 @@ void config_done ( void )
   free(config.chicon_path);
   free(config.picon_path);
   free(config.cors_origin);
+  free(config.date_mask);
   file_unlock(config_lock, config_lock_fd);
 }
 
@@ -2226,6 +2228,15 @@ const idclass_t config_class = {
       .off    = offsetof(config_t, chname_src),
       .group  = 2
     },
+    {
+      .type   = PT_STR,
+      .id     = "date_mask",
+      .name   = N_("Custom date Format"),
+      .desc   = N_("Custom date mask like (%yyyy-%M-%dd %h:%m:%s)"),
+      .opts   = PO_ADVANCED,
+      .off    = offsetof(config_t, date_mask),
+      .group  = 2,
+    },
     {
       .type   = PT_STR,
       .islist = 1,
index 39680475d84462f66a13daf5f0aa222b0e63756b..91c167b8b8cbd1c8d5400508d4215cc07973b855 100644 (file)
@@ -67,6 +67,7 @@ typedef struct config {
   uint32_t epg_cut_window;
   uint32_t epg_update_window;
   int iptv_tpool_count;
+  char *date_mask;
 } config_t;
 
 extern const idclass_t config_class;
index 4a41292bc925d360fbbb96207000db417ce9b1ea..ed917fc46cfece8fda39af10d95892f63cabb2e7 100644 (file)
@@ -191,6 +191,7 @@ comet_access_update(http_connection_t *hc, comet_mailbox_t *cmb)
   htsmsg_add_u32(m, "quicktips", config.ui_quicktips);
   htsmsg_add_u32(m, "chname_num", config.chname_num);
   htsmsg_add_u32(m, "chname_src", config.chname_src);
+  htsmsg_add_str(m, "date_mask", config.date_mask);
   if (!access_noacl)
     htsmsg_add_str(m, "username", username);
   if (hc->hc_peer_ipstr)
index 597bda416a7e2b018e0989a17d8e2c4df3446cd3..6ab139eea7bf12e7c3bed1f17ac4925dd9c2f6cb 100644 (file)
@@ -506,7 +506,11 @@ tvheadend.epg = function() {
 
         if (value) {
           var dt = new Date(value);
-          return dt.format('D, M d, H:i');
+          if (tvheadend.date_mask.length > 1){
+            return tvheadend.toCustomDate(dt,tvheadend.date_mask);
+          }else{
+            return tvheadend.toCustomDate(dt,'%ddd, %MMMM %dd, %hh:%mm');
+          }
         }
         return "";
     }
index 18d8e8a55bdccd91e9b6f988af301c8f617562ea..fe1048a400b2adbc5491583cd3dc7847f6047b1c 100644 (file)
@@ -370,7 +370,7 @@ tvheadend.IdNodeField = function(conf)
                 return function(v) {
                     if (v > 0) {
                         var dt = new Date(v * 1000);
-                        return dt.toLocaleDateString();
+                        return dt.toLocaleDateString(tvheadend.toLocaleFormat());
                     }
                     return '';
                 }
@@ -378,8 +378,11 @@ tvheadend.IdNodeField = function(conf)
             return function(v) {
                 if (v > 0) {
                     var dt = new Date(v * 1000);
-                    var wd = dt.toLocaleString(tvheadend.language, {weekday: 'short'});
-                    return wd + ' ' + dt.toLocaleString();
+                    if (tvheadend.date_mask.length > 1){
+                        return tvheadend.toCustomDate(dt,tvheadend.date_mask);
+                    }else{
+                        return tvheadend.toCustomDate(dt,'%ddd %dd/%MM/%YYYY, %hh:%mm:%ss');
+                    }
                 }
                 return '';
             }
@@ -754,8 +757,8 @@ tvheadend.idnode_editor_field = function(f, conf)
             if (!f.duration) {
                 if (d) {
                     var dt = new Date(value * 1000);
-                    value = f.date ? dt.toLocaleDateString() :
-                                     dt.toLocaleString();
+                    value = f.date ? dt.toLocaleDateString(tvheadend.toLocaleFormat()) :
+                                     dt.toLocaleString(tvheadend.toLocaleFormat());
                     r = new Ext.form.TextField({
                         fieldLabel: f.caption,
                         name: f.id,
@@ -3016,4 +3019,4 @@ tvheadend.idnode_simple = function(panel, conf)
     });
 
     tvheadend.idnode_panel(conf, panel, dpanel, builder, destroyer);
-};
+};
\ No newline at end of file
index c776f610c3f5de23386149fbf0b96577e71bd30a..40e5b0ef3e7e2832f531041e19219220d56290cc 100644 (file)
@@ -12,6 +12,7 @@ tvheadend.wizard = null;
 tvheadend.docs_toc = null;
 tvheadend.doc_history = [];
 tvheadend.doc_win = null;
+tvheadend.date_mask = '';
 tvheadend.language = window.navigator.userLanguage || window.navigator.language;
 
 // Use en-US if browser language detection fails.
@@ -744,8 +745,8 @@ Ext.Ajax.request({
  */
 tvheadend.niceDate = function(dt) {
     var d = new Date(dt);
-    return '<div class="x-nice-dayofweek">' + d.toLocaleString(tvheadend.language, {weekday: 'long'}) + '</div>' +
-           '<div class="x-nice-date">' + d.toLocaleDateString() + '</div>' +
+    return '<div class="x-nice-dayofweek">' + d.toLocaleString(tvheadend.toLocaleFormat(), {weekday: 'long'}) + '</div>' +
+           '<div class="x-nice-date">' + d.toLocaleDateString(tvheadend.toLocaleFormat()) + '</div>' +
            '<div class="x-nice-time">' + d.toLocaleTimeString() + '</div>';
 }
 
@@ -787,8 +788,8 @@ tvheadend.niceDateYearMonth = function(dt, refdate) {
         }
       }
     }
-    return '<div class="x-nice-dayofweek">' + d.toLocaleString(tvheadend.language, {weekday: 'long'}) + '</div>' +
-           '<div class="x-nice-date">' + d.toLocaleDateString() + '</div>';
+    return '<div class="x-nice-dayofweek">' + d.toLocaleString(tvheadend.toLocaleFormat(), {weekday: 'long'}) + '</div>' +
+           '<div class="x-nice-date">' + d.toLocaleDateString(tvheadend.toLocaleFormat()) + '</div>';
 }
 
 /*
@@ -998,6 +999,7 @@ function accessUpdate(o) {
     tvheadend.quicktips = o.quicktips ? true : false;
     tvheadend.chname_num = o.chname_num ? 1 : 0;
     tvheadend.chname_src = o.chname_src ? 1 : 0;
+    tvheadend.date_mask = o.date_mask;
 
     if (o.uilevel_nochange)
         tvheadend.uilevel_nochange = true;
@@ -1336,7 +1338,7 @@ tvheadend.RootTabPanel = Ext.extend(Ext.TabPanel, {
         var d = stime ? new Date(stime) : new Date();
         var el = Ext.get(panel.extra.time.tabEl).child('span.x-tab-strip-extra-comp', true);
         el.innerHTML = '<b>' + d.toLocaleTimeString() + '</b>';
-        el.qtip = d.toLocaleString();
+        el.qtip = d.toLocaleString(tvheadend.toLocaleFormat());
     },
 
     onLoginCmdClicked: function(e) {
@@ -1352,6 +1354,42 @@ tvheadend.RootTabPanel = Ext.extend(Ext.TabPanel, {
 
 });
 
+/*
+ * Return tvh_locale_lang in date().toLocaleDateString() compatible format
+ */
+tvheadend.toLocaleFormat = function()
+{
+       return tvh_locale_lang.replace('_','-');
+};
+
+tvheadend.toCustomDate = function(date, format) //author: meizz, improvements by pablozg
+{
+    var o = {
+        "\%M+" : date.getMonth()+1, //month
+        "\%d+" : date.getDate(),    //day
+        "\%h+" : date.getHours(),   //hour
+        "\%m+" : date.getMinutes(), //minute
+        "\%s+" : date.getSeconds(), //second
+        "\%q+" : Math.floor((date.getMonth()+3)/3),  //quarter
+        "\%S" : date.getMilliseconds() //millisecond
+    }
+
+    if(/(\%[yY]+)/.test(format)) format=format.replace(RegExp.$1, (date.getFullYear()+"").substr(5 - RegExp.$1.length));
+
+    if(/(\%MMMM)/.test(format)) format=format.replace(RegExp.$1, (date.toLocaleDateString('es', {month: 'long'})));
+
+    if(/(\%MMM)/.test(format)) format=format.replace(RegExp.$1, (date.toLocaleDateString('es', {month: 'short'})));
+
+    if(/(\%dddd)/.test(format)) format=format.replace(RegExp.$1, (date.toLocaleDateString('es', {weekday: 'long'})));
+
+    if(/(\%ddd)/.test(format)) format=format.replace(RegExp.$1, (date.toLocaleDateString('es', {weekday: 'short'})));
+
+    for(var k in o) if(new RegExp("("+ k +")").test(format))
+        format = format.replace(RegExp.$1, RegExp.$1.length==2 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
+
+    return format;
+}
+
 /**
  *
  */