Exemplo n.º 1
0
  /**
   * Constructor for ATimeStampFmt.
   *
   * @param styleDate one of SHORT, MEDIUM, LONG, FULL or the IFmt-styles
   * @param styleTime one of SHORT, MEDIUM, LONG, FULL or the IFmt-styles
   * @param l the locale
   */
  public ATimeStampFmt(int styleDate, int styleTime, Locale l) {
    if ((styleDate & MANDATORY) != 0 || (styleTime & MANDATORY) != 0) setMandatory(true);

    int javaDateStyle = DateFormat.MEDIUM;
    int javaTimeStyle = DateFormat.MEDIUM;

    if ((styleDate & SHORT) != 0) javaDateStyle = DateFormat.SHORT;
    else if ((styleDate & LONG) != 0) javaDateStyle = DateFormat.LONG;
    else if ((styleDate & FULL) != 0) javaDateStyle = DateFormat.FULL;

    if ((styleTime & SHORT) != 0) javaTimeStyle = DateFormat.SHORT;
    else if ((styleTime & LONG) != 0) javaTimeStyle = DateFormat.LONG;
    else if ((styleTime & FULL) != 0) javaTimeStyle = DateFormat.FULL;

    dateFormat_ = DateFormat.getDateTimeInstance(javaDateStyle, javaTimeStyle, l);
    dateFormat_.setLenient(false);
  }
Exemplo n.º 2
0
 /** Does the parse-work without the mandatory-check */
 private String parse2(String external) throws FmtParseException {
   // trim blanks on both sides
   if (external == null) return "";
   external = external.trim();
   if (external.length() == 0) return "";
   else {
     ParsePosition pp = new ParsePosition(0);
     Date date = null;
     date = dateFormat_.parse(external, pp);
     if (date == null || (pp.getIndex() != external.length() && pp.getIndex() > 0)) {
       throw new FmtParseException("ATSSyntax", getSampleTS());
     }
     return TimeStampUtil.date2Internal(date);
   }
 }
Exemplo n.º 3
0
 /** @see at.spardat.enterprise.fmt.IFmt#clone() */
 public Object clone() {
   Object toReturn = super.clone();
   ((ATimeStampFmt) toReturn).dateFormat_ = (DateFormat) dateFormat_.clone();
   return toReturn;
 }
Exemplo n.º 4
0
 /** @see at.spardat.enterprise.fmt.IFmt#format(String) */
 public String format(String internal) {
   if (internal == null || internal.length() == 0) return "";
   return dateFormat_.format(TimeStampUtil.internal2Date(internal));
 }
Exemplo n.º 5
0
 // returns a timestamp template
 private String getSampleTS() {
   return dateFormat_.format(new Date());
 }
Exemplo n.º 6
0
 /**
  * Constructs a ATimeStampFmt using a <tt>java.text.SimpleDateFormat</tt> pattern.
  *
  * @param pattern a pattern as defined in <tt>java.text.SimpleDateFormat</tt>.
  * @param l Locale
  * @param style may be MANDATORY
  */
 public ATimeStampFmt(String pattern, Locale l, int style) {
   style_ = style;
   dateFormat_ = new SimpleDateFormat(pattern, l);
   dateFormat_.setLenient(false);
 }