mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Issue 1067 and more. Add "VALUE=DATE" to encoding of all-day dates. Don't pretend end was specified in original barcode if not present. However for benefit of Android Calendar apps, use +1 hour/day end time for missing end. Fix some error messages in appspot generator too.
git-svn-id: https://zxing.googlecode.com/svn/trunk@2040 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
8198d32f53
commit
293f565db9
|
@ -77,12 +77,10 @@ public final class CalendarResultHandler extends ResultHandler {
|
|||
ParsedResult.maybeAppend(calResult.getSummary(), result);
|
||||
appendTime(calResult.getStart(), result);
|
||||
|
||||
// The end can be null if the event has no duration, so use the start time.
|
||||
String endString = calResult.getEnd();
|
||||
if (endString == null) {
|
||||
endString = calResult.getStart();
|
||||
if (endString != null) {
|
||||
appendTime(endString, result);
|
||||
}
|
||||
appendTime(endString, result);
|
||||
|
||||
ParsedResult.maybeAppend(calResult.getLocation(), result);
|
||||
ParsedResult.maybeAppend(calResult.getAttendee(), result);
|
||||
|
|
|
@ -241,7 +241,13 @@ public abstract class ResultHandler {
|
|||
}
|
||||
long endMilliseconds;
|
||||
if (end == null) {
|
||||
endMilliseconds = allDay ? startMilliseconds + 86400 : startMilliseconds;
|
||||
if (allDay) {
|
||||
// + 1 day
|
||||
endMilliseconds = startMilliseconds + 24 * 60 * 60 * 1000;
|
||||
} else {
|
||||
// + 1 hour
|
||||
endMilliseconds = startMilliseconds + 60 * 60 * 1000;
|
||||
}
|
||||
} else {
|
||||
endMilliseconds = calculateMilliseconds(end);
|
||||
}
|
||||
|
|
|
@ -49,14 +49,14 @@ public final class CalendarParsedResult extends ParsedResult {
|
|||
double longitude) {
|
||||
super(ParsedResultType.CALENDAR);
|
||||
validateDate(start);
|
||||
if (end == null) {
|
||||
end = start;
|
||||
} else {
|
||||
validateDate(end);
|
||||
}
|
||||
this.summary = summary;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
if (end != null) {
|
||||
validateDate(end);
|
||||
this.end = end;
|
||||
} else {
|
||||
this.end = null;
|
||||
}
|
||||
this.location = location;
|
||||
this.attendee = attendee;
|
||||
this.description = description;
|
||||
|
|
|
@ -56,7 +56,7 @@ public final class CalendarParsedResultTestCase extends Assert {
|
|||
"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
|
||||
"DTSTART:20080504T123456Z\r\n" +
|
||||
"END:VEVENT\r\nEND:VCALENDAR",
|
||||
null, null, null, "20080504T123456Z", "20080504T123456Z");
|
||||
null, null, null, "20080504T123456Z", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -66,7 +66,7 @@ public final class CalendarParsedResultTestCase extends Assert {
|
|||
"SUMMARY:foo\r\n" +
|
||||
"DTSTART:20080504T123456Z\r\n" +
|
||||
"END:VEVENT\r\nEND:VCALENDAR",
|
||||
null, "foo", null, "20080504T123456Z", "20080504T123456Z");
|
||||
null, "foo", null, "20080504T123456Z", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -76,7 +76,7 @@ public final class CalendarParsedResultTestCase extends Assert {
|
|||
"LOCATION:Miami\r\n" +
|
||||
"DTSTART:20080504T123456Z\r\n" +
|
||||
"END:VEVENT\r\nEND:VCALENDAR",
|
||||
null, null, "Miami", "20080504T123456Z", "20080504T123456Z");
|
||||
null, null, "Miami", "20080504T123456Z", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -86,13 +86,13 @@ public final class CalendarParsedResultTestCase extends Assert {
|
|||
"DTSTART:20080504T123456Z\r\n" +
|
||||
"DESCRIPTION:This is a test\r\n" +
|
||||
"END:VEVENT\r\nEND:VCALENDAR",
|
||||
"This is a test", null, null, "20080504T123456Z", "20080504T123456Z");
|
||||
"This is a test", null, null, "20080504T123456Z", null);
|
||||
doTest(
|
||||
"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
|
||||
"DTSTART:20080504T123456Z\r\n" +
|
||||
"DESCRIPTION:This is a test\r\n\t with a continuation\r\n" +
|
||||
"END:VEVENT\r\nEND:VCALENDAR",
|
||||
"This is a test with a continuation", null, null, "20080504T123456Z", "20080504T123456Z");
|
||||
"This is a test with a continuation", null, null, "20080504T123456Z", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -102,7 +102,7 @@ public final class CalendarParsedResultTestCase extends Assert {
|
|||
"DTSTART:20080504T123456Z\r\n" +
|
||||
"GEO:-12.345;-45.678\r\n" +
|
||||
"END:VEVENT\r\nEND:VCALENDAR",
|
||||
null, null, null, "20080504T123456Z", "20080504T123456Z", null, -12.345, -45.678);
|
||||
null, null, null, "20080504T123456Z", null, null, -12.345, -45.678);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -129,6 +129,15 @@ public final class CalendarParsedResultTestCase extends Assert {
|
|||
"20111110T120000");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllDayValueDate() {
|
||||
doTest("BEGIN:VEVENT\n" +
|
||||
"DTSTART;VALUE=DATE:20111110\n" +
|
||||
"DTEND;VALUE=DATE:20111110\n" +
|
||||
"END:VEVENT",
|
||||
null, null, null, "20111110", "20111110");
|
||||
}
|
||||
|
||||
private static void doTest(String contents,
|
||||
String description,
|
||||
String summary,
|
||||
|
|
|
@ -216,11 +216,11 @@ public final class ParsedReaderResultTestCase extends Assert {
|
|||
"DTEND:20080505\r\nEND:VEVENT", "foo\n20080504\n20080505", ParsedResultType.CALENDAR);
|
||||
// Start time only
|
||||
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\nEND:VEVENT",
|
||||
"foo\n20080504T123456Z\n20080504T123456Z", ParsedResultType.CALENDAR);
|
||||
"foo\n20080504T123456Z", ParsedResultType.CALENDAR);
|
||||
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456\r\nEND:VEVENT",
|
||||
"foo\n20080504T123456\n20080504T123456", ParsedResultType.CALENDAR);
|
||||
"foo\n20080504T123456", ParsedResultType.CALENDAR);
|
||||
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504\r\nEND:VEVENT",
|
||||
"foo\n20080504\n20080504", ParsedResultType.CALENDAR);
|
||||
"foo\n20080504", ParsedResultType.CALENDAR);
|
||||
doTestResult("BEGIN:VEVENT\r\nDTEND:20080505T\r\nEND:VEVENT",
|
||||
"BEGIN:VEVENT\r\nDTEND:20080505T\r\nEND:VEVENT", ParsedResultType.TEXT);
|
||||
// Make sure illegal entries without newlines don't crash
|
||||
|
|
|
@ -244,15 +244,15 @@ public final class CalendarEventGenerator implements GeneratorSource {
|
|||
if (date1 == null || date2 == null) {
|
||||
throw new GeneratorException("Start and end dates must be set.");
|
||||
}
|
||||
if (date1.after(date2)) {
|
||||
throw new GeneratorException("Start date is after end date.");
|
||||
if (date1.equals(date2) || date1.after(date2)) {
|
||||
throw new GeneratorException("End date must be at least a day after start date.");
|
||||
}
|
||||
DateTimeFormat isoFormatter = DateTimeFormat.getFormat("yyyyMMdd");
|
||||
StringBuilder output = new StringBuilder();
|
||||
output.append("DTSTART:");
|
||||
output.append("DTSTART;VALUE=DATE:");
|
||||
output.append(isoFormatter.format(date1));
|
||||
output.append("\r\n");
|
||||
output.append("DTEND:");
|
||||
output.append("DTEND;VALUE=DATE:");
|
||||
output.append(isoFormatter.format(date2));
|
||||
output.append("\r\n");
|
||||
return output.toString();
|
||||
|
@ -273,8 +273,8 @@ public final class CalendarEventGenerator implements GeneratorSource {
|
|||
}
|
||||
Date dateTime1 = addMilliseconds(mergeDateAndTime(date1, time1), -diffTimeZone);
|
||||
Date dateTime2 = addMilliseconds(mergeDateAndTime(date2, time2), -diffTimeZone);
|
||||
if (dateTime1.after(dateTime2)) {
|
||||
throw new GeneratorException("Ending date is after starting date.");
|
||||
if (dateTime1.equals(dateTime2) || dateTime1.after(dateTime2)) {
|
||||
throw new GeneratorException("Ending date/time must be after starting date.");
|
||||
}
|
||||
DateTimeFormat isoFormatter = DateTimeFormat.getFormat("yyyyMMdd'T'HHmmss'Z'");
|
||||
StringBuilder output = new StringBuilder();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
application: zxing
|
||||
version: 2
|
||||
version: 3
|
||||
runtime: python
|
||||
api_version: 1
|
||||
|
||||
|
|
Loading…
Reference in a new issue