예제 #1
0
 /** for testing DateTools support */
 private String getDate(Date d, DateTools.Resolution resolution) throws Exception {
   if (resolution == null) {
     return DateField.dateToString(d);
   } else {
     return DateTools.dateToString(d, resolution);
   }
 }
예제 #2
0
 /** for testing legacy DateField support */
 public void testLegacyDateRange() throws Exception {
   String startDate = getLocalizedDate(2002, 1, 1, false);
   String endDate = getLocalizedDate(2002, 1, 4, false);
   Calendar endDateExpected = new GregorianCalendar();
   endDateExpected.set(2002, 1, 4, 23, 59, 59);
   endDateExpected.set(Calendar.MILLISECOND, 999);
   assertQueryEquals(
       "[ " + escapeDateString(startDate) + " TO " + escapeDateString(endDate) + "]",
       null,
       "["
           + getLegacyDate(startDate)
           + " TO "
           + DateField.dateToString(endDateExpected.getTime())
           + "]");
   assertQueryEquals(
       "{  " + escapeDateString(startDate) + "    " + escapeDateString(endDate) + "   }",
       null,
       "{" + getLegacyDate(startDate) + " TO " + getLegacyDate(endDate) + "}");
 }
예제 #3
0
 private static void addDateDoc(
     String content,
     int year,
     int month,
     int day,
     int hour,
     int minute,
     int second,
     IndexWriter iw)
     throws IOException {
   Document d = new Document();
   d.add(new Field("f", content, Field.Store.YES, Field.Index.ANALYZED));
   Calendar cal = Calendar.getInstance(Locale.ENGLISH);
   cal.set(year, month - 1, day, hour, minute, second);
   d.add(
       new Field(
           "date",
           DateField.dateToString(cal.getTime()),
           Field.Store.YES,
           Field.Index.NOT_ANALYZED));
   iw.addDocument(d);
 }
예제 #4
0
 /** for testing legacy DateField support */
 private String getLegacyDate(String s) throws Exception {
   DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
   return DateField.dateToString(df.parse(s));
 }