[Dive4elements-commits] [PATCH] Importer-Parser: set time intevals for complete years when parsing years

Wald Commits scm-commit at wald.intevation.org
Fri Apr 26 08:52:25 CEST 2013


# HG changeset patch
# User Tom Gottfried <tom.gottfried at intevation.de>
# Date 1366959138 -7200
# Node ID 1830dae8cb9b4c93810aca53dcba87f047f96907
# Parent  4dd33b86dc61caa13e181099b6b38bc6836a1d90
Importer-Parser: set time intevals for complete years when parsing years

diff -r 4dd33b86dc61 -r 1830dae8cb9b backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightParser.java
--- 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));
             }
diff -r 4dd33b86dc61 -r 1830dae8cb9b backend/src/main/java/org/dive4elements/river/importer/parsers/LineParser.java
--- 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();
     }
diff -r 4dd33b86dc61 -r 1830dae8cb9b backend/src/main/java/org/dive4elements/river/importer/parsers/SQRelationParser.java
--- 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) {
diff -r 4dd33b86dc61 -r 1830dae8cb9b backend/src/main/java/org/dive4elements/river/importer/parsers/SedimentYieldParser.java
--- 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 + "'");


More information about the Dive4elements-commits mailing list