/** * 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); }
/** 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); } }
/** @see at.spardat.enterprise.fmt.IFmt#clone() */ public Object clone() { Object toReturn = super.clone(); ((ATimeStampFmt) toReturn).dateFormat_ = (DateFormat) dateFormat_.clone(); return toReturn; }
/** @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)); }
// returns a timestamp template private String getSampleTS() { return dateFormat_.format(new Date()); }
/** * 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); }