Package java.text

Examples of java.text.DateFormat


    } else if (CVUtility.notEmpty(yearParam) && CVUtility.notEmpty(monthParam) && CVUtility.notEmpty(dayParam)) {
      startDate.set(Calendar.MONTH, Integer.parseInt(monthParam) - 1);
      startDate.set(Calendar.DATE, Integer.parseInt(dayParam));
      startDate.set(Calendar.YEAR, Integer.parseInt(yearParam));
    } else {
      DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
      startDate.setTime(df.parse(startDateString));
    }
    endDate = new GregorianCalendar(tz, locale);
    endDate.setTime(startDate.getTime());
    endDate.add(Calendar.HOUR, 24);
View Full Code Here


      populateForm.resetForm(request, form);
      ActivityForm activityForm = (ActivityForm)form;
      // set up the date formatter default to the request locale.
      Locale locale = request.getLocale();
      activityForm.setLocale(locale);
      DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
      DateFormat tf = DateFormat.getTimeInstance(DateFormat.SHORT, locale);

      int activityType = 1;

      String unScheduleActivity = "";
      if (request.getParameter("unScheduleActivity") != null) {
        unScheduleActivity = request.getParameter("unScheduleActivity").toString();
      }

      UserObject userObject = (UserObject)session.getAttribute("userobject");
      int individualID = userObject.getIndividualID();
      String userName = userObject.getfirstName() + " " + userObject.getlastName();

      if (request.getParameter("entityID") != null) {
        activityForm.setActivityEntityID(request.getParameter("entityID"));
      }

      if (request.getParameter("entityName") != null) {
        activityForm.setActivityEntityName(request.getParameter("entityName"));
      }

      if (request.getParameter("individualID") != null) {
        activityForm.setActivityIndividualID(request.getParameter("individualID"));
      }

      if (request.getParameter("individualName") != null) {
        activityForm.setActivityIndividualName(request.getParameter("individualName"));
      }

      if (request.getParameter("ProjectID") != null && request.getParameter("ProjectTitle") != null) {
        String projectID = request.getParameter("ProjectID");
        String projectTitle = request.getParameter("ProjectTitle");
        activityForm.setActivityRelatedFieldID(projectID);
        activityForm.setActivityRelatedFieldValue(projectTitle);
        activityForm.setActivityRelatedTypeValue("Project");
        activityForm.setActivityRelatedTypeID("36");
      }

      if (request.getParameter("oppID") != null) {
        String opportunityID = request.getParameter("oppID");
        activityForm.setActivityRelatedFieldID(opportunityID);
        activityForm.setActivityRelatedTypeValue("Opportunity");
        activityForm.setActivityRelatedTypeID("30");

        if (opportunityID != null && !(opportunityID.equals(""))) {
          int oppID = Integer.parseInt(opportunityID);
          SaleFacadeHome saleFacade = (SaleFacadeHome)CVUtility.getHomeObject(
              "com.centraview.sale.salefacade.SaleFacadeHome", "SaleFacade");
          SaleFacade remote = saleFacade.create();
          remote.setDataSource(dataSource);

          HashMap relatedOpportunityInfo = remote.getOpportunityRelatedInfo(individualID, oppID);

          if (relatedOpportunityInfo != null && relatedOpportunityInfo.size() != 0) {
            String title = (String)relatedOpportunityInfo.get("Title");
            if (title != null && !title.equals("") && !title.equals("NULL")) {
              activityForm.setActivityRelatedFieldValue(title);
            }

            if (relatedOpportunityInfo.get("EntityId") != null) {
              int entityid = ((Number)relatedOpportunityInfo.get("EntityId")).intValue();
              if (entityid != 0) {
                activityForm.setActivityEntityID(entityid + "");
                String entityName = (String)relatedOpportunityInfo.get("EntityName");
                if (entityName != null && !entityName.equals("") && !entityName.equals("NULL")) {
                  activityForm.setActivityEntityName(entityName);
                }
              }
            }

            if (relatedOpportunityInfo.get("IndividualId") != null) {
              int individualid = ((Number)relatedOpportunityInfo.get("IndividualId")).intValue();
              if (individualid != 0) {
                activityForm.setActivityIndividualID(individualid + "");
                String individualName = (String)relatedOpportunityInfo.get("individualname");
                if (individualName != null && !individualName.equals("")
                    && !individualName.equals("NULL")) {
                  activityForm.setActivityIndividualName(individualName);
                }
              }
            }
          } // end if (relatedOpportunityInfo != null &&
          // relatedOpportunityInfo.size() != 0)
        } // end if (opportunityID != null && !(opportunityID.equals("")))
      } // end if (request.getParameter("oppID") != null)

      if (request.getParameter("oppName") != null) {
        activityForm.setActivityRelatedFieldValue(request.getParameter("oppName"));
      }

      activityForm.setActivityOwnerID(String.valueOf(individualID));
      activityForm.setActivityOwnerName(userName);
      activityForm.setActivityPriority("2");
      activityForm.setActivityVisibility("PUBLIC");

      // All the following mess is to set a start and end time on the form.
      if ((request.getParameter("DAY") != null) && (request.getParameter("MONTH") != null)
          && (request.getParameter("YEAR") != null)) {
        // to digit
        String startMonthName = request.getParameter("MONTH");
        int startMonth = getCalendarMonth(startMonthName);
        String startDayString = request.getParameter("DAY");
        int startDay = Integer.parseInt(startDayString);
        String startYearString = request.getParameter("YEAR");
        int startYear = Integer.parseInt(startYearString);

        Calendar start = new GregorianCalendar(startYear, startMonth, startDay, 8, 0);
        String startTimeString = tf.format(start.getTime());
        if (CVUtility.notEmpty(request.getParameter("STIME"))) {
          startTimeString = request.getParameter("STIME");
        }
        Calendar passedTime = new GregorianCalendar();
        passedTime.setTime(tf.parse(startTimeString));
        start.set(Calendar.HOUR, passedTime.get(Calendar.HOUR));
        start.set(Calendar.MINUTE, passedTime.get(Calendar.MINUTE));
        start.set(Calendar.AM_PM, passedTime.get(Calendar.AM_PM));

        activityForm.setActivityStartDate(df.format(start.getTime()));
        activityForm.setActivityStartTime(tf.format(start.getTime()));
        // add an hour onto the start time for the default end time.
        Calendar end = new GregorianCalendar();
        end.setTime(start.getTime());
        end.add(Calendar.HOUR, 1);
        String endTimeString = tf.format(end.getTime());
        if (CVUtility.notEmpty(request.getParameter("ETIME"))) {
          endTimeString = request.getParameter("ETIME");
        }
        passedTime.setTime(tf.parse(endTimeString));
        end.set(Calendar.HOUR, passedTime.get(Calendar.HOUR));
        end.set(Calendar.MINUTE, passedTime.get(Calendar.MINUTE));
        end.set(Calendar.AM_PM, passedTime.get(Calendar.AM_PM));
        activityForm.setActivityEndDate(df.format(end.getTime()));
        activityForm.setActivityEndTime(tf.format(end.getTime()));
      } else if (unScheduleActivity != null && !(unScheduleActivity.equals("unSchedule"))) {
        // In the case the start time wasn't requested from the parent window,
        // set the start time to now() rounded up to the nearest hour, and the
        // end time to be the start time plus 1 hour.
        UserPrefererences userPref = userObject.getUserPref();
        String userTimeZoneId = userPref.getTimeZone();
        TimeZone userTimeZone = TimeZone.getTimeZone(userTimeZoneId);
        Calendar now = Calendar.getInstance(userTimeZone, locale);
        // round up the hour if we are at the 1 minute mark of the hour or
        // higher. just clear the second and millisecond fields, its only
        // scheduling not physics.
        now.clear(Calendar.SECOND);
        now.clear(Calendar.MILLISECOND);
        if (now.get(Calendar.MINUTE) > 0) {
          now.clear(Calendar.MINUTE);
          now.add(Calendar.HOUR, 1);
        }
        activityForm.setActivityStartDate(df.format(now.getTime()));
        activityForm.setActivityStartTime(tf.format(now.getTime()));
        // Increment now by 1 hour to get the end time.
        now.add(Calendar.HOUR, 1);
        activityForm.setActivityEndDate(df.format(now.getTime()));
        activityForm.setActivityEndTime(tf.format(now.getTime()));
      }

      String typeOfActivity = "";
      if (request.getParameter(ConstantKeys.TYPEOFACTIVITY) == null) {
        typeOfActivity = ConstantKeys.APPOINTMENT;
View Full Code Here

        break;
      case FieldDecoration.dateType: {
        // use the standard i18n way of formating these.
        // that means using the default formats based on locale.
        if (content != null) {
          DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, this.locale);
          if (content instanceof Timestamp) {
            timeStamp = (Timestamp) content;
            valueDate = new Date(timeStamp.getTime());
            valueString = df.format(valueDate);
          }
          if (content instanceof java.sql.Date) {
            java.sql.Date dateStamp = (java.sql.Date) content;
            valueString = df.format(dateStamp);
          }
          if (content instanceof Long) {
            Long dateObject = (Long) content;
            valueDate = new Date();
            valueDate.setTime(dateObject.longValue());
            valueString = df.format(valueDate);
          }
          decoratedField.append(valueString);
        }
        break;
      }
      case FieldDecoration.dateTimeType: {
        DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, this.locale);
        timeStamp = (Timestamp) content;
        if (timeStamp != null) {
          valueDate = new Date(timeStamp.getTime());
          valueString = df.format(valueDate);
        }
        decoratedField.append(valueString);
        break;
      }
      case FieldDecoration.timeType: {
        DateFormat df = DateFormat.getTimeInstance(DateFormat.MEDIUM, this.locale);
        if (content instanceof Timestamp) {
          timeStamp = (Timestamp) content;
          valueDate = new Date(timeStamp.getTime());
          if (timeStamp != null) {
            valueDate = new Date(timeStamp.getTime());
            valueString = df.format(valueDate);
          }
        }
        if (content instanceof Long) {
          Long dateObject = (Long) content;
          if (dateObject != null) {
            valueDate = new Date();
            valueDate.setTime(dateObject.longValue());
            valueString = df.format(dateObject);
          }
        }
        decoratedField.append(valueString);
        break;
      }
      case FieldDecoration.fileSizeType:
        // display the string to file Size
        // which in byte to GB,MB,KB
        float size = (new Float(content.toString())).floatValue();
        DecimalFormat df = new DecimalFormat("###.#");
        Integer s = new Integer((int) size);
        valueString = s.toString();
        if (size > 1000000000) {
          size /= 1073741824; // 1GB
          valueString = df.format(size) + "GB";
        } else if (size > 1000000) {
          size /= 1048576; // 1MB
          valueString = df.format(size) + "MB";
        } else if (size > 1000) {
          size /= 1024; // 1KB
          valueString = df.format(size) + "KB";
        }
        decoratedField.append(valueString);
        break;

      case FieldDecoration.moneyType:
