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.

Parameters:
obj The object to format. Must be a Date.
appendTo Output parameter to receive result. Result is appended to existing contents.
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:
Reference to 'appendTo' parameter. ICU 2.0

Implements Format.

Reimplemented in RelativeDateFormat, and SimpleDateFormat.

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 SimpleDateFormat::format(), RelativeDateFormat::format(), format(), DateFormatRegressionTest::Test4052408(), DateFormatRegressionTest::Test4060212(), DateFormatRegressionTest::Test4065240(), DateFormatRegressionTest::Test4106807(), CalendarRegressionTest::test4125881(), CalendarRegressionTest::Test4167060(), TimeZoneRegressionTest::Test4176686(), CalendarRegressionTest::Test4197699(), DateFormatRegressionTest::Test4210209(), DateFormatTest::TestBadInput135(), DateFormatTest::TestDateFormatZone061(), DateFormatTest::TestDateFormatZone146(), DateFormatTest::TestFieldPosition(), NumberFormatRegressionTest::TestJ691(), DateFormatTest::TestLocaleDateFormat(), 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();
        break;
    case Formattable::kDouble:
        date = (UDate)obj.getDouble();
        break;
    case Formattable::kLong:
        date = (UDate)obj.getLong();
        break;
    default:
        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);
}


Generated by  Doxygen 1.6.0   Back to index