More Issue 1067 - go back to original behavior - user chooses inclusive end date for all day events and app will compensate. End-less events have 0 duration by default.

git-svn-id: https://zxing.googlecode.com/svn/trunk@2042 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2011-11-17 15:35:03 +00:00
parent 7e234d9dfd
commit 3569162c69
4 changed files with 20 additions and 11 deletions

View file

@ -75,11 +75,13 @@ public final class CalendarResultHandler extends ResultHandler {
CalendarParsedResult calResult = (CalendarParsedResult) getResult();
StringBuilder result = new StringBuilder(100);
ParsedResult.maybeAppend(calResult.getSummary(), result);
appendTime(calResult.getStart(), result);
String startString = calResult.getStart();
appendTime(startString, result, false, false);
String endString = calResult.getEnd();
if (endString != null) {
appendTime(endString, result);
boolean sameStartEnd = startString.equals(endString);
appendTime(endString, result, true, sameStartEnd);
}
ParsedResult.maybeAppend(calResult.getLocation(), result);
@ -88,13 +90,19 @@ public final class CalendarResultHandler extends ResultHandler {
return result.toString();
}
private static void appendTime(String when, StringBuilder result) {
private static void appendTime(String when, StringBuilder result, boolean end, boolean sameStartEnd) {
if (when.length() == 8) {
// Show only year/month/day
Date date;
synchronized (DATE_FORMAT) {
date = DATE_FORMAT.parse(when, new ParsePosition(0));
}
// if it's all-day and this is the end date, it's exclusive, so show the user
// that it ends on the day before to make more intuitive sense.
// But don't do it if the event already (incorrectly?) specifies the same start/end
if (end && !sameStartEnd) {
date = new Date(date.getTime() - 24 * 60 * 60 * 1000);
}
ParsedResult.maybeAppend(DateFormat.getDateInstance().format(date.getTime()), result);
} else {
// The when string can be local time, or UTC if it ends with a Z

View file

@ -245,8 +245,7 @@ public abstract class ResultHandler {
// + 1 day
endMilliseconds = startMilliseconds + 24 * 60 * 60 * 1000;
} else {
// + 1 hour
endMilliseconds = startMilliseconds + 60 * 60 * 1000;
endMilliseconds = startMilliseconds;
}
} else {
endMilliseconds = calculateMilliseconds(end);

View file

@ -244,16 +244,18 @@ public final class CalendarEventGenerator implements GeneratorSource {
if (date1 == null || date2 == null) {
throw new GeneratorException("Start and end dates must be set.");
}
if (date1.equals(date2) || date1.after(date2)) {
throw new GeneratorException("End date must be at least a day after start date.");
if (date1.after(date2)) {
throw new GeneratorException("End date cannot be before start date.");
}
// Specify end date as +1 day since it's exclusive
Date date2PlusDay = new Date(date2.getTime() + 24 * 60 * 60 * 1000);
DateTimeFormat isoFormatter = DateTimeFormat.getFormat("yyyyMMdd");
StringBuilder output = new StringBuilder();
output.append("DTSTART;VALUE=DATE:");
output.append(isoFormatter.format(date1));
output.append("\r\n");
output.append("DTEND;VALUE=DATE:");
output.append(isoFormatter.format(date2));
output.append(isoFormatter.format(date2PlusDay));
output.append("\r\n");
return output.toString();
}
@ -273,8 +275,8 @@ public final class CalendarEventGenerator implements GeneratorSource {
}
Date dateTime1 = addMilliseconds(mergeDateAndTime(date1, time1), -diffTimeZone);
Date dateTime2 = addMilliseconds(mergeDateAndTime(date2, time2), -diffTimeZone);
if (dateTime1.equals(dateTime2) || dateTime1.after(dateTime2)) {
throw new GeneratorException("Ending date/time must be after starting date.");
if (dateTime1.after(dateTime2)) {
throw new GeneratorException("Ending date/time cannot be before starting date/time.");
}
DateTimeFormat isoFormatter = DateTimeFormat.getFormat("yyyyMMdd'T'HHmmss'Z'");
StringBuilder output = new StringBuilder();

View file

@ -1,5 +1,5 @@
application: zxing
version: 3
version: 4
runtime: python
api_version: 1