ICU 56.1: datefmt.h Source File

ICU 56.1 56.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

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"
32 #include "unicode/udisplaycontext.h"
33
39 U_NAMESPACE_BEGIN
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,
48 UDAT_BOOLEAN_ATTRIBUTE_COUNT>;
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_INTERNAL_API
575
583 static UnicodeString getBestPattern(
584 const Locale &locale,
585 const UnicodeString &skeleton,
586 UErrorCode &status);
587 #endif /* U_HIDE_INTERNAL_API */
588
589 #ifndef U_HIDE_DRAFT_API
590
603 static DateFormat* U_EXPORT2 createInstanceForSkeleton(
604 const UnicodeString& skeleton,
605 UErrorCode &status);
606
620 static DateFormat* U_EXPORT2 createInstanceForSkeleton(
621 const UnicodeString& skeleton,
622 const Locale &locale,
623 UErrorCode &status);
624
639 static DateFormat* U_EXPORT2 createInstanceForSkeleton(
640 Calendar *calendarToAdopt,
641 const UnicodeString& skeleton,
642 const Locale &locale,
643 UErrorCode &status);
644
645 #endif /* U_HIDE_DRAFT_API */
646
654 static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
655
661 virtual UBool isLenient(void) const;
662
683 virtual void setLenient(UBool lenient);
684
685
690 virtual UBool isCalendarLenient(void) const;
691
692
702 virtual void setCalendarLenient(UBool lenient);
703
704
713 virtual const Calendar* getCalendar(void) const;
714
724 virtual void adoptCalendar(Calendar* calendarToAdopt);
725
733 virtual void setCalendar(const Calendar& newCalendar);
734
735
742 virtual const NumberFormat* getNumberFormat(void) const;
743
750 virtual void adoptNumberFormat(NumberFormat* formatToAdopt);
751
757 virtual void setNumberFormat(const NumberFormat& newNumberFormat);
758
764 virtual const TimeZone& getTimeZone(void) const;
765
772 virtual void adoptTimeZone(TimeZone* zoneToAdopt);
773
779 virtual void setTimeZone(const TimeZone& zone);
780
790 virtual void setContext(UDisplayContext value, UErrorCode& status);
791
802 virtual UDisplayContext getContext(UDisplayContextType type, UErrorCode& status) const;
803
815 virtual DateFormat& U_EXPORT2 setBooleanAttribute(UDateFormatBooleanAttribute attr,
816 UBool newvalue,
817 UErrorCode &status);
818
828 virtual UBool U_EXPORT2 getBooleanAttribute(UDateFormatBooleanAttribute attr, UErrorCode &status) const;
829
830 protected:
837 DateFormat();
838
843 DateFormat(const DateFormat&);
844
849 DateFormat& operator=(const DateFormat&);
850
857 Calendar* fCalendar;
858
865 NumberFormat* fNumberFormat;
866
867
868 private:
869
878 static DateFormat* U_EXPORT2 create(EStyle timeStyle, EStyle dateStyle, const Locale& inLocale);
879
880
884 EnumSet<UDateFormatBooleanAttribute, 0, UDAT_BOOLEAN_ATTRIBUTE_COUNT> fBoolFlags;
885
886
887 UDisplayContext fCapitalizationContext;
888 friend class DateFmtKeyByStyle;
889
890 public:
891 #ifndef U_HIDE_OBSOLETE_API
892
897 enum EField
898 {
899 // Obsolete; use UDateFormatField instead
900 kEraField = UDAT_ERA_FIELD,
901 kYearField = UDAT_YEAR_FIELD,
902 kMonthField = UDAT_MONTH_FIELD,
903 kDateField = UDAT_DATE_FIELD,
904 kHourOfDay1Field = UDAT_HOUR_OF_DAY1_FIELD,
905 kHourOfDay0Field = UDAT_HOUR_OF_DAY0_FIELD,
906 kMinuteField = UDAT_MINUTE_FIELD,
907 kSecondField = UDAT_SECOND_FIELD,
908 kMillisecondField = UDAT_FRACTIONAL_SECOND_FIELD,
909 kDayOfWeekField = UDAT_DAY_OF_WEEK_FIELD,
910 kDayOfYearField = UDAT_DAY_OF_YEAR_FIELD,
911 kDayOfWeekInMonthField = UDAT_DAY_OF_WEEK_IN_MONTH_FIELD,
912 kWeekOfYearField = UDAT_WEEK_OF_YEAR_FIELD,
913 kWeekOfMonthField = UDAT_WEEK_OF_MONTH_FIELD,
914 kAmPmField = UDAT_AM_PM_FIELD,
915 kHour1Field = UDAT_HOUR1_FIELD,
916 kHour0Field = UDAT_HOUR0_FIELD,
917 kTimezoneField = UDAT_TIMEZONE_FIELD,
918 kYearWOYField = UDAT_YEAR_WOY_FIELD,
919 kDOWLocalField = UDAT_DOW_LOCAL_FIELD,
920 kExtendedYearField = UDAT_EXTENDED_YEAR_FIELD,
921 kJulianDayField = UDAT_JULIAN_DAY_FIELD,
922 kMillisecondsInDayField = UDAT_MILLISECONDS_IN_DAY_FIELD,
923
924 // Obsolete; use UDateFormatField instead
925 ERA_FIELD = UDAT_ERA_FIELD,
926 YEAR_FIELD = UDAT_YEAR_FIELD,
927 MONTH_FIELD = UDAT_MONTH_FIELD,
928 DATE_FIELD = UDAT_DATE_FIELD,
929 HOUR_OF_DAY1_FIELD = UDAT_HOUR_OF_DAY1_FIELD,
930 HOUR_OF_DAY0_FIELD = UDAT_HOUR_OF_DAY0_FIELD,
931 MINUTE_FIELD = UDAT_MINUTE_FIELD,
932 SECOND_FIELD = UDAT_SECOND_FIELD,
933 MILLISECOND_FIELD = UDAT_FRACTIONAL_SECOND_FIELD,
934 DAY_OF_WEEK_FIELD = UDAT_DAY_OF_WEEK_FIELD,
935 DAY_OF_YEAR_FIELD = UDAT_DAY_OF_YEAR_FIELD,
936 DAY_OF_WEEK_IN_MONTH_FIELD = UDAT_DAY_OF_WEEK_IN_MONTH_FIELD,
937 WEEK_OF_YEAR_FIELD = UDAT_WEEK_OF_YEAR_FIELD,
938 WEEK_OF_MONTH_FIELD = UDAT_WEEK_OF_MONTH_FIELD,
939 AM_PM_FIELD = UDAT_AM_PM_FIELD,
940 HOUR1_FIELD = UDAT_HOUR1_FIELD,
941 HOUR0_FIELD = UDAT_HOUR0_FIELD,
942 TIMEZONE_FIELD = UDAT_TIMEZONE_FIELD
943 };
944 #endif /* U_HIDE_OBSOLETE_API */
945 };
946
947 U_NAMESPACE_END
948
949 #endif /* #if !UCONFIG_NO_FORMATTING */
950
951 #endif // _DATEFMT
952 //eof
UDAT_WEEK_OF_YEAR_FIELD
FieldPosition and UFieldPosition selector for 'w' field alignment, corresponding to the UCAL_WEEK_OF_...
Definition: udat.h:590
icu::Format
Base class for all formats.
Definition: format.h:94
UDAT_DOW_LOCAL_FIELD
FieldPosition and UFieldPosition selector for 'e' field alignment, corresponding to the UCAL_DOW_LOCA...
Definition: udat.h:644
icu::EnumSet< UDateFormatBooleanAttribute, 0, UDAT_BOOLEAN_ATTRIBUTE_COUNT >
UDAT_MONTH_FIELD
FieldPosition and UFieldPosition selector for 'M' field alignment, corresponding to the UCAL_MONTH fi...
Definition: udat.h:508
icu::NumberFormat
Abstract base class for all number formats.
Definition: numfmt.h:172
UDAT_HOUR_OF_DAY1_FIELD
FieldPosition and UFieldPosition selector for 'k' field alignment, corresponding to the UCAL_HOUR_OF_...
Definition: udat.h:524
icu::Calendar
Calendar is an abstract base class for converting between a UDate object and a set of integer fields ...
Definition: calendar.h:200
UDisplayContext
UDisplayContext
Display context settings.
Definition: udisplaycontext.h:56
UDate
double UDate
Date and Time data type.
Definition: utypes.h:201
icu::TimeZone
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:129
UDAT_BOOLEAN_ATTRIBUTE_COUNT
count boolean date format constants
Definition: udat.h:893
udisplaycontext.h
C API: Display context types (enum values)
UDAT_JULIAN_DAY_FIELD
FieldPosition and UFieldPosition selector for 'g' field alignment, corresponding to the UCAL_JULIAN_D...
Definition: udat.h:658
UDAT_DAY_OF_YEAR_FIELD
FieldPosition and UFieldPosition selector for 'D' field alignment, corresponding to the UCAL_DAY_OF_Y...
Definition: udat.h:576
format.h
C++ API: Base class for all formats.
UDAT_EXTENDED_YEAR_FIELD
FieldPosition and UFieldPosition selector for 'u' field alignment, corresponding to the UCAL_EXTENDED...
Definition: udat.h:651
icu::DateFormat::EField
EField
Field selector for FieldPosition for DateFormat fields.
Definition: datefmt.h:897
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:358
UDAT_DATE_FIELD
FieldPosition and UFieldPosition selector for 'd' field alignment, corresponding to the UCAL_DATE fie...
Definition: udat.h:515
UDAT_YEAR_WOY_FIELD
FieldPosition and UFieldPosition selector for 'Y' field alignment, corresponding to the UCAL_YEAR_WOY...
Definition: udat.h:637
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
UDAT_DAY_OF_WEEK_IN_MONTH_FIELD
FieldPosition and UFieldPosition selector for 'F' field alignment, corresponding to the UCAL_DAY_OF_W...
Definition: udat.h:583
icu::FieldPositionIterator
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition: fpositer.h:53
UDAT_MILLISECONDS_IN_DAY_FIELD
FieldPosition and UFieldPosition selector for 'A' field alignment, corresponding to the UCAL_MILLISEC...
Definition: udat.h:665
calendar.h
C++ API: Calendar object.
udat.h
C API: DateFormat.
icu::DateFormat::fCalendar
Calendar * fCalendar
The calendar that DateFormat uses to produce the time field values needed to implement date/time form...
Definition: datefmt.h:857
UDAT_WEEK_OF_MONTH_FIELD
FieldPosition and UFieldPosition selector for 'W' field alignment, corresponding to the UCAL_WEEK_OF_...
Definition: udat.h:597
icu::Format::format
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
icu::DateFormat::EStyle
EStyle
Constants for various style patterns.
Definition: datefmt.h:157
icu::DateFormat::fNumberFormat
NumberFormat * fNumberFormat
The number formatter that DateFormat uses to format numbers in dates and times.
Definition: datefmt.h:865
UDAT_DAY_OF_WEEK_FIELD
FieldPosition and UFieldPosition selector for 'E' field alignment, corresponding to the UCAL_DAY_OF_W...
Definition: udat.h:569
UDAT_AM_PM_FIELD
FieldPosition and UFieldPosition selector for 'a' field alignment, corresponding to the UCAL_AM_PM fi...
Definition: udat.h:604
UDAT_HOUR0_FIELD
FieldPosition and UFieldPosition selector for 'K' field alignment, corresponding to the UCAL_HOUR fie...
Definition: udat.h:622
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
UDisplayContextType
UDisplayContextType
Display context types, for getting values of a particular setting.
Definition: udisplaycontext.h:25
icu::Format::parseObject
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const =0
Parse a string to produce an object.
icu::Format::operator==
virtual UBool operator==(const Format &other) const =0
Return true if the given Format objects are semantically equal.
UDAT_ERA_FIELD
FieldPosition and UFieldPosition selector for 'G' field alignment, corresponding to the UCAL_ERA fiel...
Definition: udat.h:494
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:476
UDAT_MINUTE_FIELD
FieldPosition and UFieldPosition selector for 'm' field alignment, corresponding to the UCAL_MINUTE f...
Definition: udat.h:540
icu::FieldPosition
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:106
icu::ParsePosition
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:47
icu::DateFormat
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition: datefmt.h:147
locid.h
C++ API: Locale ID object.
UDAT_SECOND_FIELD
FieldPosition and UFieldPosition selector for 's' field alignment, corresponding to the UCAL_SECOND f...
Definition: udat.h:547
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UDAT_TIMEZONE_FIELD
FieldPosition and UFieldPosition selector for 'z' field alignment, corresponding to the UCAL_ZONE_OFF...
Definition: udat.h:630
icu::Format::operator=
Format & operator=(const Format &)
UDAT_YEAR_FIELD
FieldPosition and UFieldPosition selector for 'y' field alignment, corresponding to the UCAL_YEAR fie...
Definition: udat.h:501
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:293
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:66
enumset.h
C++: internal template EnumSet<>
numfmt.h
C++ API: Abstract base class for all number formats.
UDAT_HOUR_OF_DAY0_FIELD
FieldPosition and UFieldPosition selector for 'H' field alignment, corresponding to the UCAL_HOUR_OF_...
Definition: udat.h:533
UDateFormatBooleanAttribute
UDateFormatBooleanAttribute
DateFormat boolean attributes.
Definition: udat.h:863
UDAT_FRACTIONAL_SECOND_FIELD
FieldPosition and UFieldPosition selector for 'S' field alignment, corresponding to the UCAL_MILLISEC...
Definition: udat.h:562
UDAT_HOUR1_FIELD
FieldPosition and UFieldPosition selector for 'h' field alignment, corresponding to the UCAL_HOUR fie...
Definition: udat.h:613
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:234
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:185