Example #1
0
 @Test
 public void today() {
   try {
     Calendar today = Calendar.getInstance();
     beginOfDay(today);
     assertTrue(sufficientlyEqual(DynamicDate.getInstance("today"), today.getTime()));
   } catch (Exception e) {
     fail(e.getMessage());
   }
 }
Example #2
0
 protected Collection compare(Date date, int[] fields) {
   List result = new ArrayList();
   Calendar cal = Calendar.getInstance();
   cal.setLenient(true);
   cal.setTime(date);
   if (fields[0] != IGN && cal.get(Calendar.YEAR) != fields[0])
     result.add("year " + cal.get(Calendar.YEAR) + " != " + fields[0]);
   if (fields[1] != IGN && cal.get(Calendar.MONTH) != fields[1])
     result.add("month " + cal.get(Calendar.MONTH) + " != " + fields[1]);
   if (fields[2] != IGN && cal.get(Calendar.DAY_OF_MONTH) != fields[2])
     result.add("day of month " + cal.get(Calendar.DAY_OF_MONTH) + " != " + fields[2]);
   if (fields[3] != IGN && cal.get(Calendar.HOUR_OF_DAY) != fields[3])
     result.add("hour of day " + cal.get(Calendar.HOUR_OF_DAY) + " != " + fields[3]);
   if (fields[4] != IGN && cal.get(Calendar.MINUTE) != fields[4])
     result.add("minute " + cal.get(Calendar.MINUTE) + " != " + fields[4]);
   if (fields[5] != IGN && cal.get(Calendar.SECOND) != fields[5])
     result.add("second " + cal.get(Calendar.SECOND) + " != " + fields[5]);
   return result;
 }
Example #3
0
  protected int[] getNow(int[] n) {
    Calendar cal = Calendar.getInstance();
    if (n[0] != NULL && n[0] != IGN) cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) + n[0]);
    if (n[1] != NULL && n[1] != IGN) cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) + n[1]);
    if (n[2] != NULL && n[2] != IGN)
      cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) + n[2]);
    if (n[3] != NULL && n[3] != IGN)
      cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) + n[3]);
    if (n[4] != NULL && n[4] != IGN) cal.set(Calendar.MINUTE, cal.get(Calendar.MINUTE) + n[4]);
    if (n[5] != NULL && n[5] != IGN) cal.set(Calendar.SECOND, cal.get(Calendar.SECOND) + n[5]);

    return new int[] {
      n[0] == NULL ? 0 : (n[0] == IGN ? IGN : cal.get(Calendar.YEAR)),
      n[1] == NULL ? 0 : (n[1] == IGN ? IGN : cal.get(Calendar.MONTH)),
      n[2] == NULL ? 0 : (n[2] == IGN ? IGN : cal.get(Calendar.DAY_OF_MONTH)),
      n[3] == NULL ? 0 : (n[3] == IGN ? IGN : cal.get(Calendar.HOUR_OF_DAY)),
      n[4] == NULL ? 0 : (n[4] == IGN ? IGN : cal.get(Calendar.MINUTE)),
      n[5] == NULL ? 0 : (n[5] == IGN ? IGN : cal.get(Calendar.SECOND))
    };
  }
Example #4
0
 protected void beginOfDay(Calendar cal) {
   cal.set(Calendar.MILLISECOND, 0);
   cal.set(Calendar.SECOND, 0);
   cal.set(Calendar.MINUTE, 0);
   cal.set(Calendar.HOUR_OF_DAY, 0);
 }