/*
*******************************************************************************
- * Copyright (C) 1997-2008, International Business Machines Corporation and *
+ * Copyright (C) 1997-2010, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
//----------------------------------------------------------------------
+UnicodeString&
+DateFormat::format(const Formattable& obj,
+ UnicodeString& appendTo,
+ FieldPositionIterator* posIter,
+ UErrorCode& status) const
+{
+ 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, posIter, status);
+}
+
+//----------------------------------------------------------------------
+
+// Default implementation for backwards compatibility, subclasses should implement.
+UnicodeString&
+DateFormat::format(Calendar& /* unused cal */,
+ UnicodeString& appendTo,
+ FieldPositionIterator* /* unused posIter */,
+ UErrorCode& status) const {
+ if (U_SUCCESS(status)) {
+ status = U_UNSUPPORTED_ERROR;
+ }
+ return appendTo;
+}
+
+//----------------------------------------------------------------------
+
UnicodeString&
DateFormat::format(UDate date, UnicodeString& appendTo, FieldPosition& fieldPosition) const {
if (fCalendar != NULL) {
//----------------------------------------------------------------------
+UnicodeString&
+DateFormat::format(UDate date, UnicodeString& appendTo, FieldPositionIterator* posIter,
+ UErrorCode& status) const {
+ if (fCalendar != NULL) {
+ fCalendar->setTime(date, status);
+ if (U_SUCCESS(status)) {
+ return format(*fCalendar, appendTo, posIter, status);
+ }
+ }
+ return appendTo;
+}
+
+//----------------------------------------------------------------------
+
UnicodeString&
DateFormat::format(UDate date, UnicodeString& appendTo) const
{
return create(kShort, (EStyle) (kShort + kDateOffset), Locale::getDefault());
}
-//----------------------------------------------------------------------
-DateFormat* U_EXPORT2
-DateFormat::createPatternInstance(const UnicodeString& skeleton,
- const Locale& locale,
- UErrorCode& status)
-{
- if ( U_FAILURE(status) ) {
- return NULL;
- }
-
- DateTimePatternGenerator* dtptg =
- DateTimePatternGenerator::createInstance(locale, status);
- if ( dtptg == NULL ) {
- status = U_MEMORY_ALLOCATION_ERROR;
- delete dtptg;
- return NULL;
- }
- if ( U_FAILURE(status) ) {
- delete dtptg;
- return NULL;
- }
-
- const UnicodeString pattern = dtptg->getBestPattern(skeleton, status);
- delete dtptg;
- if ( U_FAILURE(status) ) {
- return NULL;
- }
- SimpleDateFormat* dtfmt = new SimpleDateFormat(pattern, locale, status);
- if ( U_FAILURE(status) ) {
- delete dtfmt;
- return NULL;
- }
- return dtfmt;
-}
-
//----------------------------------------------------------------------
DateFormat* U_EXPORT2