Logo Search packages:      
Sourcecode: icu version File versions  Download package

UnicodeString & DateFormat::format ( const Formattable obj,
UnicodeString appendTo,
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.

objThe object to format. Must be a Date.
appendToOutput parameter to receive result. Result is appended to existing contents.
posOn input: an alignment field, if desired. On output: the offsets of the alignment field.
statusOutput param filled with success/failure status.
Reference to 'appendTo' parameter. ICU 2.0

Implements Format.

Reimplemented in SimpleDateFormat, and RelativeDateFormat.

Definition at line 110 of file datefmt.cpp.

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

Referenced by DateFmtFunction::call(), RelativeDateFormat::format(), format(), DateFormatRegressionTest::Test4052408(), DateFormatRegressionTest::Test4060212(), DateFormatRegressionTest::Test4065240(), DateFormatRegressionTest::Test4106807(), CalendarRegressionTest::test4125881(), CalendarRegressionTest::Test4167060(), TimeZoneRegressionTest::Test4176686(), CalendarRegressionTest::Test4197699(), DateFormatRegressionTest::Test4210209(), IntlTestDateFormatAPI::testAPI(), DateFormatTest::TestBadInput135(), DateFormatTest::TestDateFormatZone061(), DateFormatTest::TestDateFormatZone146(), DateFormatTest::TestFieldPosition(), NumberFormatRegressionTest::TestJ691(), DateFormatTest::TestLocaleDateFormat(), IntlTestDateFormatAPI::TestNameHiding(), and IntlTestDateFormat::tryDate().

    if (U_FAILURE(status)) return appendTo;

    // if the type of the Formattable is double or long, treat it as if it were a Date
    UDate date = 0;
    switch (obj.getType())
    case Formattable::kDate:
        date = obj.getDate();
    case Formattable::kDouble:
        date = (UDate)obj.getDouble();
    case Formattable::kLong:
        date = (UDate)obj.getLong();
        status = U_ILLEGAL_ARGUMENT_ERROR;
        return appendTo;

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

    return format(date, appendTo, fieldPosition);

Here is the call graph for this function:

Here is the caller graph for this function:

Generated by  Doxygen 1.6.0   Back to index