changeset 5845:1830dae8cb9b

Importer-Parser: set time intevals for complete years when parsing years
author Tom Gottfried <tom.gottfried@intevation.de>
date Fri, 26 Apr 2013 08:52:18 +0200
parents 4dd33b86dc61
children 6343a61b62c8 d5e95f926d13
files backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightParser.java backend/src/main/java/org/dive4elements/river/importer/parsers/LineParser.java backend/src/main/java/org/dive4elements/river/importer/parsers/SQRelationParser.java backend/src/main/java/org/dive4elements/river/importer/parsers/SedimentYieldParser.java
diffstat 4 files changed, 29 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightParser.java	Fri Apr 26 08:25:41 2013 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightParser.java	Fri Apr 26 08:52:18 2013 +0200
@@ -159,9 +159,18 @@
     }
 
 
-    public static Date getDateFromYear(int year) {
+    public static Date getStartDateFromYear(int year) {
         Calendar cal = Calendar.getInstance();
-        cal.set(year, 0, 1);
+	cal.clear();
+        cal.set(year, 0, 1, 0, 0, 0);
+
+        return cal.getTime();
+    }
+
+    public static Date getEndDateFromYear(int year) {
+        Calendar cal = Calendar.getInstance();
+	cal.clear();
+        cal.set(year, 11, 31, 23, 59, 59);
 
         return cal.getTime();
     }
@@ -237,8 +246,8 @@
                 int lower = Integer.valueOf(lo);
                 int upper = Integer.valueOf(up);
 
-                Date fromYear = getDateFromYear(lower);
-                Date toYear   = getDateFromYear(upper);
+                Date fromYear = getStartDateFromYear(lower);
+                Date toYear   = getEndDateFromYear(upper);
 
                 obj.setTimeInterval(new ImportTimeInterval(fromYear, toYear));
             }
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/LineParser.java	Fri Apr 26 08:25:41 2013 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/LineParser.java	Fri Apr 26 08:52:18 2013 +0200
@@ -137,9 +137,18 @@
     }
 
 
-    public static Date getDateFromYear(int year) {
+    public static Date getStartDateFromYear(int year) {
         Calendar cal = Calendar.getInstance();
-        cal.set(year, 0, 1);
+	cal.clear();
+        cal.set(year, 0, 1, 0, 0, 0);
+
+        return cal.getTime();
+    }
+
+    public static Date getEndDateFromYear(int year) {
+        Calendar cal = Calendar.getInstance();
+	cal.clear();
+        cal.set(year, 11, 31, 23, 59, 59);
 
         return cal.getTime();
     }
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/SQRelationParser.java	Fri Apr 26 08:25:41 2013 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/SQRelationParser.java	Fri Apr 26 08:52:18 2013 +0200
@@ -99,8 +99,8 @@
                 int high = nf.parse(hi).intValue();
 
                 current.setTimeInterval(new ImportTimeInterval(
-                    getDateFromYear(low),
-                    getDateFromYear(high)
+                    getStartDateFromYear(low),
+                    getEndDateFromYear(high)
                 ));
             }
             catch (ParseException nfe) {
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/SedimentYieldParser.java	Fri Apr 26 08:25:41 2013 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/SedimentYieldParser.java	Fri Apr 26 08:52:18 2013 +0200
@@ -262,8 +262,8 @@
                 int yearB = nf.parse(a.group(2)).intValue();
 
                 return new ImportTimeInterval(
-                    getDateFromYear(yearA),
-                    getDateFromYear(yearB)
+                    getStartDateFromYear(yearA),
+                    getEndDateFromYear(yearB)
                 );
             }
 
@@ -271,7 +271,7 @@
             if (b.matches()) {
                 int year = nf.parse(b.group(1)).intValue();
 
-                return new ImportTimeInterval(getDateFromYear(year));
+                return new ImportTimeInterval(getStartDateFromYear(year));
             }
 
             log.warn("SYP: Unknown time interval string: '" + column + "'");

http://dive4elements.wald.intevation.org