Logo Search packages:      
Sourcecode: icu version File versions

UnicodeString & DateFormat::format ( const Formattable obj,
UnicodeString toAppendTo,
FieldPosition pos,
UErrorCode status 
) const [virtual]

Format an object to produce a string. This method handles Formattable objects with a UDate type. If a the Formattable object type is not a Date, then it returns a failing UErrorCode.

Parameters:
obj The object to format. Must be a Date.
toAppendTo The result of the formatting operation is appended to this string.
pos On input: an alignment field, if desired. On output: the offsets of the alignment field.
status Output param filled with success/failure status.
Returns:
The value passed in as toAppendTo (this allows chaining, as with UnicodeString::append())

Implements Format.

Reimplemented in SimpleDateFormat.

Definition at line 90 of file datefmt.cpp.

References Formattable::getDate(), Formattable::getDouble(), Formattable::getLong(), Formattable::getType(), U_FAILURE, and U_ILLEGAL_ARGUMENT_ERROR.

Referenced by SimpleDateFormat::format(), MessageFormat::format(), format(), DateFormatRegressionTest::Test4052408(), DateFormatRegressionTest::Test4060212(), DateFormatRegressionTest::Test4065240(), DateFormatRegressionTest::Test4073003(), DateFormatRegressionTest::Test4106807(), CalendarRegressionTest::test4125881(), CalendarRegressionTest::Test4167060(), CalendarRegressionTest::Test4197699(), DateFormatRegressionTest::Test4210209(), DateFormatTest::TestBadInput135(), DateFormatTest::TestDateFormatZone061(), DateFormatTest::TestDateFormatZone146(), NumberFormatRegressionTest::TestJ691(), DateFormatTest::TestLocaleDateFormat(), and IntlTestDateFormat::tryDate().

{
    if (U_FAILURE(status)) return toAppendTo;

    // if the type of the Formattable is double or long, treat it as if it were a Date
    switch (obj.getType())
    {
    case Formattable::kDate:
        format(obj.getDate(), toAppendTo, fieldPosition);
        break;
    case Formattable::kDouble:
        format((UDate)obj.getDouble(), toAppendTo, fieldPosition);
        break;
    case Formattable::kLong:
        format((UDate)obj.getLong(), toAppendTo, fieldPosition);
        break;
    default:
        status = U_ILLEGAL_ARGUMENT_ERROR;
        return toAppendTo;
    }

    // Is this right?
    //if (fieldPosition.getBeginIndex() == fieldPosition.getEndIndex())
    //  status = U_ILLEGAL_ARGUMENT_ERROR;

    return toAppendTo;
}


Generated by  Doxygen 1.6.0   Back to index