View Full Code Here

    beanMapper = new DozerBeanMapper();
  }

  @Test
  public void dateFormat() {
    DateFormat instance = SimpleDateFormat.getInstance();
    GregorianCalendar calendar = new GregorianCalendar(1, 1, 1);
    instance.setCalendar(calendar);
    Container source = new Container();
    source.setDateFormat(instance);
    Container target = new Container();

    beanMapper.map(source, target);
View Full Code Here

  }

  @Test
  public void testStringToDateMapping() throws Exception {
    mapper = getMapper(new String[] { "dozerBeanMapping.xml" });
    DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss:SS");
    String dateStr = "01/29/1975 10:45:13:25";
    TestObject sourceObj = newInstance(TestObject.class);
    sourceObj.setDateStr(dateStr);
    TestObjectPrime result = mapper.map(sourceObj, TestObjectPrime.class);
    assertEquals(df.parse(dateStr), result.getDateFromStr());
    assertEquals(dateStr, df.format(result.getDateFromStr()));

    TestObject result2 = mapper.map(result, TestObject.class);
    assertEquals(df.format(result.getDateFromStr()), result2.getDateStr());
    assertEquals(result.getDateFromStr(), df.parse(result2.getDateStr()));
  }
View Full Code Here

     * @since 4.3
     */
    private Timestamp getTimestamp(String startts,
                                   int startnanos,
                                   String starttz) throws ParseException {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); //$NON-NLS-1$
        df.setTimeZone(TimeZone.getTimeZone(starttz));

        Timestamp ts = new Timestamp(df.parse(startts).getTime());
        ts.setNanos(startnanos);
        return ts;
    }
