private SimpleDateFormat(Locale locale) { numberFormat = NumberFormat.GetInstance(locale); numberFormat.SetParseIntegerOnly(true); numberFormat.SetGroupingUsed(false); calendar = new IBM.ICU.Util.GregorianCalendar(locale); calendar.Add(ILOG.J2CsMapping.Util.Calendar.YEAR, -80); creationYear = calendar.Get(ILOG.J2CsMapping.Util.Calendar.YEAR); defaultCenturyStart = calendar.GetTime(); }
/// <summary> /// Compares the specified object to this NumberFormat and answer if they are /// equal. The object must be an instance of NumberFormat and have the same /// properties. /// </summary> /// /// <param name="object">the object to compare with this object</param> /// <returns>true if the specified object is equal to this NumberFormat, false /// otherwise</returns> /// <seealso cref="M:ILOG.J2CsMapping.Text.NumberFormat.HashCode"/> public override bool Equals(Object obj0) { if (obj0 == (Object)this) { return(true); } if (!(obj0 is NumberFormat)) { return(false); } NumberFormat obj = (NumberFormat)obj0; return(groupingUsed == obj.groupingUsed && parseIntegerOnly == obj.parseIntegerOnly && maximumFractionDigits == obj.maximumFractionDigits && maximumIntegerDigits == obj.maximumIntegerDigits && minimumFractionDigits == obj.minimumFractionDigits && minimumIntegerDigits == obj.minimumIntegerDigits); }
private Format ParseVariable(String str0, ParsePosition position) { int length = str0.Length, offset = position.GetIndex(); char ch; if (offset >= length || ((ch = str0[offset++]) != '}' && ch != ',')) { // text.15=Missing element format throw new ArgumentException("text.15"); //$NON-NLS-1$ } position.SetIndex(offset); if (ch == '}') { return(null); } int type = Match(str0, position, false, new String[] { "time", //$NON-NLS-1$ "date", "number", "choice" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ if (type == -1) { // text.16=Unknown element format throw new ArgumentException("text.16"); //$NON-NLS-1$ } StringBuilder buffer = new StringBuilder(); ch = str0[position.GetIndex() - 1]; switch (type) { case 0: // time case 1: // date if (ch == '}') { return((type == 1) ? DateFormat.GetDateInstance( DateFormat.DEFAULT, locale) : DateFormat .GetTimeInstance(DateFormat.DEFAULT, locale)); } int dateStyle = Match(str0, position, true, new String[] { "full", "long", "medium", "short" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ if (dateStyle == -1) { ILOG.J2CsMapping.Formatting.Format.UpToWithQuotes(str0, position, buffer, '}', '{'); return(new SimpleDateFormat(buffer.ToString(), locale)); } switch (dateStyle) { case 0: dateStyle = DateFormat.FULL; break; case 1: dateStyle = DateFormat.LONG; break; case 2: dateStyle = DateFormat.MEDIUM; break; case 3: dateStyle = DateFormat.SHORT; break; } return((type == 1) ? DateFormat.GetDateInstance(dateStyle, locale) : DateFormat.GetTimeInstance(dateStyle, locale)); case 2: // number if (ch == '}') { return(NumberFormat.GetInstance()); } int numberStyle = Match(str0, position, true, new String[] { "currency", "percent", "integer" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ if (numberStyle == -1) { ILOG.J2CsMapping.Formatting.Format.UpToWithQuotes(str0, position, buffer, '}', '{'); return(new DecimalFormat(buffer.ToString(), new DecimalFormatSymbols(locale))); } switch (numberStyle) { case 0: // currency return(NumberFormat.GetCurrencyInstance(locale)); case 1: // percent return(NumberFormat.GetPercentInstance(locale)); } return(NumberFormat.GetIntegerInstance(locale)); } // choice try { ILOG.J2CsMapping.Formatting.Format.UpToWithQuotes(str0, position, buffer, '}', '{'); } catch (ArgumentException e) { // ignored } return(new ChoiceFormat(buffer.ToString())); }
private StringBuilder FormatImpl(Object[] objects, StringBuilder buffer, FieldPosition position, List <FieldContainer> fields) { FieldPosition passedField = new FieldPosition(0); for (int i = 0; i <= maxOffset; i++) { buffer.Append(strings[i]); int begin = buffer.Length; Object arg; if (objects != null && argumentNumbers[i] < objects.Length) { arg = objects[argumentNumbers[i]]; } else { buffer.Append('{'); buffer.Append(argumentNumbers[i]); buffer.Append('}'); HandleArgumentField(begin, buffer.Length, argumentNumbers[i], position, fields); continue; } Format format = formats[i]; if (format == null || arg == null) { if (arg is object) { format = NumberFormat.GetInstance(); } else if (arg is DateTime) { format = DateFormat.GetInstance(); } else { buffer.Append(arg); HandleArgumentField(begin, buffer.Length, argumentNumbers[i], position, fields); continue; } } if (format is ChoiceFormat) { String result = format.FormatObject(arg); MessageFormat mf = new MessageFormat(result); mf.SetLocale(locale); mf.Format(objects, buffer, passedField); HandleArgumentField(begin, buffer.Length, argumentNumbers[i], position, fields); Handleformat(format, arg, begin, fields); } else { format.FormatObject(arg, buffer, passedField); HandleArgumentField(begin, buffer.Length, argumentNumbers[i], position, fields); Handleformat(format, arg, begin, fields); } } if (maxOffset + 1 < strings.Length) { buffer.Append(strings[maxOffset + 1]); } return(buffer); }
/// <summary> /// Sets the NumberFormat used by this DateFormat. /// </summary> /// /// <param name="format">the NumberFormat</param> public void SetNumberFormat(NumberFormat format) { numberFormat = format; }