[Lada-commits] [PATCH 3 of 3] Serialising GueltigVon and GueltigBis natively with Ext
Wald Commits
scm-commit at wald.intevation.org
Wed May 13 16:02:29 CEST 2015
# HG changeset patch
# User Dustin Demuth <dustin at intevation.de>
# Date 1431525684 -7200
# Node ID d4eb8fb99b5e8ea8cb740e7616cc3dafc42cb8c8
# Parent d572ee3271acb407c3fd46abc4d442bcfcab3a70
Serialising GueltigVon and GueltigBis natively with Ext
diff -r d572ee3271ac -r d4eb8fb99b5e app/model/Messprogramm.js
--- 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);
}
}
}, {
diff -r d572ee3271ac -r d4eb8fb99b5e app/view/form/Messprogramm.js
--- a/app/view/form/Messprogramm.js Wed May 13 13:00:13 2015 +0200
+++ b/app/view/form/Messprogramm.js Wed May 13 16:01:24 2015 +0200
@@ -246,7 +246,7 @@
labelWidth: 90,
anchor: '100%',
name: 'gueltigVon',
- format: 'd.m.Y H:i',
+ format: 'd.m.Y',
period: 'start'
}, {
xtype: 'datetime',
@@ -254,7 +254,7 @@
labelWidth: 90,
anchor: '100%',
name: 'gueltigBis',
- format: 'd.m.Y H:i',
+ format: 'd.m.Y',
period: 'end'
}, {
xtype: 'numberfield',
diff -r d572ee3271ac -r d4eb8fb99b5e index.html
--- a/index.html Wed May 13 13:00:13 2015 +0200
+++ b/index.html Wed May 13 16:01:24 2015 +0200
@@ -18,7 +18,6 @@
<script type="text/javascript" src="resources/lib/OpenLayers/OpenLayers.js"></script>
<script type="text/javascript" src="resources/lib/filesaver/FileSaver.js"></script>
<script type="text/javascript" src="resources/lib/filesaver/Blob.js"></script>
- <script type="text/javascript" src="resources/lib/Date.prototype.getDOY.js"></script>
<!-- <x-compile> -->
<!-- <x-bootstrap> -->
<script type="text/javascript" src="extjs/ext-all-debug.js"></script>
diff -r d572ee3271ac -r d4eb8fb99b5e resources/lib/Date.prototype.getDOY.js
--- a/resources/lib/Date.prototype.getDOY.js Wed May 13 13:00:13 2015 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,7 +0,0 @@
-
-// A new Prototype to return the Day of the Year.
-// Taken from: http://javascript.about.com/library/bldayyear.htm
-Date.prototype.getDOY = function() {
- var onejan = new Date(this.getFullYear(),0,1);
- return Math.ceil((this - onejan) / 86400000);
-}
More information about the Lada-commits
mailing list