/**
* <p>We would return the start and end date as a {@link java.util.Date} except that this code
* needs to work under JavaME / MIDP and there is no date parsing library available there, such
- * as <code>java.text.SimpleDateFormat</code>.</p>
+ * as <code>java.text.SimpleDateFormat</code>.</p> See validateDate() for the return format.
*
- * @return start time formatted as yyyyMMdd'T'HHmmss'Z'.</p>
+ * @return start time formatted as a RFC 2445 DATE or DATE-TIME.</p>
*/
public String getStart() {
return start;
}
/**
- * @see #getStart()
+ * @see #getStart(). May return null if the event has no duration.
*/
public String getEnd() {
return end;
return result.toString();
}
+ /**
+ * RFC 2445 allows the start and end fields to be of type DATE (e.g. 20081021) or DATE-TIME
+ * (e.g. 20081021T123000 for local time, or 20081021T123000Z for UTC).
+ *
+ * @param date The string to validate
+ */
private static void validateDate(String date) {
if (date != null) {
- if (date.length() != 16) {
+ int length = date.length();
+ if (length != 8 && length != 15 && length != 16) {
throw new IllegalArgumentException();
}
for (int i = 0; i < 8; i++) {
throw new IllegalArgumentException();
}
}
- if (date.charAt(8) != 'T') {
- throw new IllegalArgumentException();
- }
- for (int i = 9; i < 15; i++) {
- if (!Character.isDigit(date.charAt(i))) {
+ if (length > 8) {
+ if (date.charAt(8) != 'T') {
+ throw new IllegalArgumentException();
+ }
+ for (int i = 9; i < 15; i++) {
+ if (!Character.isDigit(date.charAt(i))) {
+ throw new IllegalArgumentException();
+ }
+ }
+ if (length == 16 && date.charAt(15) != 'Z') {
throw new IllegalArgumentException();
}
- }
- if (date.charAt(15) != 'Z') {
- throw new IllegalArgumentException();
}
}
}
-}
\ No newline at end of file
+}
doTestResult("12345678901", ParsedResultType.TEXT);
}
+ public void testISBN() {
+ doTestResult("9784567890123", ParsedResultType.ISBN, BarcodeFormat.EAN_13);
+ doTestResult("9794567890123", ParsedResultType.ISBN, BarcodeFormat.EAN_13);
+ doTestResult("97845678901", ParsedResultType.TEXT);
+ doTestResult("97945678901", ParsedResultType.TEXT);
+ }
+
public void testURI() {
doTestResult("http://google.com", ParsedResultType.URI);
doTestResult("google.com", ParsedResultType.URI);
}
public void testVEvent() {
+ // UTC times
doTestResult("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\n" +
"DTEND:20080505T234555Z\r\nEND:VEVENT\r\nEND:VCALENDAR", ParsedResultType.CALENDAR);
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\n" +
"DTEND:20080505T234555Z\r\nEND:VEVENT", ParsedResultType.CALENDAR);
+ // Local times
+ doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456\r\n" +
+ "DTEND:20080505T234555\r\nEND:VEVENT", ParsedResultType.CALENDAR);
+ // Date only (all day event)
+ doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504\r\n" +
+ "DTEND:20080505\r\nEND:VEVENT", ParsedResultType.CALENDAR);
+ // Start time only
+ doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\nEND:VEVENT",
+ ParsedResultType.CALENDAR);
+ doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456\r\nEND:VEVENT",
+ ParsedResultType.CALENDAR);
+ doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504\r\nEND:VEVENT",
+ ParsedResultType.CALENDAR);
doTestResult("BEGIN:VEVENT\r\nDTEND:20080505T\r\nEND:VEVENT", ParsedResultType.TEXT);
doTestResult("BEGIN:VEVENT", ParsedResultType.URI); // See above note on why this is URI
}
public EAN13BlackBox1TestCase() {
super(new File("test/data/blackbox/ean13-1"), new MultiFormatReader(), BarcodeFormat.EAN_13);
addTest(28, 31, 0.0f);
- addTest(26, 31, 180.0f);
+ addTest(25, 31, 180.0f);
}
}
\ No newline at end of file