diff options
author | yvesf <yvesf-git@xapek.org> | 2011-02-28 21:06:09 +0100 |
---|---|---|
committer | yvesf <yvesf-git@xapek.org> | 2011-02-28 21:06:09 +0100 |
commit | 70a30b84d932119c010693486c36a22860859697 (patch) | |
tree | df2c36767ddbe7f08bf7d1374ce3fb16c3de66d5 /src/main | |
parent | 81c863c5bebaabb5ce70674b6b1a49e6bab4bda1 (diff) | |
download | dhbw-calendar-70a30b84d932119c010693486c36a22860859697.tar.gz dhbw-calendar-70a30b84d932119c010693486c36a22860859697.zip |
Korrigiere Fehler bei der Behandlung von Zeitzonen (closes gh-1)
Diffstat (limited to 'src/main')
3 files changed, 52 insertions, 40 deletions
diff --git a/src/main/java/de/dhbw/horb/calendar/dualis/DualisConnection.java b/src/main/java/de/dhbw/horb/calendar/dualis/DualisConnection.java index f7bf369..7d13c47 100644 --- a/src/main/java/de/dhbw/horb/calendar/dualis/DualisConnection.java +++ b/src/main/java/de/dhbw/horb/calendar/dualis/DualisConnection.java @@ -4,8 +4,9 @@ import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Date; +import java.util.Calendar; import java.util.List; +import java.util.TimeZone; import java.util.regex.Pattern; import org.apache.commons.lang.StringUtils; @@ -32,7 +33,7 @@ public class DualisConnection { /** * Baut eine Verbindung mit Dualis auf und führt einen Login durch - * + * * @param username * Dualis Benutzername * @param password @@ -47,7 +48,6 @@ public class DualisConnection { this.password = password; } - @SuppressWarnings("deprecation") public List<VEvent> getEvents() throws FailingHttpStatusCodeException, IOException, DualisScrapingException, DualisAuthenticationException { HtmlPage page, loginPage; @@ -107,16 +107,22 @@ public class DualisConnection { } page = anchorMonat.click(); + getEventsFromPage(page, events); + + return events; + } + + private void getEventsFromPage(HtmlPage page, final List<VEvent> events) { for (HtmlElement elem : page.getElementsByTagName("div")) { if (!elem.getAttribute("class").equals("tbMonthDay")) continue; - final Date day; + final Calendar cday = Calendar.getInstance(); Object dayTitle = elem .getFirstByXPath("div[@class='tbsubhead']/a/@title"); if (dayTitle instanceof DomAttr) { String value = ((DomAttr) dayTitle).getValue(); try { - day = dateFormat.parse(value); + cday.setTime(dateFormat.parse(value)); } catch (ParseException e) { e.printStackTrace(); continue; @@ -136,35 +142,35 @@ public class DualisConnection { String timeEnd = matcher.group(2); String room = matcher.group(3); String title = matcher.group(4); - System.out.println(timeStart + "-" + timeEnd + "-" + room - + "-" + title + "-" + day); int hStart = Integer.parseInt(timeStart.split(":")[0]); int mStart = Integer.parseInt(timeStart.split(":")[1]); int hEnd = Integer.parseInt(timeEnd.split(":")[0]); int mEnd = Integer.parseInt(timeEnd.split(":")[1]); - Date start = (Date) day.clone(); - start.setHours(hStart); - start.setMinutes(mStart); - Date end = (Date) day.clone(); - end.setHours(hEnd); - end.setMinutes(mEnd); - VEvent event = new VEvent.Builder().dtstart(start) - .dtstamp(start).dtend(end).summary(title).description(title) + Calendar cstart = (Calendar) cday.clone(); + cstart.set(Calendar.HOUR_OF_DAY, hStart); + cstart.set(Calendar.MINUTE, mStart); + + Calendar cend = (Calendar) cday.clone(); + cend.set(Calendar.HOUR_OF_DAY, hEnd); + cend.set(Calendar.MINUTE, mEnd); + + cstart.setTimeZone(TimeZone.getTimeZone("Europe/Berlin")); + cend.setTimeZone(TimeZone.getTimeZone("Europe/Berlin")); + VEvent event = new VEvent.Builder().dtstart(cstart) + .dtstamp(cstart).dtend(cend).summary(title).description(title) .location(room).status("CONFIRMED").build(); events.add(event); } else { - System.err.println("Skip: " + desc + " at day " + day); + System.err.println("Skip: " + desc + " at day " + cday.getTime()); } } } - - return events; } // Parse Dates private static final SimpleDateFormat dateFormat = new SimpleDateFormat( "dd.MM.yyyy"); - + // Appointment Link Title // example: 08:15 - 10:45 / HOR-121 / Open Source Systeme private static final Pattern appLinkPattern = Pattern diff --git a/src/main/java/de/dhbw/horb/calendar/ics/AbstractICSType.java b/src/main/java/de/dhbw/horb/calendar/ics/AbstractICSType.java index 3b6019d..a03de64 100644 --- a/src/main/java/de/dhbw/horb/calendar/ics/AbstractICSType.java +++ b/src/main/java/de/dhbw/horb/calendar/ics/AbstractICSType.java @@ -8,7 +8,7 @@ public abstract class AbstractICSType { /** * Serialisierert dieses Calenderteil. Dem Ergebnis Fehlt noch der vCalendar * Header und Footer - * + * */ public abstract String serialize(); @@ -16,24 +16,24 @@ public abstract class AbstractICSType { * <b>RFC says:</b> * <pre> * FORM #2: DATE WITH UTC TIME - * + * * The date with UTC time, or absolute time, is identified by a LATIN * CAPITAL LETTER Z suffix character, the UTC designator, appended to * the time value. For example, the following represents January 19, * 1998, at 0700 UTC: - * + * * 19980119T070000Z - * + * * The "TZID" property parameter MUST NOT be applied to DATE-TIME * properties whose time values are specified in UTC. * </pre> */ public static SimpleDateFormat dateTimeFormat = new SimpleDateFormat( "yyyyMMdd'T'HHmmss'Z'"); - + /** * described in <b>RFC section 3.3.11</b> - * + * * @param text * @return */ diff --git a/src/main/java/de/dhbw/horb/calendar/ics/VEvent.java b/src/main/java/de/dhbw/horb/calendar/ics/VEvent.java index 74f00ba..dea4a17 100644 --- a/src/main/java/de/dhbw/horb/calendar/ics/VEvent.java +++ b/src/main/java/de/dhbw/horb/calendar/ics/VEvent.java @@ -1,11 +1,12 @@ package de.dhbw.horb.calendar.ics; -import java.util.Date; +import java.util.Calendar; +import java.util.TimeZone; public class VEvent extends AbstractICSType { - public Date dtstamp = new Date(); - public Date dtstart = new Date(); - public Date dtend = new Date(); + public Calendar dtstamp = Calendar.getInstance(); + public Calendar dtstart = Calendar.getInstance(); + public Calendar dtend = Calendar.getInstance(); public String status = ""; public String summary = ""; public String description = ""; @@ -19,12 +20,17 @@ public class VEvent extends AbstractICSType { @Override public String serialize() { final StringBuffer sb = new StringBuffer(); + dateTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC")); + sb.append("BEGIN:VEVENT\n"); - sb.append("DTSTART:" + dateTimeFormat.format(dtstart) + "\n"); - sb.append("DTEND:" + dateTimeFormat.format(dtend) + "\n"); - sb.append("DTSTAMP:" + dateTimeFormat.format(dtstamp) + "\n"); - sb.append("UID:vevent_" + dateTimeFormat.format(dtstamp) + "@dhbw.de\n"); - sb.append("CREATED:" + dateTimeFormat.format(new Date()) + "\n"); + sb.append("DTSTART:" + dateTimeFormat.format(dtstart.getTime()) + "\n"); + sb.append("DTEND:" + dateTimeFormat.format(dtend.getTime()) + "\n"); + sb.append("DTSTAMP:" + dateTimeFormat.format(dtstamp.getTime()) + "\n"); + sb.append("UID:vevent_" + dateTimeFormat.format(dtstamp.getTime()) + + "@dhbw.de\n"); + sb.append("CREATED:" + + dateTimeFormat.format(Calendar.getInstance(TimeZone + .getTimeZone("UTC")).getTime()) + "\n"); sb.append("STATUS:" + escapeText(status) + "\n"); sb.append("SUMMARY:" + escapeText(summary) + "\n"); sb.append("DESCRIPTION:" + escapeText(description) + "\n"); @@ -37,18 +43,18 @@ public class VEvent extends AbstractICSType { public static class Builder { VEvent event = new VEvent(); - public Builder dtstamp(Date dtstamp) { - event.dtstamp = dtstamp; + public Builder dtstamp(Calendar cstart) { + event.dtstamp = cstart; return this; } - public Builder dtstart(Date dtstart) { - event.dtstart = dtstart; + public Builder dtstart(Calendar cstart) { + event.dtstart = cstart; return this; } - public Builder dtend(Date dtend) { - event.dtend = dtend; + public Builder dtend(Calendar cend) { + event.dtend = cend; return this; } |