[PATCH 1 of 2] New pseudo datetime for year-only values (31.12. instead of 15.6.)

Wald Commits scm-commit at wald.intevation.org
Fri May 4 14:05:48 CEST 2018


# HG changeset patch
# User mschaefer
# Date 1525435427 -7200
# Node ID df5c5614e9a7264e1135fde96959f36f6081c7e6
# Parent  95643dffd006411eef111c0a2b9321ed3dd1c708
New pseudo datetime for year-only values (31.12. instead of 15.6.)

diff -r 95643dffd006 -r df5c5614e9a7 backend/src/main/java/org/dive4elements/river/backend/utils/DateGuesser.java
--- a/backend/src/main/java/org/dive4elements/river/backend/utils/DateGuesser.java	Fri May 04 13:36:01 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/backend/utils/DateGuesser.java	Fri May 04 14:03:47 2018 +0200
@@ -13,6 +13,8 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.dive4elements.river.model.TimeInterval;
+
 public final class DateGuesser {
     public static final String [] MONTH = {
             "jan", "feb", "mrz", "apr", "mai", "jun",
@@ -250,11 +252,12 @@
             final Calendar cal = Calendar.getInstance();
             final String year = m.group(1);
             cal.clear();
-            cal.set(
-                    Integer.parseInt(year) + (year.length() == 2 ? 1900 : 0),
-                    5,  // month
-                    15, // day
-                    12, 0, 0);
+            cal.set(Integer.parseInt(year) + (year.length() == 2 ? 1900 : 0),
+                    TimeInterval.YEAR_ONLY_DATE.get(Calendar.MONTH),
+                    TimeInterval.YEAR_ONLY_DATE.get(Calendar.DAY_OF_MONTH),
+                    TimeInterval.YEAR_ONLY_DATE.get(Calendar.HOUR_OF_DAY),
+                    TimeInterval.YEAR_ONLY_DATE.get(Calendar.MINUTE),
+                    TimeInterval.YEAR_ONLY_DATE.get(Calendar.SECOND));
             return cal.getTime();
         }
 
diff -r 95643dffd006 -r df5c5614e9a7 backend/src/main/java/org/dive4elements/river/model/TimeInterval.java
--- a/backend/src/main/java/org/dive4elements/river/model/TimeInterval.java	Fri May 04 13:36:01 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/TimeInterval.java	Fri May 04 14:03:47 2018 +0200
@@ -9,22 +9,33 @@
 package org.dive4elements.river.model;
 
 import java.io.Serializable;
-
+import java.util.Calendar;
 import java.util.Date;
 
+import javax.persistence.Column;
 import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
 import javax.persistence.Id;
+import javax.persistence.SequenceGenerator;
 import javax.persistence.Table;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Column;
-import javax.persistence.SequenceGenerator;
-import javax.persistence.GenerationType;
 
 @Entity
 @Table(name = "time_intervals")
 public class TimeInterval
 implements   Serializable
 {
+    /**
+     * Pseudo-date for Date values where only the year field is significant
+     * (in Flys 3.2.1 June-15 12:00 had been used)
+     */
+    public final static Calendar YEAR_ONLY_DATE;
+    static {
+        YEAR_ONLY_DATE = Calendar.getInstance();
+        YEAR_ONLY_DATE.clear();
+        YEAR_ONLY_DATE.set(0, Calendar.DECEMBER, 31, 3, 5, 6);
+    }
+
     private Integer id;
     private Date    startTime;
     private Date    stopTime;
@@ -32,43 +43,43 @@
     public TimeInterval() {
     }
 
-    public TimeInterval(Date startTime, Date stopTime) {
+    public TimeInterval(final Date startTime, final Date stopTime) {
         this.startTime = startTime;
         this.stopTime  = stopTime;
     }
 
     @Id
     @SequenceGenerator(
-        name           = "SEQUENCE_TIME_INTERVALS_ID_SEQ",
-        sequenceName   = "TIME_INTERVALS_ID_SEQ",
-        allocationSize = 1)
+            name           = "SEQUENCE_TIME_INTERVALS_ID_SEQ",
+            sequenceName   = "TIME_INTERVALS_ID_SEQ",
+            allocationSize = 1)
     @GeneratedValue(
-        strategy  = GenerationType.SEQUENCE,
-        generator = "SEQUENCE_TIME_INTERVALS_ID_SEQ")
+            strategy  = GenerationType.SEQUENCE,
+            generator = "SEQUENCE_TIME_INTERVALS_ID_SEQ")
     @Column(name = "id")
     public Integer getId() {
-        return id;
+        return this.id;
     }
 
-    public void setId(Integer id) {
+    public void setId(final Integer id) {
         this.id = id;
     }
 
     @Column(name = "start_time") // FIXME: type mapping needed?
     public Date getStartTime() {
-        return startTime;
+        return this.startTime;
     }
 
-    public void setStartTime(Date startTime) {
+    public void setStartTime(final Date startTime) {
         this.startTime = startTime;
     }
 
     @Column(name = "stop_time") // FIXME: type mapping needed?
     public Date getStopTime() {
-        return stopTime;
+        return this.stopTime;
     }
 
-    public void setStopTime(Date stopTime) {
+    public void setStopTime(final Date stopTime) {
         this.stopTime = stopTime;
     }
 }


More information about the Dive4Elements-commits mailing list