View Full Code Here

    Locale locale = request.getLocale();
    int individualID = userobjectd.getIndividualID();
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    // date format for writing to the form should be in the format based on
    // locale
    DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
    DateFormat tf = DateFormat.getTimeInstance(DateFormat.SHORT, locale);

    int activitytype = 0;

    int activityid = Integer.parseInt(requestForm.getActivityID());
    String result = "";

    // created session facade to call EJB methods (SyncFacade is a local class,
    // not an EJB!)
    SyncFacade syncfacade = new SyncFacade();
    syncfacade.setDataSource(dataSource);

    // if session is correct
    if (userobjectd.getSessionID().equals(sessionID)) {
      // A cheap way to check for NullPointerExceptions.
      try {
        ActivityForm activityForm = new ActivityForm();
        activityForm.setLocale(locale);
        activityForm.setActivityID(Integer.toString(activityid));

        String detailpriority = requestForm.getPriority();
        String detailstatus = requestForm.getStatus();

        if (detailstatus == null) {
          detailstatus = "1";
        }

        if (detailstatus != null && !detailstatus.equals("")) {
          if (detailstatus.equals("Pending")) {
            detailstatus = "1";
          } else if (detailstatus.equals("Completed")) {
            detailstatus = "2";
          }
        }

        String detailtitle = requestForm.getTitle();
        String detaildetail = requestForm.getDescription();

        // call to getting activity details
        ActivityVO vo = null;
        activitytype = syncfacade.getActivityType(activityid);
        vo = syncfacade.getActivity(activityid, individualID);

        ActivityGenericFillVOX agf = new ActivityGenericFillVOX();
        activityForm.setLocale(request.getLocale());
        agf.fillBasicForm(vo, activityForm);

        // if user wants to edit any field , that will not be null , so
        // that field is set to ActivityForm

        if (detailpriority != null) {
          activityForm.setActivityPriority(detailpriority);
        }

        if (detailstatus != null) {
          activityForm.setActivityStatus(detailstatus);
        }

        if (detailtitle != null) {
          activityForm.setActivityTitle(detailtitle);
        }

        if (detaildetail != null) {
          activityForm.setActivityDetail(detaildetail);
        }

        // startdate
        String activitystartdate = requestForm.getStartDateTime();
        Calendar start = new GregorianCalendar(tz, locale);
        if (activitystartdate != null) {
          try {
            Date dd = simpleDateFormat.parse(activitystartdate);
            start.setTime(dd);
          } catch (Exception e) {
            logger.error("[execute]: Exception", e);
          }
        }
        activityForm.setActivityStartDate(df.format(start.getTime()));
        activityForm.setActivityStartTime(tf.format(start.getTime()));

        String activityenddate = requestForm.getEndDateTime();
        Calendar end = new GregorianCalendar(tz, locale);
        if (activityenddate != null) {
          try {
            Date dd = simpleDateFormat.parse(activityenddate);
            end.setTime(dd);
          } catch (Exception e) {
            logger.error("[execute]: Exception", e);
          }
        }
        activityForm.setActivityEndDate(df.format(end.getTime()));
        activityForm.setActivityEndTime(tf.format(end.getTime()));

        // alarm date time
        String alarmDateTime = requestForm.getAlarmDateTime();
        Calendar remind = new GregorianCalendar(tz, locale);
        // if alarmDateTime is not null , so set it to ActivityForm
        if (alarmDateTime != null) {
          try {
            Date d = simpleDateFormat.parse(alarmDateTime);
            remind.setTime(d);
          } catch (Exception e) {
            logger.error("[execute]: Exception", e);
          }
        }
        activityForm.setActivityRemindDate(df.format(remind));
        activityForm.setActivityReminderTime(tf.format(remind));

        activityForm.setActivityType(String.valueOf(activitytype));

        result = syncfacade.updateActivity(activityForm, individualID);
View Full Code Here

    // the portlets
    // set up below.
    HashMap calendarMap = CalendarUtil.getCalendarCollection(startTime, endTime, tz, individualId,
        60, "", dataSource);
    // use default formatters for locale
    DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT, locale);
    DateFormat dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale);

    // email portlet
    MailHome home = (MailHome)CVUtility.getHomeObject("com.centraview.mail.MailHome", "Mail");
    Mail remote = home.create();
    remote.setDataSource(dataSource);
    ArrayList emailFolders = remote.getHomeFolderList(individualId);
    // this modifier gets stuck right in the html of the "Compose" button
    String emailButtonModifier = "";
    if ((emailFolders == null) || (emailFolders.size() < 1)) {
      emailButtonModifier = "disabled=\"true\"";
    }
    request.setAttribute("emailFolders", emailFolders);
    request.setAttribute("emailButtonModifier", emailButtonModifier);

    // calendar portlet

    // for every activity on the calendar list, create a display object, and
    // append it to the list. The list will be iterated and displayed on the JSP
    ArrayList calendarDisplayList = new ArrayList();
    CalendarList calendarList = (CalendarList)calendarMap.get("calendarlist");
    Set listkey = calendarList.keySet();
    Iterator it = listkey.iterator();
    while (it.hasNext()) {
      Integer key = (Integer)it.next();
      CalendarListElement ele = (CalendarListElement)calendarList.get(key);
      Set elekey = ele.keySet();
      Iterator eleit = elekey.iterator();
      while (eleit.hasNext()) {
        CalendarMember calmember = (CalendarMember)ele.get(eleit.next());
        CalendarActivityObject activity = calmember.getActivityobject();
        Calendar start = activity.getStartTime();
        start.setTimeZone(tz);
        Calendar end = activity.getEndTime();
        end.setTimeZone(tz);
        String timeRange = dateTimeFormat.format(start.getTime()) + " - "
            + dateTimeFormat.format(end.getTime());
        String activityStartTime = timeFormat.format(start.getTime());
        // type is that stored in the activitytype database table.
        String activityType = activity.getActivityType();
        String icon = this.determineActivityIcon(activityType);
        activityType = this.convertActivityType(activityType);
View Full Code Here

    private void readQuakes(BufferedReader rdr)
        throws IOException, ParseException {
       
        // process actual quake listing input file
        Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        format.setCalendar(calendar);
        String line;
        while ((line = rdr.readLine()) != null) {
           
            // parse the date and milliseconds
            int mark = line.indexOf(' ');
            mark = line.indexOf(' ', mark+1);
            Date date = format.parse(line.substring(0, mark));
            line = line.substring(mark+1).trim();
            mark = line.indexOf(' ');
            int millis = Integer.parseInt(line.substring(0, mark));
            line = line.substring(mark+1).trim();
           
View Full Code Here

    // date format for incoming dates: 2004-01-13 15:00:00
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    // date format for writing to the form should be in the format based on
    // locale
    DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
    DateFormat tf = DateFormat.getTimeInstance(DateFormat.SHORT, locale);

    ActivityAddHandler requestForm = (ActivityAddHandler)form;
    String sessionID = requestForm.getSessionID();

    // check sessionid is matching or not
    if (userobjectd.getSessionID().equals(sessionID)) {
      ActivityForm activityForm = new ActivityForm();
      activityForm.setLocale(locale);
      String priority = requestForm.getPriority();

      // this is the string that we'll pass to the activityform
      // set to 2 (medium) by default
      String detailpriority = "2";

      if (priority != null) {
        // set the String integer value based on the String string value
        // (confused yet?)
        if (priority.equals("High")) {
          detailpriority = "1";
        } else if (priority.equals("Low")) {
          detailpriority = "3";
        }
      }

      String detailstatus = requestForm.getStatus();

      if (detailstatus == null) {
        detailstatus = "1";
      }

      if (detailstatus != null && !detailstatus.equals("")) {
        if (detailstatus.equals("Pending")) {
          detailstatus = "1";
        } else if (detailstatus.equals("Completed")) {
          detailstatus = "2";
        }
      }

      String detailtitle = requestForm.getTitle();
      String detaildetail = requestForm.getDescription();

      // startdate
      Calendar start = new GregorianCalendar(tz, locale);
      String activityStartDate = requestForm.getStartDateTime();
      if (activityStartDate != null && (!activityStartDate.equals(""))) {
        try {
          Date dd = simpleDateFormat.parse(activityStartDate);
          start.setTime(dd);
        } catch (Exception e) {
          logger.error("[execute]: Exception", e);
        }
      }
      activityForm.setActivityStartDate(df.format(start.getTime()));
      activityForm.setActivityStartTime(tf.format(start.getTime()));

      // enddate
      Calendar end = new GregorianCalendar(tz, locale);
      String activityenddate = requestForm.getEndDateTime();
      if (activityenddate != null && (!activityenddate.equals(""))) {
        try {
          Date dd = simpleDateFormat.parse(activityenddate);
          end.setTime(dd);
        } catch (Exception e) {
          logger.error("[execute]: Exception", e);
        }
      }
      activityForm.setActivityEndDate(df.format(end.getTime()));
      activityForm.setActivityEndTime(tf.format(end.getTime()));

      activityForm.setActivityPriority(detailpriority);
      activityForm.setActivityStatus(detailstatus);
      activityForm.setActivityTitle(detailtitle);
      activityForm.setActivityDetail(detaildetail);
View Full Code Here

TOP

Related Classes of java.text.DateFormat

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.