diff app/model/Messprogramm.js @ 793:d4eb8fb99b5e

Serialising GueltigVon and GueltigBis natively with Ext
author Dustin Demuth <dustin@intevation.de>
date Wed, 13 May 2015 16:01:24 +0200
parents 4c1101f0ba99
children f4eb53ba63fc
line wrap: on
line diff
--- a/app/model/Messprogramm.js	Wed May 13 13:00:13 2015 +0200
+++ b/app/model/Messprogramm.js	Wed May 13 16:01:24 2015 +0200
@@ -62,28 +62,55 @@
         name: 'gueltigVon',
         type: 'date',
         convert: function(v) {
+            var firstofyeartimestamp = new Date(
+                Date.UTC(
+                    new Date().getFullYear(),0,1))
+                .valueOf();
+            var dayToMilli = 86400000;
+
             if (!v) {
                 return v;
             }
-            return new Date(v);
+            //check if v might be a date
+            // unless we go back in time this will work
+            if (v < 1000) {
+                v = v * dayToMilli;
+                v = v + firstofyeartimestamp;
+                v = new Date(v);
+            }
+            return v;
         },
         serialize: function(value) {
             if (value instanceof Date && !isNaN(value.valueOf())) {
-                return value.getDOY();
+                return Ext.Date.getDayOfYear(value);
             }
         }
     }, {
         name: 'gueltigBis',
         type: 'date',
         convert: function(v) {
+            var firstofyeartimestamp = new Date(
+                Date.UTC(
+                    new Date().getFullYear(),0,1))
+                .valueOf();
+            var dayToMilli = 86400000;
+
             if (!v) {
                 return v;
             }
-            return new Date(v);
+
+            //check if v might be a date
+            // unless we go back in time this will work
+            if (v < 1000) {
+                v = v * dayToMilli;
+                v = v + firstofyeartimestamp;
+                v = new Date(v);
+            }
+            return v;
         },
         serialize: function(value) {
             if (value instanceof Date && !isNaN(value.valueOf())) {
-                return value.getDOY();
+                return Ext.Date.getDayOfYear(value);
             }
         }
     }, {

http://lada.wald.intevation.org