ICU 58.2 58.2

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

- File List
- Globals

datefmt.h
Go to the documentation of this file.
1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 ********************************************************************************
5 * Copyright (C) 1997-2016, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 ********************************************************************************
8 *
9 * File DATEFMT.H
10 *
11 * Modification History:
12 *
13 * Date Name Description
14 * 02/19/97 aliu Converted from java.
15 * 04/01/97 aliu Added support for centuries.
16 * 07/23/98 stephen JDK 1.2 sync
17 * 11/15/99 weiv Added support for week of year/day of week formatting
18 ********************************************************************************
19 */
20
21 #ifndef DATEFMT_H
22 #define DATEFMT_H
23
24 #include "unicode/utypes.h"
25
26 #if !UCONFIG_NO_FORMATTING
27
28 #include "unicode/udat.h"
29 #include "unicode/calendar.h"
30 #include "unicode/numfmt.h"
31 #include "unicode/format.h"
32 #include "unicode/locid.h"
33 #include "unicode/enumset.h"
34 #include "unicode/udisplaycontext.h"
35
41 U_NAMESPACE_BEGIN
42
43 class TimeZone;
44 class DateTimePatternGenerator;
45
46 // explicit template instantiation. see digitlst.h
47 #if defined (_MSC_VER)
48 template class U_I18N_API EnumSet<UDateFormatBooleanAttribute,
49 0,
50 UDAT_BOOLEAN_ATTRIBUTE_COUNT>;
51 #endif
52
149 class U_I18N_API DateFormat : public Format {
150 public:
151
159 enum EStyle
160 {
161 kNone = -1,
162
163 kFull = 0,
164 kLong = 1,
165 kMedium = 2,
166 kShort = 3,
167
168 kDateOffset = kShort + 1,
169 // kFull + kDateOffset = 4
170 // kLong + kDateOffset = 5
171 // kMedium + kDateOffset = 6
172 // kShort + kDateOffset = 7
173
174 kDateTime = 8,
175 // Default DateTime
176
177 kDateTimeOffset = kDateTime + 1,
178 // kFull + kDateTimeOffset = 9
179 // kLong + kDateTimeOffset = 10
180 // kMedium + kDateTimeOffset = 11
181 // kShort + kDateTimeOffset = 12
182
183 // relative dates
184 kRelative = (1 << 7),
185
186 kFullRelative = (kFull | kRelative),
187
188 kLongRelative = kLong | kRelative,
189
190 kMediumRelative = kMedium | kRelative,
191
192 kShortRelative = kShort | kRelative,
193
194
195 kDefault = kMedium,
196
197
198
203 FULL = kFull,
204 LONG = kLong,
205 MEDIUM = kMedium,
206 SHORT = kShort,
207 DEFAULT = kDefault,
208 DATE_OFFSET = kDateOffset,
209 NONE = kNone,
210 DATE_TIME = kDateTime
211 };
212
217 virtual ~DateFormat();
218
223 virtual UBool operator==(const Format&) const;
224
225
226 using Format::format;
227
242 virtual UnicodeString& format(const Formattable& obj,
243 UnicodeString& appendTo,
244 FieldPosition& pos,
245 UErrorCode& status) const;
246
262 virtual UnicodeString& format(const Formattable& obj,
263 UnicodeString& appendTo,
264 FieldPositionIterator* posIter,
265 UErrorCode& status) const;
299 virtual UnicodeString& format( Calendar& cal,
300 UnicodeString& appendTo,
301 FieldPosition& fieldPosition) const = 0;
302
321 virtual UnicodeString& format(Calendar& cal,
322 UnicodeString& appendTo,
323 FieldPositionIterator* posIter,
324 UErrorCode& status) const;
352 UnicodeString& format( UDate date,
353 UnicodeString& appendTo,
354 FieldPosition& fieldPosition) const;
355
369 UnicodeString& format(UDate date,
370 UnicodeString& appendTo,
371 FieldPositionIterator* posIter,
372 UErrorCode& status) const;
384 UnicodeString& format(UDate date, UnicodeString& appendTo) const;
385
420 virtual UDate parse( const UnicodeString& text,
421 UErrorCode& status) const;
422
449 virtual void parse( const UnicodeString& text,
450 Calendar& cal,
451 ParsePosition& pos) const = 0;
452
483 UDate parse( const UnicodeString& text,
484 ParsePosition& pos) const;
485
509 virtual void parseObject(const UnicodeString& source,
510 Formattable& result,
511 ParsePosition& parse_pos) const;
512
520 static DateFormat* U_EXPORT2 createInstance(void);
521
533 static DateFormat* U_EXPORT2 createTimeInstance(EStyle style = kDefault,
534 const Locale& aLocale = Locale::getDefault());
535
551 static DateFormat* U_EXPORT2 createDateInstance(EStyle style = kDefault,
552 const Locale& aLocale = Locale::getDefault());
553
572 static DateFormat* U_EXPORT2 createDateTimeInstance(EStyle dateStyle = kDefault,
573 EStyle timeStyle = kDefault,
574 const Locale& aLocale = Locale::getDefault());
575
576 #ifndef U_HIDE_INTERNAL_API
577
585 static UnicodeString getBestPattern(
586 const Locale &locale,
587 const UnicodeString &skeleton,
588 UErrorCode &status);
589 #endif /* U_HIDE_INTERNAL_API */
590
604 static DateFormat* U_EXPORT2 createInstanceForSkeleton(
605 const UnicodeString& skeleton,
606 UErrorCode &status);
607
621 static DateFormat* U_EXPORT2 createInstanceForSkeleton(
622 const UnicodeString& skeleton,
623 const Locale &locale,
624 UErrorCode &status);
625
640 static DateFormat* U_EXPORT2 createInstanceForSkeleton(
641 Calendar *calendarToAdopt,
642 const UnicodeString& skeleton,
643 const Locale &locale,
644 UErrorCode &status);
645
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 &#39;w&#39; field alignment, corresponding to the UCAL_WEEK_OF_...
Definition: udat.h:592
icu::Format
Base class for all formats.
Definition: format.h:96
UDAT_DOW_LOCAL_FIELD
FieldPosition and UFieldPosition selector for &#39;e&#39; field alignment, corresponding to the UCAL_DOW_LOCA...
Definition: udat.h:646
icu::EnumSet< UDateFormatBooleanAttribute, 0, UDAT_BOOLEAN_ATTRIBUTE_COUNT >
UDAT_MONTH_FIELD
FieldPosition and UFieldPosition selector for &#39;M&#39; field alignment, corresponding to the UCAL_MONTH fi...
Definition: udat.h:510
icu::NumberFormat
Abstract base class for all number formats.
Definition: numfmt.h:169
UDAT_HOUR_OF_DAY1_FIELD
FieldPosition and UFieldPosition selector for &#39;k&#39; field alignment, corresponding to the UCAL_HOUR_OF_...
Definition: udat.h:526
icu::Calendar
Calendar is an abstract base class for converting between a UDate object and a set of integer fields ...
Definition: calendar.h:202
UDisplayContext
UDisplayContext
Display context settings.
Definition: udisplaycontext.h:66
UDate
double UDate
Date and Time data type.
Definition: utypes.h:203
icu::TimeZone
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:131
UDAT_BOOLEAN_ATTRIBUTE_COUNT
One more than the highest normal UDateFormatBooleanAttribute value.
Definition: udat.h:911
udisplaycontext.h
C API: Display context types (enum values)
UDAT_JULIAN_DAY_FIELD
FieldPosition and UFieldPosition selector for &#39;g&#39; field alignment, corresponding to the UCAL_JULIAN_D...
Definition: udat.h:660
UDAT_DAY_OF_YEAR_FIELD
FieldPosition and UFieldPosition selector for &#39;D&#39; field alignment, corresponding to the UCAL_DAY_OF_Y...
Definition: udat.h:578
format.h
C++ API: Base class for all formats.
UDAT_EXTENDED_YEAR_FIELD
FieldPosition and UFieldPosition selector for &#39;u&#39; field alignment, corresponding to the UCAL_EXTENDED...
Definition: udat.h:653
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:360
UDAT_DATE_FIELD
FieldPosition and UFieldPosition selector for &#39;d&#39; field alignment, corresponding to the UCAL_DATE fie...
Definition: udat.h:517
UDAT_YEAR_WOY_FIELD
FieldPosition and UFieldPosition selector for &#39;Y&#39; field alignment, corresponding to the UCAL_YEAR_WOY...
Definition: udat.h:639
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
UDAT_DAY_OF_WEEK_IN_MONTH_FIELD
FieldPosition and UFieldPosition selector for &#39;F&#39; field alignment, corresponding to the UCAL_DAY_OF_W...
Definition: udat.h:585
icu::FieldPositionIterator
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition: fpositer.h:55
UDAT_MILLISECONDS_IN_DAY_FIELD
FieldPosition and UFieldPosition selector for &#39;A&#39; field alignment, corresponding to the UCAL_MILLISEC...
Definition: udat.h:667
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 &#39;W&#39; field alignment, corresponding to the UCAL_WEEK_OF_...
Definition: udat.h:599
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:159
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 &#39;E&#39; field alignment, corresponding to the UCAL_DAY_OF_W...
Definition: udat.h:571
UDAT_AM_PM_FIELD
FieldPosition and UFieldPosition selector for &#39;a&#39; field alignment, corresponding to the UCAL_AM_PM fi...
Definition: udat.h:606
UDAT_HOUR0_FIELD
FieldPosition and UFieldPosition selector for &#39;K&#39; field alignment, corresponding to the UCAL_HOUR fie...
Definition: udat.h:624
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
UDisplayContextType
UDisplayContextType
Display context types, for getting values of a particular setting.
Definition: udisplaycontext.h:27
UDAT_ERA_FIELD
FieldPosition and UFieldPosition selector for &#39;G&#39; field alignment, corresponding to the UCAL_ERA fiel...
Definition: udat.h:496
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
UDAT_MINUTE_FIELD
FieldPosition and UFieldPosition selector for &#39;m&#39; field alignment, corresponding to the UCAL_MINUTE f...
Definition: udat.h:542
icu::FieldPosition
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:108
icu::ParsePosition
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:49
icu::DateFormat
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition: datefmt.h:149
locid.h
C++ API: Locale ID object.
icu::Format::operator==
virtual UBool operator==(const Format &other) const =0
Return true if the given Format objects are semantically equal.
icu::Format::parseObject
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const =0
Parse a string to produce an object.
UDAT_SECOND_FIELD
FieldPosition and UFieldPosition selector for &#39;s&#39; field alignment, corresponding to the UCAL_SECOND f...
Definition: udat.h:549
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UDAT_TIMEZONE_FIELD
FieldPosition and UFieldPosition selector for &#39;z&#39; field alignment, corresponding to the UCAL_ZONE_OFF...
Definition: udat.h:632
icu::Format::operator=
Format & operator=(const Format &)
UDAT_YEAR_FIELD
FieldPosition and UFieldPosition selector for &#39;y&#39; field alignment, corresponding to the UCAL_YEAR fie...
Definition: udat.h:503
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:295
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:68
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 &#39;H&#39; field alignment, corresponding to the UCAL_HOUR_OF_...
Definition: udat.h:535
UDateFormatBooleanAttribute
UDateFormatBooleanAttribute
DateFormat boolean attributes.
Definition: udat.h:880
UDAT_FRACTIONAL_SECOND_FIELD
FieldPosition and UFieldPosition selector for &#39;S&#39; field alignment, corresponding to the UCAL_MILLISEC...
Definition: udat.h:564
UDAT_HOUR1_FIELD
FieldPosition and UFieldPosition selector for &#39;h&#39; field alignment, corresponding to the UCAL_HOUR fie...
Definition: udat.h:615
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:259
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:187