示例#1
0
 public CalendarTableModel(String[] columnNames) {
   calendar = new GregorianCalendar();
   calendar.setFirstDayOfWeek(Calendar.SUNDAY);
   calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
   this.columnNames = columnNames;
   rowCount = 24;
   columnCount = columnNames.length;
   appointments = new ArrayList<Appointment>();
 }
示例#2
0
 @Bug(8401)
 public void testFloor4() throws Exception {
   // conflict between DoM and DoW. In this we need to find a day that's the first day of a month
   // and Sunday in 2010
   CronTab x = new CronTab("0 0 1 * 0");
   Calendar c = new GregorianCalendar(2011, 0, 1, 15, 55);
   c.setFirstDayOfWeek(MONDAY);
   // the last such day in 2010 is Aug 1st
   GregorianCalendar answer = new GregorianCalendar(2010, 7, 1, 0, 0);
   answer.setFirstDayOfWeek(MONDAY);
   compare(answer, x.floor(c));
 }
  public static Date obterUltimoDiaDaSemana(Date data) {
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setFirstDayOfWeek(Calendar.SUNDAY);
    calendar.setTime(data);

    calendar.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
    calendar.set(Calendar.AM_PM, Calendar.PM);
    calendar.set(Calendar.HOUR, 11);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);

    return calendar.getTime();
  }
示例#4
0
 @Test(dataProvider = "allRules")
 public void test_weekOfMonth_getValue_crossCheckCalendar(DayOfWeek dow, int minimalDays) {
   DateTimeRule rule = WeekRules.of(dow, minimalDays).weekOfMonth();
   GregorianCalendar gcal = new GregorianCalendar();
   gcal.setFirstDayOfWeek(dow == SUNDAY ? 1 : dow.getValue() + 1);
   gcal.setMinimalDaysInFirstWeek(minimalDays);
   gcal.set(2011, Calendar.JANUARY, 1);
   LocalDate date = LocalDate.of(2011, 1, 1);
   for (int i = 1; i <= 365; i++) {
     assertEquals(rule.getValue(date).getValue(), gcal.get(Calendar.WEEK_OF_MONTH));
     gcal.add(Calendar.DAY_OF_MONTH, 1);
     date = date.plusDays(1);
   }
 }
