Package java.util

Examples of java.util.GregorianCalendar


   * @param locale the locale.
   * @return
   */
  public ActionErrors validateDateString(String fieldLabel, String date, Locale locale, String errorKey, ActionErrors actionErrors)
  {
    Calendar calendar = new GregorianCalendar();
    calendar.setLenient(false);
    DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
    try {
      Date parsedDate = df.parse(date);
      calendar.setTime(parsedDate);
    } catch (ParseException e) {
      ActionMessage error = new ActionMessage(errorKey, messages.getMessage(fieldLabel));
      actionErrors.add(errorKey, error);
    } catch (Exception e) {
      ActionMessage error = new ActionMessage(errorKey, messages.getMessage(fieldLabel));
View Full Code Here


        endMinute = "0" + endMinute;
      }

      // need to modify for locale support in future - Ashwin
      // get start calendar
      GregorianCalendar startCalendar = new GregorianCalendar(Integer.parseInt(yearStartValue
          .trim()), Integer.parseInt(monthStartValue.trim()), Integer
          .parseInt(dayStartValue.trim()), Integer.parseInt(startHour.trim()), Integer
          .parseInt(startMinute.trim()));
      // get end calendar
      GregorianCalendar endCalendar = new GregorianCalendar(Integer.parseInt(yearEndValue.trim()),
          Integer.parseInt(monthEndValue.trim()), Integer.parseInt(dayEndValue.trim()), Integer
              .parseInt(endHour.trim()), Integer.parseInt(endMinute.trim()));

      // compare start date and end date
      if (endCalendar.before(startCalendar)) {
        isError = true;
      } else {
        isError = false;
      }

      // check for date error or time error
      if (isError) {
        // check if date is proper by having time = 00:00 AM
        // get start calendar
        startCalendar = new GregorianCalendar(Integer.parseInt(yearStartValue.trim()), Integer
            .parseInt(monthStartValue.trim()), Integer.parseInt(dayStartValue.trim()), 00, 00);
        // get end calendar
        endCalendar = new GregorianCalendar(Integer.parseInt(yearEndValue.trim()), Integer
            .parseInt(monthEndValue.trim()), Integer.parseInt(dayEndValue.trim()), 00, 00);

        // compare start date and end date
        if (endCalendar.before(startCalendar)) {
          // if error then error is in date
          isError = true;
          ActionMessage error = new ActionMessage(errorKey, messages.getMessage(fieldEndDateLabel),
              messages.getMessage(fieldStartDateLabel));
          actionErrors.add(errorKey, error);
View Full Code Here

    boolean isError = true;
    try {
      // need to modify for locale support in future - Ashwin
      // get start calendar
      GregorianCalendar startCalendar = new GregorianCalendar(Integer.parseInt(yearStartValue),
          Integer.parseInt(monthStartValue), Integer.parseInt(dayStartValue));
      // get end calendar
      GregorianCalendar endCalendar = new GregorianCalendar(Integer.parseInt(yearEndValue), Integer
          .parseInt(monthEndValue), Integer.parseInt(dayEndValue));

      // compare start date and end date
      if (endCalendar.before(startCalendar)) {
        isError = true;
      } else {
        isError = false;
      }
    } catch (Exception e) {
View Full Code Here

  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException, CommunicationException, NamingException
  {
      String Final_Forward = ".view.calendar.popup.calendar";
     
      TimeZone tz = TimeZone.getTimeZone("EST");
      GregorianCalendar startTimeUser = new GregorianCalendar(tz);
      startTimeUser.setFirstDayOfWeek(Calendar.MONDAY);
      startTimeUser.setTimeInMillis(System.currentTimeMillis());
      int currentDay = startTimeUser.get(Calendar.DATE);
      int currentMonth = startTimeUser.get(Calendar.MONTH);
      int currentYear = startTimeUser.get(Calendar.YEAR);
      request.setAttribute("currentDate", startTimeUser);

      String selectedDay = request.getParameter("selectedDay");
      String selectedMonthName = request.getParameter("selectedMonthName");
      String selectedYear = request.getParameter("selectedYear");
      int day = (selectedDay == null) ? currentDay : Integer.parseInt(selectedDay);
      int month = (selectedMonthName == null) ? currentMonth : CalendarUtil.getCalendarMonth(selectedMonthName);
      int year = (selectedYear == null) ? currentYear : Integer.parseInt(selectedYear);
      if(selectedMonthName == null){
        selectedMonthName = CalendarUtil.getCalenderMonthName(currentMonth);
      }
     
      GregorianCalendar selectedDate = new GregorianCalendar(year, month, 1);
      request.setAttribute("selectedDate", selectedDate);
      request.setAttribute("showWeeklyColumn", new Boolean(true));
      return (mapping.findForward(Final_Forward));
  }   // end execute(...)
View Full Code Here

      calendarlist.put(new Integer(i), new CalendarListElement(start, end));
      // pre-populate the row to contain zero items.
      TDColumn.put(new Integer(i), new Integer(0));
    }
 
    GregorianCalendar listRenderCalendar = new GregorianCalendar(tz);
    listRenderCalendar.setTime(starttimeuser.getTime());
 
    int counthour = 0;
    for (int i = 0; i < totalnumberofrows; i++) {
      // The Calendar fields will be used to track the current place in
      // the displayed calendar, we will increment through the blocks
      // and compare the activites returned from the list.
      int calendarDate = listRenderCalendar.get(Calendar.DATE);
      int calendarMonth = listRenderCalendar.get(Calendar.MONTH);
      int calendarYear = listRenderCalendar.get(Calendar.YEAR);
      Iterator activityIterator = calactivityVector.iterator();
      int uniqueId = 0;
      while (activityIterator.hasNext()) {
        uniqueId++;
        CalendarActivityObject activityobject = (CalendarActivityObject)activityIterator.next();
        GregorianCalendar starttime = activityobject.getStartTime();
        GregorianCalendar endtime = activityobject.getEndTime();
 
        // If somehow we squeezed an illegally formed activity in we should skip
        // it.
        if ((starttime.getTimeInMillis() > endTimeuser.getTimeInMillis())) {
          continue;
        }
        // calendarStartingBlock is the starting block for an activity on the
        // displayed table.
        int calendarStartingBlock = 0;
        // The critical info on the currently selected activity.
        int activityDate = starttime.get(Calendar.DATE);
        int activityMonth = starttime.get(Calendar.MONTH);
        int activityYear = starttime.get(Calendar.YEAR);
        int activityHour = starttime.get(Calendar.HOUR);
        int activityMinute = starttime.get(Calendar.MINUTE);
        int activityAMPM = starttime.get(Calendar.AM_PM);
        if (activityAMPM == 1) {
          activityHour = activityHour + 12;
        }
        boolean flag = false;
 
        // If the selected activity has the same month, date, and year
        // and we are looking at the Daily View.
        if (activityDate == calendarDate && activityMonth == calendarMonth
            && activityYear == calendarYear
            && (totalnumberofrows == 24 || totalnumberofrows == 48 || totalnumberofrows == 96)) {
          // if it is daily hourly blocks then the starting block is the
          // starting hour
          calendarStartingBlock = (activityHour);
          // otherwise we need calculate the starting block because the number
          // of blocks may
          // have doubled or quadrupled (30 or 15 minute intervals)
          // It needs to be the floor function of the division also.
          if (totalnumberofrows == 48) {
            int diffMinute = (int)Math.floor(activityMinute / 30.0);
            calendarStartingBlock = (calendarStartingBlock * 2) + diffMinute;
          } else if (totalnumberofrows == 96) {
            int diffMinute = (int)Math.floor(activityMinute / 15.0);
            calendarStartingBlock = (calendarStartingBlock * 4) + diffMinute;
          }
          flag = true;
        } else if (activityDate == calendarDate && activityMonth == calendarMonth
            && activityYear == calendarYear) {
          // it is still the same, but we are not one of the daily views.
          flag = true; // no setup required for numberof rows = 28 through 31
                        // ??
 
          calendarStartingBlock = (activityDate - 1);
          if (totalnumberofrows == 168) // if weekly columnar
          {
            calendarStartingBlock = starttime.get(Calendar.DAY_OF_WEEK);
            if (calendarStartingBlock == Calendar.SUNDAY) // if SUNDAY
            {
              calendarStartingBlock = 6; // then move to the end.
            } else {
              // else normalize monday to be zero (coupled to UI)                                                           // normalize
              calendarStartingBlock = calendarStartingBlock - Calendar.MONDAY;
            }
            calendarStartingBlock = (calendarStartingBlock * 24) + (activityHour);
 
            // Display as an allday activity on top
            if (activityobject.getAllDayEvent()) {
              activityobject.setAllDayTime();
              flag = false;
              allDayMap.put(activityobject.getActivityID(), activityobject);
            }
          }
 
          if (totalnumberofrows == 7) {
            // if weekly non-columnar
            calendarStartingBlock = starttime.get(GregorianCalendar.DAY_OF_WEEK);
            if (calendarStartingBlock == Calendar.SUNDAY) // if SUNDAY
            {
              calendarStartingBlock = 6; // then move to the end.
            } else {
              // else normalize monday to be zero (coupled to UI)                                                           // normalize
              calendarStartingBlock = calendarStartingBlock - Calendar.MONDAY;
            }
          }
        }
 
        if (flag) // It matches one of our calendar blocks, we need to display
                  // it
        {
          // Get the blank element we stuck in there before as a placeholder
          CalendarListElement element = (CalendarListElement)calendarlist.get(new Integer(
              calendarStartingBlock));
          // monthly will only use the element at 0 on calendarlist (I guess the
          // rest is designed for that)
          if (element != null) // if the element is null then our
                                // calendarStartingBlock is totally out of
                                // whack.
          {
            int numberOfRows = 1; // assume it only takes one row
            // We probably should take account if the activity spans to a
            // different day.
            // right now this doesn't seem to accomodate that.
            int activityEndHour = endtime.get(Calendar.HOUR);
            int activityEndAMPM = endtime.get(Calendar.AM_PM);
            if (activityEndAMPM == 1) {
              activityEndHour = activityEndHour + 12;
            }
 
            // calculate the number of rows the activity spans, if it is one of
            // the daily views
            // use ceiling function, so that any activity that impinges on the
            // above activity
            // will fill that row also.
            if (totalnumberofrows == 24 || totalnumberofrows == 48 || totalnumberofrows == 96) {
              // We must have to do the ZoneOffSet and DayLight Saving to
              // Offset.
              // off zone time values we must have to add to TimeInMillis
              long startTimeValue = starttime.getTimeInMillis()
                  + starttime.get(Calendar.ZONE_OFFSET) + starttime.get(Calendar.DST_OFFSET);
              long endTimeValue = endtime.getTimeInMillis() + endtime.get(Calendar.ZONE_OFFSET)
                  + endtime.get(Calendar.DST_OFFSET);
 
              double activityDuration = endTimeValue - startTimeValue;
              numberOfRows = (int)Math.ceil(activityDuration / (timespan * 60000));
 
              // When we have Scheduling and activity for two whole day event
View Full Code Here

    protected Timestamp getTimestamp(String day, String month, String year, String timeZone) {

        int startday   = Integer.parseInt(day);
        int startmonth = Integer.parseInt(month) - 1;
        int startyear  = Integer.parseInt(year);
        GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone(timeZone));
        gc.set(startyear,startmonth,startday,0,0,0);
        return new  Timestamp(gc.getTimeInMillis());
    }
View Full Code Here

      return "";
    }
   
    if (memberValue != null)
    {
      GregorianCalendar greg = null;
      boolean isTimestamp = false;    // used to determine if a mySQL TIMESTAMP value was
                                      // passed in, in the form of a java.sql.Date object
      try
      {
        greg = new GregorianCalendar(((Date)this.getMemberValue()).getYear(),((Date)this.getMemberValue()).getMonth(),((Date)this.getMemberValue()).getDate(),((Date)this.getMemberValue()).getHours(),((Date)this.getMemberValue()).getMinutes());
      }catch(Exception e){
        // mking is responsible for this code.
        // I'm making an assumption here, that if an exception was thrown above, then
        // we must have been passed a mySQL TIMESTAMP value in the form of a java.sql.Date
        // object. In that case, let's set the isTimestamp flag to true, and create an
        // empty GregorianCalendar object. Then populate that object via the setTime() method.
        isTimestamp = true;
        greg = new GregorianCalendar();
        try
        {
          // populate GregorianCalendar with the memberValue, which is a java.sql.Date object
          greg.setTime(memberValue);
        }catch(Exception err){
          System.out.println("[DateMember] DateMember.getDisplayString() threw Exception:");
          //err.printStackTrace();
        }
        System.out.println("[DateMember] DateMember.getDisplayString() threw Exception:");
        //e.printStackTrace();
      }

      if (! isTimestamp)
      {
        // if we didn't set the isTimestamp flag to true in the above block,
        // then continue with the previous code, setting time zone
        greg.setTimeZone(TimeZone.getTimeZone("EST"));

        greg.get(Calendar.HOUR_OF_DAY);

        greg.setTimeZone(TimeZone.getTimeZone(this.getTimeZone()));

        ((Date)this.getMemberValue()).setYear(greg.get(Calendar.YEAR));
        ((Date)this.getMemberValue()).setMonth(greg.get(Calendar.MONTH));
        ((Date)this.getMemberValue()).setDate(greg.get(Calendar.DATE));
        ((Date)this.getMemberValue()).setHours(greg.get(Calendar.HOUR_OF_DAY));
        ((Date)this.getMemberValue()).setMinutes(greg.get(Calendar.MINUTE));

        DateFormat df = null;

        // When you set the applyDate to false then
        // it will only display the Date and it will not consider the Time
View Full Code Here

  /**
   * changes the date & time of a Timestamp object by applying a new timezone
   */
  public static Timestamp convertTimeZone(Timestamp dt, TimeZone currentTZ, TimeZone targetTZ)
  {
    GregorianCalendar gc = new GregorianCalendar(currentTZ);
    gc.setTime(dt);
    gc.get(Calendar.YEAR);
    gc.setTimeZone(targetTZ);
    Timestamp nts = new Timestamp(gc.getTimeInMillis());
    return nts;
  }
View Full Code Here

  /**
   * changes the date of a Date object by applying a new timezone
   */
  public static Date convertTimeZone(Date dt, TimeZone currentTZ, TimeZone targetTZ)
  {
    GregorianCalendar gc = new GregorianCalendar(currentTZ);
    gc.setTime(dt);
    gc.setTimeZone(targetTZ);
    Date nts = new Date(gc.getTimeInMillis());
    return nts;
  }
View Full Code Here

          Timestamp startTimestamp = (Timestamp)oldEvent.getStartdate();
          Timestamp endTimestamp = (Timestamp)oldEvent.getEnddate();

          //This section SHOULD NOT NEED TO BE DONE.
          //The way Timestamps are currently handled means I have to do this this way.
          Calendar tempCalendar = new GregorianCalendar();
          //fix the start time
          tempCalendar.setTimeInMillis(startTimestamp.getTime());
          tempCalendar.add(Calendar.YEAR, 1900);
          startTimestamp.setTime(tempCalendar.getTimeInMillis());

          //fix the end time
          tempCalendar.setTimeInMillis(endTimestamp.getTime());
          tempCalendar.add(Calendar.YEAR, 1900);
          endTimestamp.setTime(tempCalendar.getTimeInMillis());
          //End of This section SHOULD NOT NEED TO BE DONE.

          newEventHashMap.put("StartDate", startTimestamp);
          newEventHashMap.put("EndDate", endTimestamp);
View Full Code Here

TOP

Related Classes of java.util.GregorianCalendar

Copyright © 2018 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.