ICU 50.1.2  50.1.2
dtitvfmt.h
Go to the documentation of this file.
1 /********************************************************************************
2 * Copyright (C) 2008-2012, International Business Machines Corporation and
3 * others. All Rights Reserved.
4 *******************************************************************************
5 *
6 * File DTITVFMT.H
7 *
8 *******************************************************************************
9 */
10 
11 #ifndef __DTITVFMT_H__
12 #define __DTITVFMT_H__
13 
14 
15 #include "unicode/utypes.h"
16 
22 #if !UCONFIG_NO_FORMATTING
23 
24 #include "unicode/ucal.h"
25 #include "unicode/smpdtfmt.h"
26 #include "unicode/dtintrv.h"
27 #include "unicode/dtitvinf.h"
28 #include "unicode/dtptngen.h"
29 
31 
32 
33 
219 public:
220 
234  static DateIntervalFormat* U_EXPORT2 createInstance(
235  const UnicodeString& skeleton,
236  UErrorCode& status);
237 
267  static DateIntervalFormat* U_EXPORT2 createInstance(
268  const UnicodeString& skeleton,
269  const Locale& locale,
270  UErrorCode& status);
271 
287  static DateIntervalFormat* U_EXPORT2 createInstance(
288  const UnicodeString& skeleton,
289  const DateIntervalInfo& dtitvinf,
290  UErrorCode& status);
291 
327  static DateIntervalFormat* U_EXPORT2 createInstance(
328  const UnicodeString& skeleton,
329  const Locale& locale,
330  const DateIntervalInfo& dtitvinf,
331  UErrorCode& status);
332 
337  virtual ~DateIntervalFormat();
338 
345  virtual Format* clone(void) const;
346 
354  virtual UBool operator==(const Format& other) const;
355 
363  UBool operator!=(const Format& other) const;
364 
365 
366  using Format::format;
367 
384  virtual UnicodeString& format(const Formattable& obj,
385  UnicodeString& appendTo,
386  FieldPosition& fieldPosition,
387  UErrorCode& status) const ;
388 
389 
390 
403  UnicodeString& format(const DateInterval* dtInterval,
404  UnicodeString& appendTo,
405  FieldPosition& fieldPosition,
406  UErrorCode& status) const ;
407 
408 
429  UnicodeString& format(Calendar& fromCalendar,
430  Calendar& toCalendar,
431  UnicodeString& appendTo,
432  FieldPosition& fieldPosition,
433  UErrorCode& status) const ;
434 
461  virtual void parseObject(const UnicodeString& source,
462  Formattable& result,
463  ParsePosition& parse_pos) const;
464 
465 
472  const DateIntervalInfo* getDateIntervalInfo(void) const;
473 
474 
481  void setDateIntervalInfo(const DateIntervalInfo& newIntervalPatterns,
482  UErrorCode& status);
483 
484 
490  const DateFormat* getDateFormat(void) const;
491 
497  virtual const TimeZone& getTimeZone(void) const;
498 
505  virtual void adoptTimeZone(TimeZone* zoneToAdopt);
506 
512  virtual void setTimeZone(const TimeZone& zone);
513 
525  static UClassID U_EXPORT2 getStaticClassID(void);
526 
538  virtual UClassID getDynamicClassID(void) const;
539 
540 protected:
541 
547 
553 
554 private:
555 
556  /*
557  * This is for ICU internal use only. Please do not use.
558  * Save the interval pattern information.
559  * Interval pattern consists of 2 single date patterns and the separator.
560  * For example, interval pattern "MMM d - MMM d, yyyy" consists
561  * a single date pattern "MMM d", another single date pattern "MMM d, yyyy",
562  * and a separator "-".
563  * The pattern is divided into 2 parts. For above example,
564  * the first part is "MMM d - ", and the second part is "MMM d, yyyy".
565  * Also, the first date appears in an interval pattern could be
566  * the earlier date or the later date.
567  * And such information is saved in the interval pattern as well.
568  * @internal ICU 4.0
569  */
570  struct PatternInfo {
571  UnicodeString firstPart;
572  UnicodeString secondPart;
586  UBool laterDateFirst;
587  };
588 
589 
595 
615  DateIntervalFormat(const Locale& locale, DateIntervalInfo* dtItvInfo,
616  const UnicodeString* skeleton, UErrorCode& status);
617 
618 
632  static DateIntervalFormat* U_EXPORT2 create(const Locale& locale,
633  DateIntervalInfo* dtitvinf,
634  const UnicodeString* skeleton,
635  UErrorCode& status);
636 
650  static SimpleDateFormat* U_EXPORT2 createSDFPatternInstance(
651  const UnicodeString& skeleton,
652  const Locale& locale,
654  UErrorCode& status);
655 
656 
680  UnicodeString& fallbackFormat(Calendar& fromCalendar,
681  Calendar& toCalendar,
682  UnicodeString& appendTo,
683  FieldPosition& pos,
684  UErrorCode& status) const;
685 
686 
687 
723  void initializePattern(UErrorCode& status);
724 
725 
726 
735  void setFallbackPattern(UCalendarDateFields field,
736  const UnicodeString& skeleton,
737  UErrorCode& status);
738 
739 
740 
766  static void U_EXPORT2 getDateTimeSkeleton(const UnicodeString& skeleton,
767  UnicodeString& date,
768  UnicodeString& normalizedDate,
769  UnicodeString& time,
770  UnicodeString& normalizedTime);
771 
772 
773 
798  UBool setSeparateDateTimePtn(const UnicodeString& dateSkeleton,
799  const UnicodeString& timeSkeleton);
800 
801 
802 
803 
828  UBool setIntervalPattern(UCalendarDateFields field,
829  const UnicodeString* skeleton,
830  const UnicodeString* bestSkeleton,
831  int8_t differenceInfo,
832  UnicodeString* extendedSkeleton = NULL,
833  UnicodeString* extendedBestSkeleton = NULL);
834 
864  static void U_EXPORT2 adjustFieldWidth(
865  const UnicodeString& inputSkeleton,
866  const UnicodeString& bestMatchSkeleton,
867  const UnicodeString& bestMatchIntervalPattern,
868  int8_t differenceInfo,
869  UnicodeString& adjustedIntervalPattern);
870 
884  void concatSingleDate2TimeInterval(const UChar* format,
885  int32_t formatLen,
886  const UnicodeString& datePattern,
887  UCalendarDateFields field,
888  UErrorCode& status);
889 
897  static UBool U_EXPORT2 fieldExistsInSkeleton(UCalendarDateFields field,
898  const UnicodeString& skeleton);
899 
900 
907  static int32_t U_EXPORT2 splitPatternInto2Part(const UnicodeString& intervalPattern);
908 
909 
916  void setIntervalPattern(UCalendarDateFields field,
917  const UnicodeString& intervalPattern);
918 
919 
927  void setIntervalPattern(UCalendarDateFields field,
928  const UnicodeString& intervalPattern,
929  UBool laterDateFirst);
930 
931 
942  void setPatternInfo(UCalendarDateFields field,
943  const UnicodeString* firstPart,
944  const UnicodeString* secondPart,
945  UBool laterDateFirst);
946 
947 
948  // from calendar field to pattern letter
949  static const UChar fgCalendarFieldToPatternLetter[];
950 
951 
955  DateIntervalInfo* fInfo;
956 
960  SimpleDateFormat* fDateFormat;
961 
967  Calendar* fFromCalendar;
968  Calendar* fToCalendar;
969 
973  DateTimePatternGenerator* fDtpng;
974 
978  UnicodeString fSkeleton;
979  PatternInfo fIntervalPatterns[DateIntervalInfo::kIPI_MAX_INDEX];
980 };
981 
982 inline UBool
984  return !operator==(other);
985 }
986 
988 
989 #endif /* #if !UCONFIG_NO_FORMATTING */
990 
991 #endif // _DTITVFMT_H__
992 //eof
Base class for all formats.
Definition: format.h:94
UCalendarDateFields
Possible fields in a UCalendar.
Definition: ucal.h:183
DateIntervalFormat is a class for formatting and parsing date intervals in a language-independent man...
Definition: dtitvfmt.h:218
C API: Calendar.
C++ API: Date/Time Pattern Generator.
DateIntervalInfo is a public class for encapsulating localizable date time interval patterns...
Definition: dtitvinf.h:151
Calendar is an abstract base class for converting between a UDate object and a set of integer fields ...
Definition: calendar.h:200
This class provides flexible generation of date format patterns, like "yy-MM-dd". ...
Definition: dtptngen.h:49
virtual UClassID getDynamicClassID() const =0
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
virtual Format * clone() const =0
Clone this object polymorphically.
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:129
This class represents a date interval.
Definition: dtintrv.h:32
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:358
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
C++ API: Format and parse dates in a language-independent manner.
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:218
#define NULL
Define NULL if necessary, to 0 for C++ and to ((void *)0) for C.
Definition: utypes.h:186
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
uint16_t UChar
Define UChar to be UCHAR_TYPE, if that is #defined (for example, to char16_t), or wchar_t if that is ...
Definition: umachine.h:278
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
C++ API: Date Interval data type.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:476
SimpleDateFormat is a concrete class for formatting and parsing dates in a language-independent manne...
Definition: smpdtfmt.h:227
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:106
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:47
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition: datefmt.h:138
virtual UBool operator==(const Format &other) const =0
Return true if the given Format objects are semantically equal.
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const =0
Parse a string to produce an object.
Basic definitions for ICU, for both C and C++ APIs.
C++ API: Date/Time interval patterns for formatting date/time interval.
Format & operator=(const Format &)
UBool operator!=(const Format &other) const
Return true if the given Format objects are not semantically equal.
Definition: format.h:119
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:246
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:62
int8_t UBool
The ICU boolean type.
Definition: umachine.h:200
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:182