示例#5
0
  public static void main(String[] args) throws Throwable {

    int N = 10000;
    long t1970 = new java.util.Date(70, 0, 01).getTime();
    Random r = new Random();
    for (int i = 0; i < N; i++) {
      int days = r.nextInt(50) * 365 + r.nextInt(365);
      long secs = t1970 + days * 86400 + r.nextInt(86400);
      int nanos = r.nextInt(NANOS_PER_SECOND);
      int nanos_ms = nanos / 1000000 * 1000000; // millis precision
      long millis = secs * 1000 + r.nextInt(1000);
      LocalDateTime ldt = LocalDateTime.ofEpochSecond(secs, nanos, ZoneOffset.UTC);
      LocalDateTime ldt_ms = LocalDateTime.ofEpochSecond(secs, nanos_ms, ZoneOffset.UTC);
      Instant inst = Instant.ofEpochSecond(secs, nanos);
      Instant inst_ms = Instant.ofEpochSecond(secs, nanos_ms);
      ///////////// java.util.Date /////////////////////////
      Date jud = new java.util.Date(millis);
      Instant inst0 = jud.toInstant();
      if (jud.getTime() != inst0.toEpochMilli() || !jud.equals(Date.from(inst0))) {
        System.out.printf("ms: %16d  ns: %10d  ldt:[%s]%n", millis, nanos, ldt);
        throw new RuntimeException("FAILED: j.u.d -> instant -> j.u.d");
      }
      // roundtrip only with millis precision
      Date jud0 = Date.from(inst_ms);
      if (jud0.getTime() != inst_ms.toEpochMilli() || !inst_ms.equals(jud0.toInstant())) {
        System.out.printf("ms: %16d  ns: %10d  ldt:[%s]%n", millis, nanos, ldt);
        throw new RuntimeException("FAILED: instant -> j.u.d -> instant");
      }
      //////////// java.util.GregorianCalendar /////////////
      GregorianCalendar cal = new GregorianCalendar();
      // non-roundtrip of tz name between j.u.tz and j.t.zid
      cal.setTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault()));
      cal.setGregorianChange(new java.util.Date(Long.MIN_VALUE));
      cal.setFirstDayOfWeek(Calendar.MONDAY);
      cal.setMinimalDaysInFirstWeek(4);
      cal.setTimeInMillis(millis);
      ZonedDateTime zdt0 = cal.toZonedDateTime();
      if (cal.getTimeInMillis() != zdt0.toInstant().toEpochMilli()
          || !cal.equals(GregorianCalendar.from(zdt0))) {
        System.out.println("cal:" + cal);
        System.out.println("zdt:" + zdt0);
        System.out.println("calNew:" + GregorianCalendar.from(zdt0));
        System.out.printf("ms: %16d  ns: %10d  ldt:[%s]%n", millis, nanos, ldt);
        throw new RuntimeException("FAILED: gcal -> zdt -> gcal");
      }
      inst0 = cal.toInstant();
      if (cal.getTimeInMillis() != inst0.toEpochMilli()) {
        System.out.printf("ms: %16d  ns: %10d  ldt:[%s]%n", millis, nanos, ldt);
        throw new RuntimeException("FAILED: gcal -> zdt");
      }
      ZonedDateTime zdt = ZonedDateTime.of(ldt_ms, ZoneId.systemDefault());
      GregorianCalendar cal0 = GregorianCalendar.from(zdt);
      if (zdt.toInstant().toEpochMilli() != cal0.getTimeInMillis()
          || !zdt.equals(GregorianCalendar.from(zdt).toZonedDateTime())) {
        System.out.printf("ms: %16d  ns: %10d  ldt:[%s]%n", millis, nanos, ldt);
        throw new RuntimeException("FAILED: zdt -> gcal -> zdt");
      }
    }

    ///////////// java.util.TimeZone /////////////////////////
    for (String zidStr : TimeZone.getAvailableIDs()) {
      // TBD: tzdt intergration
      if (zidStr.startsWith("SystemV")
          || zidStr.contains("Riyadh8")
          || zidStr.equals("US/Pacific-New")
          || zidStr.equals("EST")
          || zidStr.equals("HST")
          || zidStr.equals("MST")) {
        continue;
      }
      ZoneId zid = ZoneId.of(zidStr, ZoneId.SHORT_IDS);
      if (!zid.equals(TimeZone.getTimeZone(zid).toZoneId())) {
        throw new RuntimeException("FAILED: zid -> tz -> zid :" + zidStr);
      }
      TimeZone tz = TimeZone.getTimeZone(zidStr);
      // no round-trip for alias and "GMT"
      if (!tz.equals(TimeZone.getTimeZone(tz.toZoneId()))
          && !ZoneId.SHORT_IDS.containsKey(zidStr)
          && !zidStr.startsWith("GMT")) {
        throw new RuntimeException("FAILED: tz -> zid -> tz :" + zidStr);
      }
    }
    System.out.println("Passed!");
  }
  /**
   * Calculates Efforts and overheads data for users
   *
   * <p>EffortLefts are calculated for every week by summings efforts from blis assigned to user
   * from projects that start/end date hit in particular week.
   *
   * <p>For example: Weeks 1 2 3 4 Eff 20 20 10 10 projects 2 2 1 1 (10h blis each)
   *
   * <p>So efforts are just sumassignmentDAO.getAssignment(user, backlog).getDeltaOverhead();med
   * together and NOT divided for length of the project or weeks.
   */
  public DailyWorkLoadData getDailyWorkLoadData(User user, int weeksAhead) {
    DailyWorkLoadData data = new DailyWorkLoadData();
    Map<Backlog, BacklogLoadData> loadDataList = new HashMap<Backlog, BacklogLoadData>();
    ArrayList<Integer> weekNumbers = new ArrayList<Integer>();
    // String[] overallTotals = new String[3]; // Not currently used, but
    // could
    // use in the future

    GregorianCalendar cal = new GregorianCalendar();
    cal.setFirstDayOfWeek(GregorianCalendar.MONDAY);

    int currentWeek = cal.get(GregorianCalendar.WEEK_OF_YEAR);

    // 1. Weeks
    for (int i = 0; i < weeksAhead; i++) {
      int weekNum = currentWeek + i;
      if (weekNum > 52) weekNum -= 52;
      weekNumbers.add(weekNum);
      if (!data.getWeeklyTotals().containsKey(weekNum)) {
        data.getWeeklyTotals().put(new Integer(weekNum), new AFTime(0));
        data.getWeeklyEfforts().put(new Integer(weekNum), new AFTime(0));
        data.getWeeklyOverheads().put(new Integer(weekNum), new AFTime(0));
      }
    }

    // 2. Backlog loads
    List<Backlog> assignedBacklogs =
        this.backlogBusiness.getUserBacklogs(user, new Date(), weeksAhead);

    data.setBacklogs(assignedBacklogs);

    // Loop through the backlogs
    for (Backlog blog : assignedBacklogs) {
      BacklogLoadData bdata =
          this.backlogBusiness.calculateBacklogLoadData(blog, user, new Date(), weeksAhead);
      loadDataList.put(bdata.getBacklog(), bdata);

      // Calculate totals
      for (Integer weekNo : weekNumbers) {
        AFTime effAdd = bdata.getEfforts().get(weekNo);
        if (effAdd != null) {
          data.getWeeklyEfforts().get(weekNo).add(effAdd);
          data.getTotalEffort().add(effAdd);
        }

        AFTime ohAdd = bdata.getOverheads().get(weekNo);
        if (ohAdd != null) {
          data.getWeeklyOverheads().get(weekNo).add(ohAdd);
          data.getTotalOverhead().add(ohAdd);
        }

        AFTime toAdd = bdata.getWeeklyTotals().get(weekNo);
        if (toAdd != null) {
          data.getWeeklyTotals().get(weekNo).add(toAdd);
          data.getOverallTotal().add(toAdd);
        }
      }
    }
    for (Integer weekNo : weekNumbers) {
      int lastWeek = weekNo - 1;
      if (lastWeek < 1) lastWeek += 52;
      boolean accommondate =
          isAccommodableWorkload(currentWeek, weekNo, data.getWeeklyTotals().get(weekNo), user);
      data.getWeeklyOverload().put(weekNo, new Boolean(accommondate));
    }
    data.setWeekNumbers(weekNumbers);
    data.setLoadDatas(loadDataList);

    return data;
  }