ICU 55.1  55.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
datefmt.h
Go to the documentation of this file.
1 /*
2  ********************************************************************************
3  * Copyright (C) 1997-2015, International Business Machines
4  * Corporation and others. All Rights Reserved.
5  ********************************************************************************
6  *
7  * File DATEFMT.H
8  *
9  * Modification History:
10  *
11  * Date Name Description
12  * 02/19/97 aliu Converted from java.
13  * 04/01/97 aliu Added support for centuries.
14  * 07/23/98 stephen JDK 1.2 sync
15  * 11/15/99 weiv Added support for week of year/day of week formatting
16  ********************************************************************************
17  */
18 
19 #ifndef DATEFMT_H
20 #define DATEFMT_H
21 
22 #include "unicode/utypes.h"
23 
24 #if !UCONFIG_NO_FORMATTING
25 
26 #include "unicode/udat.h"
27 #include "unicode/calendar.h"
28 #include "unicode/numfmt.h"
29 #include "unicode/format.h"
30 #include "unicode/locid.h"
31 #include "unicode/enumset.h"
33 
40 
41 class TimeZone;
42 class DateTimePatternGenerator;
43 
44 // explicit template instantiation. see digitlst.h
45 #if defined (_MSC_VER)
46 template class U_I18N_API EnumSet<UDateFormatBooleanAttribute,
47  0,
49 #endif
50 
147 class U_I18N_API DateFormat : public Format {
148 public:
149 
157  enum EStyle
158  {
159  kNone = -1,
160 
161  kFull = 0,
162  kLong = 1,
163  kMedium = 2,
164  kShort = 3,
165 
166  kDateOffset = kShort + 1,
167  // kFull + kDateOffset = 4
168  // kLong + kDateOffset = 5
169  // kMedium + kDateOffset = 6
170  // kShort + kDateOffset = 7
171 
172  kDateTime = 8,
173  // Default DateTime
174 
175  kDateTimeOffset = kDateTime + 1,
176  // kFull + kDateTimeOffset = 9
177  // kLong + kDateTimeOffset = 10
178  // kMedium + kDateTimeOffset = 11
179  // kShort + kDateTimeOffset = 12
180 
181  // relative dates
182  kRelative = (1 << 7),
183 
184  kFullRelative = (kFull | kRelative),
185 
186  kLongRelative = kLong | kRelative,
187 
188  kMediumRelative = kMedium | kRelative,
189 
190  kShortRelative = kShort | kRelative,
191 
192 
193  kDefault = kMedium,
194 
195 
196 
201  FULL = kFull,
202  LONG = kLong,
203  MEDIUM = kMedium,
204  SHORT = kShort,
205  DEFAULT = kDefault,
206  DATE_OFFSET = kDateOffset,
207  NONE = kNone,
208  DATE_TIME = kDateTime
209  };
210 
215  virtual ~DateFormat();
216 
221  virtual UBool operator==(const Format&) const;
222 
223 
224  using Format::format;
225 
240  virtual UnicodeString& format(const Formattable& obj,
241  UnicodeString& appendTo,
242  FieldPosition& pos,
243  UErrorCode& status) const;
244 
260  virtual UnicodeString& format(const Formattable& obj,
261  UnicodeString& appendTo,
262  FieldPositionIterator* posIter,
263  UErrorCode& status) const;
297  virtual UnicodeString& format( Calendar& cal,
298  UnicodeString& appendTo,
299  FieldPosition& fieldPosition) const = 0;
300 
319  virtual UnicodeString& format(Calendar& cal,
320  UnicodeString& appendTo,
321  FieldPositionIterator* posIter,
322  UErrorCode& status) const;
350  UnicodeString& format( UDate date,
351  UnicodeString& appendTo,
352  FieldPosition& fieldPosition) const;
353 
367  UnicodeString& format(UDate date,
368  UnicodeString& appendTo,
369  FieldPositionIterator* posIter,
370  UErrorCode& status) const;
382  UnicodeString& format(UDate date, UnicodeString& appendTo) const;
383 
418  virtual UDate parse( const UnicodeString& text,
419  UErrorCode& status) const;
420 
447  virtual void parse( const UnicodeString& text,
448  Calendar& cal,
449  ParsePosition& pos) const = 0;
450 
481  UDate parse( const UnicodeString& text,
482  ParsePosition& pos) const;
483 
507  virtual void parseObject(const UnicodeString& source,
508  Formattable& result,
509  ParsePosition& parse_pos) const;
510 
518  static DateFormat* U_EXPORT2 createInstance(void);
519 
531  static DateFormat* U_EXPORT2 createTimeInstance(EStyle style = kDefault,
532  const Locale& aLocale = Locale::getDefault());
533 
549  static DateFormat* U_EXPORT2 createDateInstance(EStyle style = kDefault,
550  const Locale& aLocale = Locale::getDefault());
551 
570  static DateFormat* U_EXPORT2 createDateTimeInstance(EStyle dateStyle = kDefault,
571  EStyle timeStyle = kDefault,
572  const Locale& aLocale = Locale::getDefault());
573 
574 #ifndef U_HIDE_DRAFT_API
575 
589  static DateFormat* U_EXPORT2 createInstanceForSkeleton(
590  const UnicodeString& skeleton,
591  UErrorCode &status);
592 
606  static DateFormat* U_EXPORT2 createInstanceForSkeleton(
607  const UnicodeString& skeleton,
608  const Locale &locale,
609  UErrorCode &status);
610 
625  static DateFormat* U_EXPORT2 createInstanceForSkeleton(
626  Calendar *calendarToAdopt,
627  const UnicodeString& skeleton,
628  const Locale &locale,
629  UErrorCode &status);
630 
631 #endif /* U_HIDE_DRAFT_API */
632 
633 #ifndef U_HIDE_INTERNAL_API
634 
660  static DateFormat* U_EXPORT2 internalCreateInstanceForSkeleton(
661  const UnicodeString& skeleton,
662  const Locale &locale,
664  UErrorCode &status);
665 
666 #endif /* U_HIDE_INTERNAL_API */
667 
675  static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
676 
682  virtual UBool isLenient(void) const;
683 
704  virtual void setLenient(UBool lenient);
705 
706 
711  virtual UBool isCalendarLenient(void) const;
712 
713 
723  virtual void setCalendarLenient(UBool lenient);
724 
725 
734  virtual const Calendar* getCalendar(void) const;
735 
745  virtual void adoptCalendar(Calendar* calendarToAdopt);
746 
754  virtual void setCalendar(const Calendar& newCalendar);
755 
756 
763  virtual const NumberFormat* getNumberFormat(void) const;
764 
771  virtual void adoptNumberFormat(NumberFormat* formatToAdopt);
772 
778  virtual void setNumberFormat(const NumberFormat& newNumberFormat);
779 
785  virtual const TimeZone& getTimeZone(void) const;
786 
793  virtual void adoptTimeZone(TimeZone* zoneToAdopt);
794 
800  virtual void setTimeZone(const TimeZone& zone);
801 
811  virtual void setContext(UDisplayContext value, UErrorCode& status);
812 
823  virtual UDisplayContext getContext(UDisplayContextType type, UErrorCode& status) const;
824 
836  virtual DateFormat& U_EXPORT2 setBooleanAttribute(UDateFormatBooleanAttribute attr,
837  UBool newvalue,
838  UErrorCode &status);
839 
849  virtual UBool U_EXPORT2 getBooleanAttribute(UDateFormatBooleanAttribute attr, UErrorCode &status) const;
850 
851 protected:
858  DateFormat();
859 
864  DateFormat(const DateFormat&);
865 
871 
879 
887 
888 
889 private:
898  static DateFormat* U_EXPORT2 create(EStyle timeStyle, EStyle dateStyle, const Locale& inLocale);
899 
900 
905 
906 
907  UDisplayContext fCapitalizationContext;
908  friend class DateFmtKeyByStyle;
909 
910 public:
911 #ifndef U_HIDE_OBSOLETE_API
912 
917  enum EField
918  {
919  // Obsolete; use UDateFormatField instead
920  kEraField = UDAT_ERA_FIELD,
921  kYearField = UDAT_YEAR_FIELD,
922  kMonthField = UDAT_MONTH_FIELD,
923  kDateField = UDAT_DATE_FIELD,
924  kHourOfDay1Field = UDAT_HOUR_OF_DAY1_FIELD,
925  kHourOfDay0Field = UDAT_HOUR_OF_DAY0_FIELD,
926  kMinuteField = UDAT_MINUTE_FIELD,
927  kSecondField = UDAT_SECOND_FIELD,
928  kMillisecondField = UDAT_FRACTIONAL_SECOND_FIELD,
929  kDayOfWeekField = UDAT_DAY_OF_WEEK_FIELD,
930  kDayOfYearField = UDAT_DAY_OF_YEAR_FIELD,
931  kDayOfWeekInMonthField = UDAT_DAY_OF_WEEK_IN_MONTH_FIELD,
932  kWeekOfYearField = UDAT_WEEK_OF_YEAR_FIELD,
933  kWeekOfMonthField = UDAT_WEEK_OF_MONTH_FIELD,
934  kAmPmField = UDAT_AM_PM_FIELD,
935  kHour1Field = UDAT_HOUR1_FIELD,
936  kHour0Field = UDAT_HOUR0_FIELD,
937  kTimezoneField = UDAT_TIMEZONE_FIELD,
938  kYearWOYField = UDAT_YEAR_WOY_FIELD,
939  kDOWLocalField = UDAT_DOW_LOCAL_FIELD,
940  kExtendedYearField = UDAT_EXTENDED_YEAR_FIELD,
941  kJulianDayField = UDAT_JULIAN_DAY_FIELD,
942  kMillisecondsInDayField = UDAT_MILLISECONDS_IN_DAY_FIELD,
943 
944  // Obsolete; use UDateFormatField instead
945  ERA_FIELD = UDAT_ERA_FIELD,
946  YEAR_FIELD = UDAT_YEAR_FIELD,
947  MONTH_FIELD = UDAT_MONTH_FIELD,
948  DATE_FIELD = UDAT_DATE_FIELD,
949  HOUR_OF_DAY1_FIELD = UDAT_HOUR_OF_DAY1_FIELD,
950  HOUR_OF_DAY0_FIELD = UDAT_HOUR_OF_DAY0_FIELD,
951  MINUTE_FIELD = UDAT_MINUTE_FIELD,
952  SECOND_FIELD = UDAT_SECOND_FIELD,
953  MILLISECOND_FIELD = UDAT_FRACTIONAL_SECOND_FIELD,
954  DAY_OF_WEEK_FIELD = UDAT_DAY_OF_WEEK_FIELD,
955  DAY_OF_YEAR_FIELD = UDAT_DAY_OF_YEAR_FIELD,
956  DAY_OF_WEEK_IN_MONTH_FIELD = UDAT_DAY_OF_WEEK_IN_MONTH_FIELD,
957  WEEK_OF_YEAR_FIELD = UDAT_WEEK_OF_YEAR_FIELD,
958  WEEK_OF_MONTH_FIELD = UDAT_WEEK_OF_MONTH_FIELD,
959  AM_PM_FIELD = UDAT_AM_PM_FIELD,
960  HOUR1_FIELD = UDAT_HOUR1_FIELD,
961  HOUR0_FIELD = UDAT_HOUR0_FIELD,
962  TIMEZONE_FIELD = UDAT_TIMEZONE_FIELD
963  };
964 #endif /* U_HIDE_OBSOLETE_API */
965 };
966 
968 
969 #endif /* #if !UCONFIG_NO_FORMATTING */
970 
971 #endif // _DATEFMT
972 //eof