aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornetconomy <netconomy@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2007-11-29 08:49:17 +0000
committernetconomy <netconomy@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2007-11-29 08:49:17 +0000
commit00809217ec7c890a844f9a7c667c71b550ad92a6 (patch)
tree3654f2c43e0abf7c5ef9fe1fcab3d23348edf628 /src
parentd5a386b533a3e56006c13c875f6ee80a97569777 (diff)
downloadpdf-as-3-00809217ec7c890a844f9a7c667c71b550ad92a6.tar.gz
pdf-as-3-00809217ec7c890a844f9a7c667c71b550ad92a6.tar.bz2
pdf-as-3-00809217ec7c890a844f9a7c667c71b550ad92a6.zip
EGIZDate intern auf Date-Berechnung umgestellt
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@232 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/pdf/EGIZDate.java304
1 files changed, 170 insertions, 134 deletions
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/EGIZDate.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/EGIZDate.java
index ddbea0b..06539a7 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/EGIZDate.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/EGIZDate.java
@@ -39,63 +39,75 @@ public class EGIZDate {
private static final Logger LOG = Logger.getLogger(EGIZDate.class);
- /**
- * The year.
- */
- protected int year;
-
- /**
- * The month.
- */
- protected int month;
-
- /**
- * The day.
- */
- protected int day;
-
- /**
- * The hour.
- */
- protected int hour;
-
- /**
- * The minute.
- */
- protected int minute;
-
- /**
- * The second.
- */
- protected int second;
+ protected Date date = null;
+
+ // TODO remove deprecated old code
+// /**
+// * The year.
+// */
+// protected int year;
+//
+// /**
+// * The month.
+// */
+// protected int month;
+//
+// /**
+// * The day.
+// */
+// protected int day;
+//
+// /**
+// * The hour.
+// */
+// protected int hour;
+//
+// /**
+// * The minute.
+// */
+// protected int minute;
+//
+// /**
+// * The second.
+// */
+// protected int second;
+//
+// /**
+// * Constructor that fills the date with values.
+// *
+// * @param year
+// * The year.
+// * @param month
+// * The month.
+// * @param day
+// * The day.
+// * @param hour
+// * The hour.
+// * @param minute
+// * The minute.
+// * @param second
+// * The second.
+// */
+// public EGIZDate(int year, int month, int day, int hour, int minute,
+// int second) {
+// this.year = year;
+// this.month = month;
+// this.day = day;
+// this.hour = hour;
+// this.minute = minute;
+// this.second = second;
+// }
+
/**
- * Constructor that fills the date with values.
- *
- * @param year
- * The year.
- * @param month
- * The month.
- * @param day
- * The day.
- * @param hour
- * The hour.
- * @param minute
- * The minute.
- * @param second
- * The second.
- */
- public EGIZDate(int year, int month, int day, int hour, int minute,
- int second) {
- this.year = year;
- this.month = month;
- this.day = day;
- this.hour = hour;
- this.minute = minute;
- this.second = second;
- }
+ * @param date
+ */
+ protected EGIZDate(Date date)
+ {
+ this.date = date;
+ }
- /**
+ /**
* Parses the date information from a given date value.
*
* <p>
@@ -109,60 +121,72 @@ public class EGIZDate {
* thrown if the date String has an illegal format.
*/
public static EGIZDate parseFromString(String date_value) {
- // find the according RFC standard and cite it
-
- /*
- * Pattern date_pattern =
- * Pattern.compile("^\\d\\d\\d\\d-\\d\\d-\\d\\dT\\d\\d:\\d\\d:\\d\\d(Z|((\\+|\\-)\\d\\d:\\d\\d))?$");
- * Matcher date_matcher = date_pattern.matcher(date_value); if
- * (!date_matcher.matches()) { throw new IllegalArgumentException("The
- * date_value (" + date_value + ") has an illegal format."); } // for
- * some strange reasons capture groups don't work
- *
- * int year = Integer.parseInt(date_value.substring(0, 4)); int month =
- * Integer.parseInt(date_value.substring(5, 7)); int day =
- * Integer.parseInt(date_value.substring(8, 10)); int hour =
- * Integer.parseInt(date_value.substring(11, 13)); int minute =
- * Integer.parseInt(date_value.substring(14, 16)); int second =
- * Integer.parseInt(date_value.substring(17, 19)); return new
- * EGIZDate(year, month, day, hour, minute, second);
- */
-
- String[] parsePatterns = { "yyyy-MM-dd'T'HH:mm:ss",
- "yyyy-MM-dd'T'HH:mm:ssZ", "yyyy-MM-dd'T'HH:mm:ssZZ" };
- if (date_value.length() > 19) {
- int li = date_value.lastIndexOf(":");
- if (li >= 19) {
- date_value = new StringBuffer(date_value).deleteCharAt(li).toString();
- }
- // FIXME: @iaik: wenn man bei UTC+"Z" die letzten -2 Zeichen durch "UTC" ersetzt verliert die Zeit ihre Sekunden-Einerstelle!!!!!!!
+ Date date = parseDateFromString(date_value);
+// Calendar calendar = new GregorianCalendar();
+// calendar.setTime(date);
+
+ LOG.debug("Parsing date string \"" + date_value + "\" returns: " + date);
+
+// return new EGIZDate(calendar.get(Calendar.YEAR), calendar
+// .get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH),
+// calendar.get(Calendar.HOUR), calendar.get(Calendar.MINUTE),
+// calendar.get(Calendar.SECOND));
+ return new EGIZDate(date);
+
+ }
+
+ public static Date parseDateFromString (String date_value)
+ {
+ // find the according RFC standard and cite it
+
+ /*
+ * Pattern date_pattern =
+ * Pattern.compile("^\\d\\d\\d\\d-\\d\\d-\\d\\dT\\d\\d:\\d\\d:\\d\\d(Z|((\\+|\\-)\\d\\d:\\d\\d))?$");
+ * Matcher date_matcher = date_pattern.matcher(date_value); if
+ * (!date_matcher.matches()) { throw new IllegalArgumentException("The
+ * date_value (" + date_value + ") has an illegal format."); } // for
+ * some strange reasons capture groups don't work
+ *
+ * int year = Integer.parseInt(date_value.substring(0, 4)); int month =
+ * Integer.parseInt(date_value.substring(5, 7)); int day =
+ * Integer.parseInt(date_value.substring(8, 10)); int hour =
+ * Integer.parseInt(date_value.substring(11, 13)); int minute =
+ * Integer.parseInt(date_value.substring(14, 16)); int second =
+ * Integer.parseInt(date_value.substring(17, 19)); return new
+ * EGIZDate(year, month, day, hour, minute, second);
+ */
+
+ String[] parsePatterns = { "yyyy-MM-dd'T'HH:mm:ss",
+ "yyyy-MM-dd'T'HH:mm:ssZ", "yyyy-MM-dd'T'HH:mm:ssZZ" };
+ if (date_value.length() > 19) {
+ int li = date_value.lastIndexOf(":");
+ if (li >= 19) {
+ date_value = new StringBuffer(date_value).deleteCharAt(li).toString();
+ }
+ // FIXME: @iaik: wenn man bei UTC+"Z" die letzten -2 Zeichen durch "UTC" ersetzt verliert die Zeit ihre Sekunden-Einerstelle!!!!!!!
// alter code:
-// if (date_value.endsWith("Z")) {
-// date_value = date_value.substring(0, date_value.length()-2) + "UTC";
-// }
- // neuer code:
+// if (date_value.endsWith("Z")) {
+// date_value = date_value.substring(0, date_value.length()-2) + "UTC";
+// }
+ // neuer code:
if (date_value.endsWith("ZZ")) {
date_value = date_value.substring(0, date_value.length()-2) + "UTC";
}
if (date_value.endsWith("Z")) {
date_value = date_value.substring(0, date_value.length()-1) + "UTC";
}
-
- } else {
- date_value += "UTC";
- }
-
- Date date;
- try {
- date = DateUtils.parseDate(date_value, parsePatterns);
- } catch (ParseException e) {
- throw new IllegalArgumentException("The date_value (" + date_value
- + ") has an illegal format.");
- }
- Calendar calendar = new GregorianCalendar();
- calendar.setTime(date);
-
- LOG.debug("Parsing date string \"" + date_value + "\" returns: " + date);
+
+ } else {
+ date_value += "UTC";
+ }
+
+ Date date;
+ try {
+ date = DateUtils.parseDate(date_value, parsePatterns);
+ } catch (ParseException e) {
+ throw new IllegalArgumentException("The date_value (" + date_value
+ + ") has an illegal format.");
+ }
// return new EGIZDate(calendar.get(Calendar.YEAR), calendar
@@ -172,10 +196,11 @@ public class EGIZDate {
// fixed by tknall: really bad bug: Calendar.HOUR means hour in 12-hour-mode instead f 24-hour. !!!!
// this leads to false comparison of two dates where one date is prior noon and one after noon.
- return new EGIZDate(calendar.get(Calendar.YEAR), calendar
- .get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH),
- calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE),
- calendar.get(Calendar.SECOND));
+// return new EGIZDate(calendar.get(Calendar.YEAR), calendar
+// .get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH),
+// calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE),
+// calendar.get(Calendar.SECOND));
+ return date;
}
@@ -187,43 +212,45 @@ public class EGIZDate {
return false;
}
- return toString().equals(obj.toString());
+ EGIZDate other = (EGIZDate)obj;
+ return this.date.equals(other.date);
}
/**
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
- return toString().hashCode();
+ return this.date.hashCode();
}
- /**
- * @see java.lang.Object#toString()
- */
- public String toString() {
- return "parsed date = " + year + "-" + month + "-" + day + "T" + hour
- + ":" + minute + ":" + second;
- }
+ /**
+ * @see java.lang.Object#toString()
+ */
+ public String toString()
+ {
+ return this.date.toString();
+ }
+
- /**
- * Converts the date to a long integer.
- *
- * <p>
- * An earlier date is lower than a later date.
- * </p>
- * <p>
- * E.g. a date in 1999 will get a smaller number than a date in 2006.
- * </p>
- *
- * @return Returns the compareable long.
- */
- protected long toCompareableLong() {
- return +this.year * 12 * 31 * 24 * 60 * 60 + this.month * 31 * 24 * 60
- * 60 + this.day * 24 * 60 * 60 + this.hour * 60 * 60
- + this.minute * 60 + this.second;
- }
+// /**
+// * Converts the date to a long integer.
+// *
+// * <p>
+// * An earlier date is lower than a later date.
+// * </p>
+// * <p>
+// * E.g. a date in 1999 will get a smaller number than a date in 2006.
+// * </p>
+// *
+// * @return Returns the compareable long.
+// */
+// protected long toCompareableLong() {
+// return +this.year * 12 * 31 * 24 * 60 * 60 + this.month * 31 * 24 * 60
+// * 60 + this.day * 24 * 60 * 60 + this.hour * 60 * 60
+// + this.minute * 60 + this.second;
+// }
- /**
+ /**
* Compares this EGIZDate to another EXIZDate.
*
* @param other
@@ -233,8 +260,17 @@ public class EGIZDate {
* date is later (higher) than the other date.
*/
public int compareTo(EGIZDate other) {
- long diff = toCompareableLong() - other.toCompareableLong();
- return (int) diff;
+ return this.date.compareTo(other.date);
+// long diff = toCompareableLong() - other.toCompareableLong();
+// return (int) diff;
}
+ /**
+ * @return the date
+ */
+ public Date getDate()
+ {
+ return this.date;
+ }
+
}