Exemplo n.º 1
0
 public static boolean isSameLocalTime(Calendar cal1, Calendar cal2) {
   if ((cal1 == null) || (cal2 == null)) {
     throw new IllegalArgumentException("The date must not be null");
   }
   return (cal1.get(14) == cal2.get(14))
       && (cal1.get(13) == cal2.get(13))
       && (cal1.get(12) == cal2.get(12))
       && (cal1.get(10) == cal2.get(10))
       && (cal1.get(6) == cal2.get(6))
       && (cal1.get(1) == cal2.get(1))
       && (cal1.get(0) == cal2.get(0))
       && (cal1.getClass() == cal2.getClass());
 }
Exemplo n.º 2
0
  @Test
  public void testDeepDeclaredFieldMap() throws Exception {
    Calendar c = Calendar.getInstance();
    Map<String, Field> fields = ReflectionUtils.getDeepDeclaredFieldMap(c.getClass());
    assertTrue(fields.size() > 0);
    assertTrue(fields.containsKey("firstDayOfWeek"));
    assertFalse(fields.containsKey("blart"));

    Map<String, Field> test2 = ReflectionUtils.getDeepDeclaredFieldMap(Child.class);
    assertEquals(2, test2.size());
    assertTrue(test2.containsKey("com.cedarsoftware.util.TestReflectionUtils$Parent.foo"));
    assertFalse(test2.containsKey("com.cedarsoftware.util.TestReflectionUtils$Child.foo"));
  }
Exemplo n.º 3
0
  @Test
  public void testDeepDeclaredFields() throws Exception {
    Calendar c = Calendar.getInstance();
    Collection<Field> fields = ReflectionUtils.getDeepDeclaredFields(c.getClass());
    assertTrue(fields.size() > 0);

    boolean miss = true;
    boolean found = false;
    for (Field field : fields) {
      if ("firstDayOfWeek".equals(field.getName())) {
        found = true;
        break;
      }

      if ("blart".equals(field.getName())) {
        miss = false;
      }
    }

    assertTrue(found);
    assertTrue(miss);
  }
Exemplo n.º 4
0
  public static void main(String[] args) throws ParseException {
    //		 String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000);
    //		 // if no ids were returned, something is wrong. get out.
    //		 if (ids.length == 0)
    //		     System.exit(0);
    //
    //		  // begin output
    //		 System.out.println("Current Time");
    //
    //		 // create a Pacific Standard Time time zone
    //		 SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]);
    //
    //		 // set up rules for daylight savings time
    //		 pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
    //		 pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
    //
    //		 // create a GregorianCalendar with the Pacific Daylight time zone
    //		 // and the current date and time
    Calendar calendar = new GregorianCalendar();
    System.out.println(Calendar.getInstance().getClass().getName());
    System.out.println(calendar.getClass().getName());

    Date trialTime = getDate("2011-01-01", "yyyy-MM-dd");
    calendar.setTime(trialTime);

    // print out a bunch of interesting things
    System.out.println("ERA: " + calendar.get(Calendar.ERA));
    System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
    System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
    System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
    System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
    System.out.println("DATE: " + calendar.get(Calendar.DATE));
    System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
    System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));
    System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
    System.out.println(toString(trialTime, "yyyy-MM-dd"));
    // calendar.add(Calendar.DATE, -calendar.get(Calendar.DAY_OF_WEEK) + 1);
    System.out.println(toString(calendar.getTime(), "yyyy-MM-dd"));
    System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));

    System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
    System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
    System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
    System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY));
    System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
    System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
    System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
    System.out.println("ZONE_OFFSET: " + (calendar.get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000)));
    System.out.println("DST_OFFSET: " + (calendar.get(Calendar.DST_OFFSET) / (60 * 60 * 1000)));

    System.out.println("Current Time, with hour reset to 3");
    calendar.clear(Calendar.HOUR_OF_DAY); // so doesn't override
    calendar.set(Calendar.HOUR, 3);
    System.out.println("ERA: " + calendar.get(Calendar.ERA));
    System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
    System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
    System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
    System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
    System.out.println("DATE: " + calendar.get(Calendar.DATE));
    System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
    System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));
    System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
    System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
    System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
    System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
    System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY));
    System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
    System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
    System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
    System.out.println(
        "ZONE_OFFSET: " + (calendar.get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000))); // in hours
    System.out.println(
        "DST_OFFSET: " + (calendar.get(Calendar.DST_OFFSET) / (60 * 60 * 1000))); // in hours

    System.out.println(
        toString(new Date(getTheDayZero(new Date(), 0) * 1000), "yyyy-MM-dd HH:mm:ss"));

    // System.out.println(DateUtil.getIntervalDays(DateUtil.getDate("2014-02-14", "yyyy-MM-dd"),
    // DateUtil.getDate("2012-11-13", "yyyy-MM-dd")));
  }
Exemplo n.º 5
0
 @Test
 public void noFormatter() {
   Calendar c = Calendar.getInstance();
   thrown.expectMessage("There is no good formatter for class " + c.getClass().getName());
   String result = formatter.format("{0:04d}", c);
 }