Package java.util

Examples of java.util.Calendar


    HashMap headerList = new HashMap();
    HashMap headerLinkList = new HashMap();
    HashMap dateList = new HashMap();

    ArrayList calendarNavBarList = new ArrayList();
    Calendar currentCalendar = Calendar.getInstance();
    int thisDayOfMonth = currentCalendar.get(Calendar.DAY_OF_MONTH);
    int thisMonthOfYear = currentCalendar.get(Calendar.MONTH);
    String thisMonth = getCalenderMonthName(thisMonthOfYear);
    int thisYear = currentCalendar.get(Calendar.YEAR);

    if (calendarType != null && (calendarType.equals("DAILY") || calendarType.equals(""))) {
      int previousDailyDay = 0;
      String previousDailyMonth = "";
      int previousDailyYear = 0;

      if (currentDay != 0 && currentMonth >= 0 && currentYear != 0) {
        Calendar previousCalendarWeek = Calendar.getInstance();
        previousCalendarWeek.set(currentYear, currentMonth, currentDay);
        previousCalendarWeek.add(Calendar.DATE, -1);
        previousDailyDay = previousCalendarWeek.get(Calendar.DATE);
        int intYearOfMonth = previousCalendarWeek.get(Calendar.MONTH);
        previousDailyMonth = getCalenderMonthName(intYearOfMonth);
        previousDailyYear = previousCalendarWeek.get(Calendar.YEAR);
      }
      int nextDailyDay = 0;
      String nextDailyMonth = "";
      int nextDailyYear = 0;
      if (currentDay != 0 && currentMonth >= 0 && currentYear != 0) {
        Calendar nextCalendarWeek = Calendar.getInstance();
        nextCalendarWeek.set(currentYear, currentMonth, currentDay);
        nextCalendarWeek.add(Calendar.DATE, +1);
        nextDailyDay = nextCalendarWeek.get(Calendar.DATE);
        int intYearOfMonth = nextCalendarWeek.get(Calendar.MONTH);
        nextDailyYear = nextCalendarWeek.get(Calendar.YEAR);
        nextDailyMonth = getCalenderMonthName(intYearOfMonth);
      }

      StringBuffer previous = new StringBuffer();
      previous.append("c_goTo('/calendar.do?Type=DAILY&selectedDay=" + previousDailyDay);
      previous.append("&selectedMonthName=" + previousDailyMonth + "&selectedYear=" + previousDailyYear + "');");

      StringBuffer current = new StringBuffer();
      current.append("c_goTo('/calendar.do?Type=DAILY&selectedDay=" + thisDayOfMonth);
      current.append("&selectedMonthName=" + thisMonth + "&selectedYear=" + thisYear + "');");

      StringBuffer next = new StringBuffer();
      next.append("c_goTo('/calendar.do?Type=DAILY&selectedDay=" + nextDailyDay);
      next.append("&selectedMonthName=" + nextDailyMonth + "&selectedYear=" + nextDailyYear + "');");

      calendarNavBarList.add(new DDNameValue("Previous", previous.toString()));
      calendarNavBarList.add(new DDNameValue("Today", current.toString()));
      calendarNavBarList.add(new DDNameValue("Next", next.toString()));
    } else if (calendarType != null && (calendarType.equals("WEEKLY") || calendarType.equals("WEEKLYCOLUMNS"))) {
      int previousWeekDate = 0;
      String previousWeekMonth = "";
      int previousWeekYear = 0;
      if (currentDay != 0 && currentMonth >= 0 && currentYear != 0) {
        Calendar previousCalendarWeek = Calendar.getInstance();
        previousCalendarWeek.set(currentYear, currentMonth, currentDay);
        previousCalendarWeek.add(Calendar.DATE, -7);
        previousWeekDate = previousCalendarWeek.get(Calendar.DATE);
        int intYearOfMonth = previousCalendarWeek.get(Calendar.MONTH);
        previousWeekMonth = getCalenderMonthName(intYearOfMonth);
        previousWeekYear = previousCalendarWeek.get(Calendar.YEAR);
      }
      int nextWeekDay = 0;
      String nextWeekMonth = "";
      int nextWeekYear = 0;

      if (currentDay != 0 && currentMonth >= 0 && currentYear != 0) {
        Calendar nextCalendarWeek = Calendar.getInstance();
        nextCalendarWeek.set(currentYear, currentMonth, currentDay);
        nextCalendarWeek.add(Calendar.DATE, +7);
        nextWeekDay = nextCalendarWeek.get(Calendar.DATE);
        int intYearOfMonth = nextCalendarWeek.get(Calendar.MONTH);
        nextWeekYear = nextCalendarWeek.get(Calendar.YEAR);
        nextWeekMonth = getCalenderMonthName(intYearOfMonth);
      }

      StringBuffer previous = new StringBuffer();
      previous.append("c_goTo('/calendar.do?Type=" + calendarType + "&selectedDay=" + previousWeekDate);
      previous.append("&selectedMonthName=" + previousWeekMonth + "&selectedYear=" + previousWeekYear + "');");

      StringBuffer current = new StringBuffer();
      current.append("c_goTo('/calendar.do?Type=" + calendarType + "&selectedDay=" + thisDayOfMonth);
      current.append("&selectedMonthName=" + thisMonth + "&selectedYear=" + thisYear + "');");

      StringBuffer next = new StringBuffer();
      next.append("c_goTo('/calendar.do?Type=" + calendarType + "&selectedDay=" + nextWeekDay);
      next.append("&selectedMonthName=" + nextWeekMonth + "&selectedYear=" + nextWeekYear + "');");

      calendarNavBarList.add(new DDNameValue("Previous", previous.toString()));
      calendarNavBarList.add(new DDNameValue("Current Week", current.toString()));
      calendarNavBarList.add(new DDNameValue("Next", next.toString()));
      SimpleDateFormat formatter = new SimpleDateFormat("MM/dd");

      String dailyGo = "c_goTo('/calendar.do?Type=DAILY";

      if (currentDay != 0 && currentMonth >= 0 && currentYear != 0) {
        Calendar headerCalendarWeek = Calendar.getInstance();
        headerCalendarWeek.set(currentYear, currentMonth, currentDay);

        int dayOfWeek = headerCalendarWeek.get(Calendar.DAY_OF_WEEK);
        // Subtracting it with 2 coz in the Calendar Starting Day is Monday.
        int offset = dayOfWeek - 2;
        if (offset < 0) {
          int daysInWeek = 7;
          // if we are before the current day of the week, we need to fall all
          // the way back to the previous beginning of the week. calculating our
          // offset in this way will give us the right num of days to the
          // previous start. this makes it easy to just add it to the
          // currentDate.
          offset = daysInWeek + offset;
        }
        int currentDate = headerCalendarWeek.get(Calendar.DATE);
        headerCalendarWeek.set(Calendar.DATE, currentDate - offset);

        int headerDayOfMonth = headerCalendarWeek.get(Calendar.DATE);
        int headerMonthOfYear = headerCalendarWeek.get(Calendar.MONTH);
        int headerYear = headerCalendarWeek.get(Calendar.YEAR);

        try {
          // This is used in the columnar weekly view for calculating the
          // date to be filled in when you click on a empty cell.
          calendarNavBarMap.put("startDayOfWeek", new Integer(headerDayOfMonth));
        } catch (NumberFormatException nfe) {
          logger.info("[setCalendarNavBar]: The offset for the clickable weekly view boxes will probably be broken.");
          calendarNavBarMap.put("startDayOfWeek", new Integer(0));
        }

        String dateString = headerYear + ",'" + getCalenderMonthName(headerMonthOfYear) + "'," + headerDayOfMonth;
        String headerDate = formatter.format(headerCalendarWeek.getTime());
        String dailyDate = "&selectedDay=" + headerDayOfMonth + "&selectedMonthName=" + getCalenderMonthName(headerMonthOfYear) + "&selectedYear="
            + headerYear;

        String action = "ScheduleActivity(" + dateString + ",'','');";
        dateList.put(String.valueOf(0), action);
        headerLinkList.put(String.valueOf(0), dailyGo + dailyDate + "');");
        headerList.put(String.valueOf(0), headerDate);
        int count = 1;
        for (int i = 0; i < 6; i++) {
          headerCalendarWeek.add(Calendar.DATE, 1);
          headerDayOfMonth = headerCalendarWeek.get(Calendar.DAY_OF_MONTH);
          headerMonthOfYear = headerCalendarWeek.get(Calendar.MONTH);
          headerYear = headerCalendarWeek.get(Calendar.YEAR);
          dateString = headerYear + ",'" + getCalenderMonthName(headerMonthOfYear) + "'," + headerDayOfMonth;
          action = "ScheduleActivity(" + dateString + ",'','');";
          dateList.put(String.valueOf(count), action);
          headerDate = formatter.format(headerCalendarWeek.getTime());
          headerList.put(String.valueOf(count), headerDate);
          dailyDate = "&selectedDay=" + headerDayOfMonth + "&selectedMonthName=" + getCalenderMonthName(headerMonthOfYear) + "&selectedYear="
              + headerYear;
          headerLinkList.put(String.valueOf(count), dailyGo + dailyDate + "');");
          count++;
        }
      }
    } else if (calendarType != null && calendarType.equals("MONTHLY")) {
      int previousMonthlyDay = 0;
      String previousMonthlyMonth = "";
      int previousMonthlyYear = 0;

      if (currentDay != 0 && currentMonth >= 0 && currentYear != 0) {
        Calendar previousCalendarWeek = Calendar.getInstance();
        previousCalendarWeek.set(currentYear, currentMonth, currentDay);
        previousCalendarWeek.add(Calendar.MONTH, -1);
        previousMonthlyDay = previousCalendarWeek.get(Calendar.DATE);
        int intYearOfMonth = previousCalendarWeek.get(Calendar.MONTH);
        previousMonthlyMonth = getCalenderMonthName(intYearOfMonth);
        previousMonthlyYear = previousCalendarWeek.get(Calendar.YEAR);
      }

      int nextMonthlyDay = 0;
      String nextMonthlyMonth = "";
      int nextMonthlyYear = 0;

      if (currentDay != 0 && currentMonth >= 0 && currentYear != 0) {
        Calendar nextCalendarWeek = Calendar.getInstance();
        nextCalendarWeek.set(currentYear, currentMonth, currentDay);
        nextCalendarWeek.add(Calendar.MONTH, 1);
        nextMonthlyDay = nextCalendarWeek.get(Calendar.DATE);
        int intYearOfMonth = nextCalendarWeek.get(Calendar.MONTH);
        nextMonthlyYear = nextCalendarWeek.get(Calendar.YEAR);
        nextMonthlyMonth = getCalenderMonthName(intYearOfMonth);
      }
      StringBuffer previous = new StringBuffer();
      previous.append("c_goTo('/calendar.do?Type=MONTHLY&selectedDay=" + previousMonthlyDay);
      previous.append("&selectedMonthName=" + previousMonthlyMonth + "&selectedYear=" + previousMonthlyYear + "');");
View Full Code Here


      if ( start == null ) {
        start=new Date();
      }

      if ( end == null ) {
        Calendar temp = Calendar.getInstance();
        temp.setTime(new Date());
        temp.add(Constants.convertFreqNameToCalendarField(freq),interval*2);
        end = temp.getTime();
      }

      //===== WALK the dates that are described in the freq/interval.  Also fill in any
      //===== sets that are required at each level
      Calendar cur = Calendar.getInstance();
      cur.clear();
      cur.setLenient(false);
      Calendar limit = Calendar.getInstance();
      limit.clear();
      limit.setLenient(false);
      limit.setTime(end);

      //----------------- Build the year list
      cur.setTime( start );
      int val;

      if ( "YEARLY".equals(freq) ){
        //--- build by freq
        protoDateList.addAll( getFullDateValueList(Calendar.YEAR,interval,cur,limit) );
      }

      //----------------- Build the month list
      cur.setTime( start );
      if ( "MONTHLY".equals(freq) ){
        //--- build by freq
        protoDateList.addAll( getFullDateValueList(Calendar.MONTH,interval,cur,limit) );
      }
      else if ( !foundByMonth ){
        monthSet.add( new Integer( cur.get(Calendar.MONTH) ) ); // adding user fudge
      }

      //----------------- Build the day list  STILL VERY EVIL
      cur.setTime( start );
      if ( "DAILY".equals(freq) ){
        //--- build by freq
        protoDateList.addAll( getFullDateValueList(Calendar.DAY_OF_MONTH,interval,cur,limit) );
      }
      else if ( !foundByDay && !foundByWeekNo && !foundByMonthDay && !foundByYearDay ){
        monthDaySet.add( new Integer( cur.get(Calendar.DAY_OF_MONTH) ) );
      }

      //----------------- Build the week list
      cur.setTime( start );
      if ( "WEEKLY".equals(freq) ){
        //--- build by freq
        protoDateList.addAll( getFullDateValueList(Calendar.WEEK_OF_YEAR,interval,cur,limit) );
        if ( !foundByDay ){
          weekDaySet.add( new ByDay(0,Constants.convertDayNumberToDayName(cur.get(Calendar.DAY_OF_WEEK)) ) );
        }
      }
      //--- the week from original date is not taken as a default


      //----------------- Build the hour list
      cur.setTime( start );
      if ( "HOURLY".equals(freq) ){
        //--- build by freq
        protoDateList.addAll( getFullDateValueList(Calendar.HOUR_OF_DAY,interval,cur,limit) );
      }
      else if ( !foundByHour ){
        hourSet.add( new Integer( cur.get(Calendar.HOUR_OF_DAY) ) );
      }

      //----------------- Build the minute list
      cur.setTime( start );
      if ( "MINUTELY".equals(freq) ){
        //--- build by freq
        protoDateList.addAll( getFullDateValueList(Calendar.MINUTE,interval,cur,limit) );
      }
      else if ( !foundByMinute ){
        minSet.add( new Integer( cur.get(Calendar.MINUTE) ) );
      }

      //----------------- Build the second list
      cur.setTime( start );
      if ( "SECONDLY".equals(freq) ){
        //--- build by freq
        protoDateList.addAll( getFullDateValueList(Calendar.SECOND,interval,cur,limit) );
      }
      else if ( !foundBySecond ){
        secSet.add( new Integer( cur.get(Calendar.SECOND) ) );
      }


      resultList = new ArrayList();
      Calendar result = Calendar.getInstance();
      result.setLenient(false);
      result.clear();

/*
      if ( TestRecurrance.debug ){
        println("pS   "+protoDateList.size());
        println("yS   "+yearSet.size()+"  "+yearSet);
        println("mS   "+monthSet.size()+"  "+monthSet);
        println("mDS  "+monthDaySet.size()+"  "+monthDaySet);
        println("wDS  "+weekDaySet.size()+"  "+weekDaySet);
        println("hS   "+hourSet.size()+"  "+hourSet);
        println("minS "+minSet.size()+"  "+minSet);
        println("sS   "+secSet.size()+"  "+secSet);
      }
*/

      //===== CULL the dates that are not acceptable to BYxyz commands which are of a higher
      //===== magnitude than the frequency
      int freqNumber = Constants.convertFreqNameToFreqNumber(freq);

      for ( int pdCtr = protoDateList.size()-1 ; pdCtr>=0 ; pdCtr-- ){
        Calendar curProtoDate = (Calendar)protoDateList.get(pdCtr);

        // BYMONTH
        if ( foundByMonth && freqNumber <= Constants.FREQ_MONTHLY ){
          if ( ! isDateInMetaSet(curProtoDate,Calendar.MONTH,monthSet) ){
            println("remove by month");
            protoDateList.remove(pdCtr);
            continue;
          }
        }
        // BYWEEKNO
        if ( foundByWeekNo && freqNumber <= Constants.FREQ_WEEKLY ){
          if ( ! isDateInMetaSet(curProtoDate,Calendar.WEEK_OF_YEAR,weekNumberSet) ){
            println("remove by week no");
            protoDateList.remove(pdCtr);
            continue;
          }
        }
        // BYYEARDAY
        if ( foundByYearDay && freqNumber <= Constants.FREQ_DAILY ){
          if ( ! isDateInMetaSet(curProtoDate,Calendar.DAY_OF_YEAR,yearDaySet) ){
            println("remove by year day");
            protoDateList.remove(pdCtr);
            continue;
          }
        }
        // BYMONTHDAY
        if ( foundByMonthDay && freqNumber <= Constants.FREQ_DAILY ){
          if ( ! isDateInMetaSet(curProtoDate,Calendar.DAY_OF_MONTH,monthDaySet) ){
            println("remove by month day");
            protoDateList.remove(pdCtr);
            continue;
          }
        }
        // BYDAY - Deeply Evil
        if ( foundByDay && freqNumber <= Constants.FREQ_DAILY ){
          if ( ! isDateInWeekDayMetaSet(curProtoDate,Calendar.DAY_OF_MONTH,weekDaySet) ){
            println("remove by month day");
            protoDateList.remove(pdCtr);
            continue;
          }
        }
        // BYHOUR
        if ( foundByHour && freqNumber <= Constants.FREQ_HOURLY ){
          if ( ! isDateInMetaSet(curProtoDate,Calendar.HOUR_OF_DAY,hourSet) ){
            println("remove by hour");
            protoDateList.remove(pdCtr);
            continue;
          }
        }
        // BYMINUTE
        if ( foundByMinute && freqNumber <= Constants.FREQ_MINUTELY ){
          if ( ! isDateInMetaSet(curProtoDate,Calendar.MINUTE,minSet) ){
            println("remove by minute");
            protoDateList.remove(pdCtr);
            continue;
          }
        }
      }

      //===== SPEW in the dates that are added by using a BYxyz of lower
      //===== magnitude than the frequency

      HashSet resultSet = new HashSet();

      for ( int pdCtr = protoDateList.size()-1 ; pdCtr>=0 ; pdCtr-- ){
        Calendar curProtoDate = (Calendar)protoDateList.get(pdCtr);

        HashSet resultPile = new HashSet();
        resultPile.add(curProtoDate);

        // BYMONTH
        if ( freqNumber > Constants.FREQ_MONTHLY ){
          resultPile = breedMetaSet(resultPile,Calendar.MONTH,monthSet);
        }

        // BYWEEKNO
        if ( freqNumber > Constants.FREQ_WEEKLY ){
          resultPile = breedMetaSet(resultPile,Calendar.WEEK_OF_YEAR,weekNumberSet);
        }
        // BYYEARDAY
        if ( freqNumber > Constants.FREQ_DAILY && freqNumber != Constants.FREQ_WEEKLY ){
          resultPile = breedMetaSet(resultPile,Calendar.DAY_OF_YEAR,yearDaySet);
        }
        // BYMONTHDAY
        if ( freqNumber > Constants.FREQ_DAILY && freqNumber != Constants.FREQ_WEEKLY ){
          resultPile = breedMetaSet(resultPile,Calendar.DAY_OF_MONTH,monthDaySet);
        }
        // BYDAY - Deeply Evil
        if ( freqNumber > Constants.FREQ_DAILY                  /*&& freqNumber != Constants.FREQ_WEEKLY*/ ){
          resultPile = breedWeekDayMetaSet(resultPile,weekDaySet);
        }
        // BYHOUR
        if ( freqNumber > Constants.FREQ_HOURLY ){
          resultPile = breedMetaSet(resultPile,Calendar.HOUR_OF_DAY,hourSet);
        }
        // BYMINUTE
        if ( freqNumber > Constants.FREQ_MINUTELY ){
          resultPile = breedMetaSet(resultPile,Calendar.MINUTE,minSet);
        }
        // BYSECOND
        if ( freqNumber > Constants.FREQ_SECONDLY ){
          resultPile = breedMetaSet(resultPile,Calendar.SECOND,secSet);
        }

        resultSet.addAll(resultPile);
      }

      println("pS pb "+resultSet.size());

      //--- convert the calendar objects into date objects
      for ( Iterator rsIt = resultSet.iterator(); rsIt.hasNext() ; ){
        Calendar c = (Calendar)rsIt.next();
        resultList.add(c.getTime());
      }


      Collections.sort(resultList);

      //===== ENSURE the limitation on the primary dates
      //--- ensure the bounds
      for ( int rctr=resultList.size()-1;rctr>=0;rctr-- ){
        Date curDate = (Date)resultList.get(rctr);
        if ( ! ( (curDate.before(end) || curDate.equals(end)) &&
                 (curDate.after(start) || curDate.equals(start)) ) ){
          resultList.remove(rctr);
        }
      }
/*
      if ( TestRecurrance.debug ){
        println("rS "+resultList.size());
      }
*/
      //===== FILTER the dates returned
      //--- apply the BYSETPOS filter by examining the dates for each recurrance and culling appropriately
      //--- note that finalList MUST be sorted for this to work.
      resultList = (ArrayList)filterUsingBySetPos(resultList, bspSet, Constants.convertFreqNameToCalendarField(freq) );

      //--- apply the OFFSET filter by altering each date as requested.  NOTE:  This may take dates outside
      //      the start and end range.  (I.E. you'll want a meeting reminder before the start of the first
      //      meeting)



      //--- ensure the count
      List finalList;
      if ( count != 0 && resultList.size() > count ){
        finalList = (List)resultList.subList(0,count);
      }
      else{
        finalList = resultList;
      }

      //==== MODIFY the dates returned using OFFSET
      if( offsetAmount != 0 ){
        Calendar modificationTool = Calendar.getInstance();
        for(int ctr=0;ctr<finalList.size();ctr++){
          Date curMod = (Date)finalList.get(ctr);
          modificationTool.setTime(curMod);
          modificationTool.add(offsetUnit, offsetAmount);
          curMod = modificationTool.getTime();
          finalList.set(ctr,curMod);
        }

      }

View Full Code Here

  @param cur the start of the range
  @param end the end of the range.
  ***/
  private List getValueList(int unit, int interval, Calendar inputCur, Calendar inputEnd)
  {
    Calendar cur = roundDown(unit,(Calendar)inputCur.clone());
    Calendar end = roundDown(unit,(Calendar)inputEnd.clone());

    int val = cur.get(unit);

    ArrayList resultList = new ArrayList();
    //println("val "+val);
    resultList.add(new Integer(val));

    cur.add(unit, interval);

    while ( cur.getTime().before(end.getTime()) ||
            cur.getTime().equals(end.getTime()) ){              // while not past the end date
      val = cur.get(unit);
      //println("val "+val);
      resultList.add(new Integer(val));
      cur.add(unit, interval);
    }
View Full Code Here

  @param cur the start of the range
  @param end the end of the range.
  ***/
  private List getFullDateValueList(int unit, int interval, Calendar inputCur, Calendar inputEnd)
  {
    Calendar cur = roundDown(unit,(Calendar)inputCur.clone());
    Calendar end = roundDown(unit,(Calendar)inputEnd.clone());

    println("Round Down  "+cur.getTime());
    println("Round Up    "+end.getTime());
    //int val = cur.get(unit);

    ArrayList resultList = new ArrayList();
    resultList.add( cur.clone() );
    println("val "+cur.getTime());

    cur.add(unit, interval);

    while ( cur.getTime().before(end.getTime()) ||
            cur.getTime().equals(end.getTime()) ){              // while not past the end date
      println("val "+cur.getTime());
      resultList.add( cur.clone() );
      cur.add(unit, interval);
    }

View Full Code Here

  @param unRounded a calendar value
  @return a rounded calendar value
  ***/
  private Calendar roundDown(int unit,Calendar unRounded)
  {
    Calendar result = (Calendar)unRounded.clone();
    //println("pre "+result.getTime());

    if ( unit < Calendar.YEAR ) result.set(Calendar.YEAR,0);
    if ( unit < Calendar.MONTH ) result.set(Calendar.MONTH,0);
    if ( unit < Calendar.DAY_OF_MONTH ) result.set(Calendar.DAY_OF_MONTH,1);
    if ( unit < Calendar.HOUR_OF_DAY ) result.set(Calendar.HOUR_OF_DAY,0);
    if ( unit < Calendar.MINUTE ) result.set(Calendar.MINUTE,0);
    if ( unit < Calendar.SECOND ) result.set(Calendar.SECOND,0);

    if ( unit == Calendar.WEEK_OF_YEAR ) result.set(Calendar.WEEK_OF_YEAR,unRounded.get(Calendar.WEEK_OF_YEAR));

    //println("post "+result.getTime());
    return result;
  }
View Full Code Here

        if ( curProtoDate.get(Calendar.DAY_OF_WEEK) == Constants.convertDayNameToDayNumber(bd.weekday) ){
          return true;
        }
      }
      else{
        Calendar hunter = huntDayOfWeek(curProtoDate, bd);
        if ( hunter.get(Calendar.DAY_OF_YEAR) == curProtoDate.get(Calendar.DAY_OF_YEAR) ){
          return true;
        }
      }
    }
    //--- we can only get here if none of the previous items matched and returned true.
View Full Code Here

  @param unit either Calendar.MONTH or Calendar.YEAR depending on the current
  ***/
  private Calendar huntDayOfWeek(Calendar curProtoDate,
                                 ByDay bd)
  {
    Calendar hunter = (Calendar)curProtoDate.clone();
    //println("hunting");

    // figure out if we're talking months or years.
    int unit = Calendar.DAY_OF_MONTH;
    if ( "YEARLY".equals(freq) ){
      unit = Calendar.DAY_OF_YEAR;
    }
    //println("hunting: unit "+unit);

    // figure out what direction we're going
    int start = 1;
    int limit = curProtoDate.getActualMaximum(unit);
    int direction = 1;
    if ( bd.count < 0 ){
      start = limit;
      limit = 1;
      direction = -1;
    }
    //println("hunting: start "+start);
    //println("hunting: limit "+limit);

    // figure out day we want
    int goalDow = Constants.convertDayNameToDayNumber(bd.weekday);

    // spin through the days and hunt for the date of the requested week day
    hunter.set(unit,start);
    int foundCount = 0;
    int safety = 0;
    while ( foundCount < Math.abs(bd.count) ) {
      if ( hunter.get(Calendar.DAY_OF_WEEK) == goalDow ){
        foundCount++;
      }
      hunter.add(unit,direction);
      safety++;
      if ( safety>366 ){
        // this should never happen.  :]
        throw new IllegalArgumentException("  ERROR: This loop has spun out of control. Either the week code you entered is bad, or you have asked for too large of an ofset");
      }
    }
    // undo the for-loop fudging and return the value
    hunter.add(unit,-1*direction);
    //println("hunting: found count "+foundCount);
    //println("hunting: returning "+hunter.getTime());

    return hunter;
  }
View Full Code Here

    }

    HashSet result = new HashSet();

    for ( Iterator oit = origSet.iterator() ; oit.hasNext() ; ){
      Calendar curProtoDate = (Calendar)oit.next();

      int localMax = curProtoDate.getActualMaximum(unit);
      int modVal;

      for ( Iterator it = metaSet.iterator() ; it.hasNext() ; ){
        modVal = ((Integer)it.next()).intValue();
        if ( modVal<0 ){
          //-1 implies the last item in the group, so the +1 makes it all work out.
          modVal = modVal+localMax+1;
        }
        Calendar newDate = (Calendar)curProtoDate.clone();
        newDate.set(unit,modVal);
        result.add(newDate);
      }
    }

    return result;
View Full Code Here

      dynaForm.set("whoshouldattend", eventDetails.getWhoshouldattend());
      dynaForm.set("maxattendees", "" + eventDetails.getMaxattendees());
      dynaForm.set("moderatorid", "" + eventDetails.getModeratorid());
      dynaForm.set("moderatorname", eventDetails.getModeratorname());

      Calendar calendar = new GregorianCalendar();

      if (eventDetails.getStartdate() != null)
      {
        Timestamp date = (Timestamp)eventDetails.getStartdate();
        calendar.setTimeInMillis(date.getTime());

        int[] hhmm = new int[2];
        hhmm[0] = calendar.get(Calendar.HOUR_OF_DAY);
        hhmm[1] = calendar.get(Calendar.MINUTE);

        String strTime = CVUtility.convertTime24HrsFormatToStr(hhmm);
        dynaForm.set("startmonth", Integer.toString(calendar.get(Calendar.MONTH) + 1));
        dynaForm.set("startday", Integer.toString(calendar.get(Calendar.DATE)));
        dynaForm.set("startyear", Integer.toString(calendar.get(Calendar.YEAR)));
        dynaForm.set("starttime", strTime);
      }

      if (eventDetails.getEnddate() != null)
      {
        Timestamp date = (Timestamp)eventDetails.getEnddate();
        calendar.setTimeInMillis(date.getTime());

        int[] hhmm = new int[2];
        hhmm[0] = calendar.get(Calendar.HOUR_OF_DAY);
        hhmm[1] = calendar.get(Calendar.MINUTE);

        String strTime = CVUtility.convertTime24HrsFormatToStr(hhmm);
        dynaForm.set("endmonth", Integer.toString(calendar.get(Calendar.MONTH) + 1));
        dynaForm.set("endday", Integer.toString(calendar.get(Calendar.DATE)));
        dynaForm.set("endyear", Integer.toString(calendar.get(Calendar.YEAR)));
        dynaForm.set("endtime", strTime);
      }

      if (eventDetails.getCreateddate() != null)
      {
        Timestamp date = (Timestamp)eventDetails.getCreateddate();
        calendar.setTimeInMillis(date.getTime());

        String month = getCalenderMonth(calendar.get(Calendar.MONTH) + 1);

        dynaForm.set("createddate", month + " " + Integer.toString(calendar.get(Calendar.DATE)) + ", " + Integer.toString(calendar.get(Calendar.YEAR)));
      }

      if (eventDetails.getModifieddate() != null)
      {
        Timestamp date = (Timestamp)eventDetails.getModifieddate();

        calendar.setTimeInMillis(date.getTime());

        String month = getCalenderMonth(calendar.get(Calendar.MONTH) + 1);

        dynaForm.set("modifieddate", month + " " + Integer.toString(calendar.get(Calendar.DATE)) + ", " + Integer.toString(calendar.get(Calendar.YEAR)));
      }

          if (!duplicateEvent)
          {
        try
View Full Code Here

    println("in bwdms: unit = "+unit);

    HashSet result = new HashSet();

    for ( Iterator oit = origSet.iterator() ; oit.hasNext() ; ){
      Calendar curProtoDate = (Calendar)oit.next();

      for ( Iterator it = metaSet.iterator() ; it.hasNext() ; ){
        ByDay bd  = (ByDay)it.next();

        if ( bd.count==0 ){
          println("in bwdms: finding all");
          // they want all occurrences
          ByDay localbd = new ByDay(1,bd.weekday);


          Calendar str = Calendar.getInstance();
          str.setTime(start);
          Calendar hunter = huntDayOfWeek( str , localbd);

          // some of the other BYxyz commands may limit the scope of this breeding.
          // figure that out here
          int localUnit = unit;
          boolean needSameMonth = false;
          boolean needSameWeek = false;
          boolean needSameDay = false;
          if ( foundByMonth || "MONTHLY".equals(freq) ) needSameMonth = true;
          //if ( foundByMonthDay || foundByWeekNo || foundByYearDay || "WEEKLY".equals(freq) ) needSameWeek = true;
          if ( foundByWeekNo || "WEEKLY".equals(freq) ) needSameWeek = true;
          if ( foundByMonthDay || foundByYearDay || "DAILY".equals(freq) ) needSameDay = true;

          println("nsm "+needSameMonth);
          println("nsw "+needSameWeek);
          println("nsd "+needSameDay);

          while ( hunter.getTime().before(end) ){               //JJHNOTE
            if ( hunter.get(Calendar.YEAR) == curProtoDate.get(Calendar.YEAR) ){
              if ( !needSameMonth || ( needSameMonth && hunter.get(Calendar.MONTH) == curProtoDate.get(Calendar.MONTH) ) ){
                if ( !needSameWeek || ( needSameWeek && hunter.get(Calendar.WEEK_OF_YEAR) == curProtoDate.get(Calendar.WEEK_OF_YEAR)) ){
                  if ( !needSameDay || ( needSameDay && hunter.get(Calendar.DAY_OF_YEAR) == curProtoDate.get(Calendar.DAY_OF_YEAR)) ){
                    result.add( hunter.clone() );
                  }
                }
              }
            }
            hunter.add( Calendar.WEEK_OF_YEAR, 1);
          }

        }
        else{
          println("in bwdms: finding specific");
View Full Code Here

TOP

Related Classes of java.util.Calendar

Copyright © 2015 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.