ICU 69.1 69.1

datefmt.h
Go to the documentation of this file.
1 // © 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 U_SHOW_CPLUSPLUS_API
27
28 #if !UCONFIG_NO_FORMATTING
29
30 #include "unicode/udat.h"
31 #include "unicode/calendar.h"
32 #include "unicode/numfmt.h"
33 #include "unicode/format.h"
34 #include "unicode/locid.h"
35 #include "unicode/enumset.h"
36 #include "unicode/udisplaycontext.h"
37
43 U_NAMESPACE_BEGIN
44
45 class TimeZone;
46 class DateTimePatternGenerator;
47
53 #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN && !defined(U_IN_DOXYGEN)
54 template class U_I18N_API EnumSet<UDateFormatBooleanAttribute,
55 0,
56 UDAT_BOOLEAN_ATTRIBUTE_COUNT>;
57 #endif
58
156 class U_I18N_API DateFormat : public Format {
157 public:
158
166 enum EStyle
167 {
168 kNone = -1,
169
170 kFull = 0,
171 kLong = 1,
172 kMedium = 2,
173 kShort = 3,
174
175 kDateOffset = kShort + 1,
176 // kFull + kDateOffset = 4
177 // kLong + kDateOffset = 5
178 // kMedium + kDateOffset = 6
179 // kShort + kDateOffset = 7
180
181 kDateTime = 8,
182 // Default DateTime
183
184 kDateTimeOffset = kDateTime + 1,
185 // kFull + kDateTimeOffset = 9
186 // kLong + kDateTimeOffset = 10
187 // kMedium + kDateTimeOffset = 11
188 // kShort + kDateTimeOffset = 12
189
190 // relative dates
191 kRelative = (1 << 7),
192
193 kFullRelative = (kFull | kRelative),
194
195 kLongRelative = kLong | kRelative,
196
197 kMediumRelative = kMedium | kRelative,
198
199 kShortRelative = kShort | kRelative,
200
201
202 kDefault = kMedium,
203
204
205
210 FULL = kFull,
211 LONG = kLong,
212 MEDIUM = kMedium,
213 SHORT = kShort,
214 DEFAULT = kDefault,
215 DATE_OFFSET = kDateOffset,
216 NONE = kNone,
217 DATE_TIME = kDateTime
218 };
219
224 virtual ~DateFormat();
225
232 virtual DateFormat* clone() const = 0;
233
238 virtual UBool operator==(const Format&) const;
239
240
241 using Format::format;
242
257 virtual UnicodeString& format(const Formattable& obj,
258 UnicodeString& appendTo,
259 FieldPosition& pos,
260 UErrorCode& status) const;
261
277 virtual UnicodeString& format(const Formattable& obj,
278 UnicodeString& appendTo,
279 FieldPositionIterator* posIter,
280 UErrorCode& status) const;
314 virtual UnicodeString& format( Calendar& cal,
315 UnicodeString& appendTo,
316 FieldPosition& fieldPosition) const = 0;
317
336 virtual UnicodeString& format(Calendar& cal,
337 UnicodeString& appendTo,
338 FieldPositionIterator* posIter,
339 UErrorCode& status) const;
367 UnicodeString& format( UDate date,
368 UnicodeString& appendTo,
369 FieldPosition& fieldPosition) const;
370
384 UnicodeString& format(UDate date,
385 UnicodeString& appendTo,
386 FieldPositionIterator* posIter,
387 UErrorCode& status) const;
399 UnicodeString& format(UDate date, UnicodeString& appendTo) const;
400
435 virtual UDate parse( const UnicodeString& text,
436 UErrorCode& status) const;
437
464 virtual void parse( const UnicodeString& text,
465 Calendar& cal,
466 ParsePosition& pos) const = 0;
467
498 UDate parse( const UnicodeString& text,
499 ParsePosition& pos) const;
500
524 virtual void parseObject(const UnicodeString& source,
525 Formattable& result,
526 ParsePosition& parse_pos) const;
527
535 static DateFormat* U_EXPORT2 createInstance(void);
536
548 static DateFormat* U_EXPORT2 createTimeInstance(EStyle style = kDefault,
549 const Locale& aLocale = Locale::getDefault());
550
566 static DateFormat* U_EXPORT2 createDateInstance(EStyle style = kDefault,
567 const Locale& aLocale = Locale::getDefault());
568
587 static DateFormat* U_EXPORT2 createDateTimeInstance(EStyle dateStyle = kDefault,
588 EStyle timeStyle = kDefault,
589 const Locale& aLocale = Locale::getDefault());
590
591 #ifndef U_HIDE_INTERNAL_API
592
600 static UnicodeString getBestPattern(
601 const Locale &locale,
602 const UnicodeString &skeleton,
603 UErrorCode &status);
604 #endif /* U_HIDE_INTERNAL_API */
605
619 static DateFormat* U_EXPORT2 createInstanceForSkeleton(
620 const UnicodeString& skeleton,
621 UErrorCode &status);
622
636 static DateFormat* U_EXPORT2 createInstanceForSkeleton(
637 const UnicodeString& skeleton,
638 const Locale &locale,
639 UErrorCode &status);
640
655 static DateFormat* U_EXPORT2 createInstanceForSkeleton(
656 Calendar *calendarToAdopt,
657 const UnicodeString& skeleton,
658 const Locale &locale,
659 UErrorCode &status);
660
661
669 static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
670
676 virtual UBool isLenient(void) const;
677
698 virtual void setLenient(UBool lenient);
699
700
705 virtual UBool isCalendarLenient(void) const;
706
707
717 virtual void setCalendarLenient(UBool lenient);
718
719
728 virtual const Calendar* getCalendar(void) const;
729
739 virtual void adoptCalendar(Calendar* calendarToAdopt);
740
748 virtual void setCalendar(const Calendar& newCalendar);
749
750
757 virtual const NumberFormat* getNumberFormat(void) const;
758
765 virtual void adoptNumberFormat(NumberFormat* formatToAdopt);
766
772 virtual void setNumberFormat(const NumberFormat& newNumberFormat);
773
779 virtual const TimeZone& getTimeZone(void) const;
780
787 virtual void adoptTimeZone(TimeZone* zoneToAdopt);
788
794 virtual void setTimeZone(const TimeZone& zone);
795
805 virtual void setContext(UDisplayContext value, UErrorCode& status);
806
817 virtual UDisplayContext getContext(UDisplayContextType type, UErrorCode& status) const;
818
830 virtual DateFormat& U_EXPORT2 setBooleanAttribute(UDateFormatBooleanAttribute attr,
831 UBool newvalue,
832 UErrorCode &status);
833
843 virtual UBool U_EXPORT2 getBooleanAttribute(UDateFormatBooleanAttribute attr, UErrorCode &status) const;
844
845 protected:
852 DateFormat();
853
858 DateFormat(const DateFormat&);
859
864 DateFormat& operator=(const DateFormat&);
865
872 Calendar* fCalendar;
873
880 NumberFormat* fNumberFormat;
881
882
883 private:
884
893 static DateFormat* U_EXPORT2 create(EStyle timeStyle, EStyle dateStyle, const Locale& inLocale);
894
895
899 EnumSet<UDateFormatBooleanAttribute, 0, UDAT_BOOLEAN_ATTRIBUTE_COUNT> fBoolFlags;
900
901
902 UDisplayContext fCapitalizationContext;
903 friend class DateFmtKeyByStyle;
904
905 public:
906 #ifndef U_HIDE_OBSOLETE_API
907
912 enum EField
913 {
914 // Obsolete; use UDateFormatField instead
915 kEraField = UDAT_ERA_FIELD,
916 kYearField = UDAT_YEAR_FIELD,
917 kMonthField = UDAT_MONTH_FIELD,
918 kDateField = UDAT_DATE_FIELD,
919 kHourOfDay1Field = UDAT_HOUR_OF_DAY1_FIELD,
920 kHourOfDay0Field = UDAT_HOUR_OF_DAY0_FIELD,
921 kMinuteField = UDAT_MINUTE_FIELD,
922 kSecondField = UDAT_SECOND_FIELD,
923 kMillisecondField = UDAT_FRACTIONAL_SECOND_FIELD,
924 kDayOfWeekField = UDAT_DAY_OF_WEEK_FIELD,
925 kDayOfYearField = UDAT_DAY_OF_YEAR_FIELD,
926 kDayOfWeekInMonthField = UDAT_DAY_OF_WEEK_IN_MONTH_FIELD,
927 kWeekOfYearField = UDAT_WEEK_OF_YEAR_FIELD,
928 kWeekOfMonthField = UDAT_WEEK_OF_MONTH_FIELD,
929 kAmPmField = UDAT_AM_PM_FIELD,
930 kHour1Field = UDAT_HOUR1_FIELD,
931 kHour0Field = UDAT_HOUR0_FIELD,
932 kTimezoneField = UDAT_TIMEZONE_FIELD,
933 kYearWOYField = UDAT_YEAR_WOY_FIELD,
934 kDOWLocalField = UDAT_DOW_LOCAL_FIELD,
935 kExtendedYearField = UDAT_EXTENDED_YEAR_FIELD,
936 kJulianDayField = UDAT_JULIAN_DAY_FIELD,
937 kMillisecondsInDayField = UDAT_MILLISECONDS_IN_DAY_FIELD,
938
939 // Obsolete; use UDateFormatField instead
940 ERA_FIELD = UDAT_ERA_FIELD,
941 YEAR_FIELD = UDAT_YEAR_FIELD,
942 MONTH_FIELD = UDAT_MONTH_FIELD,
943 DATE_FIELD = UDAT_DATE_FIELD,
944 HOUR_OF_DAY1_FIELD = UDAT_HOUR_OF_DAY1_FIELD,
945 HOUR_OF_DAY0_FIELD = UDAT_HOUR_OF_DAY0_FIELD,
946 MINUTE_FIELD = UDAT_MINUTE_FIELD,
947 SECOND_FIELD = UDAT_SECOND_FIELD,
948 MILLISECOND_FIELD = UDAT_FRACTIONAL_SECOND_FIELD,
949 DAY_OF_WEEK_FIELD = UDAT_DAY_OF_WEEK_FIELD,
950 DAY_OF_YEAR_FIELD = UDAT_DAY_OF_YEAR_FIELD,
951 DAY_OF_WEEK_IN_MONTH_FIELD = UDAT_DAY_OF_WEEK_IN_MONTH_FIELD,
952 WEEK_OF_YEAR_FIELD = UDAT_WEEK_OF_YEAR_FIELD,
953 WEEK_OF_MONTH_FIELD = UDAT_WEEK_OF_MONTH_FIELD,
954 AM_PM_FIELD = UDAT_AM_PM_FIELD,
955 HOUR1_FIELD = UDAT_HOUR1_FIELD,
956 HOUR0_FIELD = UDAT_HOUR0_FIELD,
957 TIMEZONE_FIELD = UDAT_TIMEZONE_FIELD
958 };
959 #endif /* U_HIDE_OBSOLETE_API */
960 };
961
962 U_NAMESPACE_END
963
964 #endif /* #if !UCONFIG_NO_FORMATTING */
965
966 #endif /* U_SHOW_CPLUSPLUS_API */
967
968 #endif // _DATEFMT
969 //eof
UDAT_HOUR_OF_DAY1_FIELD
@ UDAT_HOUR_OF_DAY1_FIELD
FieldPosition and UFieldPosition selector for 'k' field alignment, corresponding to the UCAL_HOUR_OF_...
Definition: udat.h:551
UDAT_MINUTE_FIELD
@ UDAT_MINUTE_FIELD
FieldPosition and UFieldPosition selector for 'm' field alignment, corresponding to the UCAL_MINUTE f...
Definition: udat.h:567
icu::FieldPosition
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:110
UDAT_JULIAN_DAY_FIELD
@ UDAT_JULIAN_DAY_FIELD
FieldPosition and UFieldPosition selector for 'g' field alignment, corresponding to the UCAL_JULIAN_D...
Definition: udat.h:685
icu::NumberFormat
Definition: numfmt.h:175
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::DateFormat
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition: datefmt.h:156
UDAT_FRACTIONAL_SECOND_FIELD
@ UDAT_FRACTIONAL_SECOND_FIELD
FieldPosition and UFieldPosition selector for 'S' field alignment, corresponding to the UCAL_MILLISEC...
Definition: udat.h:589
UDAT_TIMEZONE_FIELD
@ UDAT_TIMEZONE_FIELD
FieldPosition and UFieldPosition selector for 'z' field alignment, corresponding to the UCAL_ZONE_OFF...
Definition: udat.h:657
U_I18N_API
#define U_I18N_API
Definition: utypes.h:301
icu::Calendar
Calendar is an abstract base class for converting between a UDate object and a set of integer fields ...
Definition: calendar.h:189
UDAT_DATE_FIELD
@ UDAT_DATE_FIELD
FieldPosition and UFieldPosition selector for 'd' field alignment, corresponding to the UCAL_DATE fie...
Definition: udat.h:542
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:269
icu::Format::parseObject
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const =0
Parse a string to produce an object.
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:64
icu::FieldPositionIterator
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition: fpositer.h:58
UDAT_YEAR_WOY_FIELD
@ UDAT_YEAR_WOY_FIELD
FieldPosition and UFieldPosition selector for 'Y' field alignment, corresponding to the UCAL_YEAR_WOY...
Definition: udat.h:664
format.h
C++ API: Base class for all formats.
UDAT_DAY_OF_YEAR_FIELD
@ UDAT_DAY_OF_YEAR_FIELD
FieldPosition and UFieldPosition selector for 'D' field alignment, corresponding to the UCAL_DAY_OF_Y...
Definition: udat.h:603
UDAT_DOW_LOCAL_FIELD
@ UDAT_DOW_LOCAL_FIELD
FieldPosition and UFieldPosition selector for 'e' field alignment, corresponding to the UCAL_DOW_LOCA...
Definition: udat.h:671
UDAT_EXTENDED_YEAR_FIELD
@ UDAT_EXTENDED_YEAR_FIELD
FieldPosition and UFieldPosition selector for 'u' field alignment, corresponding to the UCAL_EXTENDED...
Definition: udat.h:678
UDAT_HOUR1_FIELD
@ UDAT_HOUR1_FIELD
FieldPosition and UFieldPosition selector for 'h' field alignment, corresponding to the UCAL_HOUR fie...
Definition: udat.h:640
UDateFormatBooleanAttribute
UDateFormatBooleanAttribute
DateFormat boolean attributes.
Definition: udat.h:917
icu::Format::format
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
icu::TimeZone
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:133
UDisplayContextType
UDisplayContextType
Display context types, for getting values of a particular setting.
Definition: udisplaycontext.h:27
icu::Format
Base class for all formats.
Definition: format.h:98
UDAT_MILLISECONDS_IN_DAY_FIELD
@ UDAT_MILLISECONDS_IN_DAY_FIELD
FieldPosition and UFieldPosition selector for 'A' field alignment, corresponding to the UCAL_MILLISEC...
Definition: udat.h:692
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:295
icu::Format::operator=
Format & operator=(const Format &)
icu::Format::clone
virtual Format * clone() const =0
Clone this object polymorphically.
UDAT_DAY_OF_WEEK_FIELD
@ UDAT_DAY_OF_WEEK_FIELD
FieldPosition and UFieldPosition selector for 'E' field alignment, corresponding to the UCAL_DAY_OF_W...
Definition: udat.h:596
enumset.h
C++: internal template EnumSet<>
UDAT_HOUR0_FIELD
@ UDAT_HOUR0_FIELD
FieldPosition and UFieldPosition selector for 'K' field alignment, corresponding to the UCAL_HOUR fie...
Definition: udat.h:649
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
UDAT_BOOLEAN_ATTRIBUTE_COUNT
@ UDAT_BOOLEAN_ATTRIBUTE_COUNT
One more than the highest normal UDateFormatBooleanAttribute value.
Definition: udat.h:949
UDAT_DAY_OF_WEEK_IN_MONTH_FIELD
@ 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:610
UDAT_YEAR_FIELD
@ UDAT_YEAR_FIELD
FieldPosition and UFieldPosition selector for 'y' field alignment, corresponding to the UCAL_YEAR fie...
Definition: udat.h:528
icu::DateFormat::EField
EField
Field selector for FieldPosition for DateFormat fields.
Definition: datefmt.h:912
calendar.h
C++ API: Calendar object.
UDAT_SECOND_FIELD
@ UDAT_SECOND_FIELD
FieldPosition and UFieldPosition selector for 's' field alignment, corresponding to the UCAL_SECOND f...
Definition: udat.h:574
UDate
double UDate
Date and Time data type.
Definition: utypes.h:203
UDAT_WEEK_OF_YEAR_FIELD
@ UDAT_WEEK_OF_YEAR_FIELD
FieldPosition and UFieldPosition selector for 'w' field alignment, corresponding to the UCAL_WEEK_OF_...
Definition: udat.h:617
UDAT_HOUR_OF_DAY0_FIELD
@ UDAT_HOUR_OF_DAY0_FIELD
FieldPosition and UFieldPosition selector for 'H' field alignment, corresponding to the UCAL_HOUR_OF_...
Definition: udat.h:560
UDisplayContext
UDisplayContext
Display context settings.
Definition: udisplaycontext.h:64
icu::DateFormat::EStyle
EStyle
Constants for various style patterns.
Definition: datefmt.h:166
numfmt.h
C++ API: Compatibility APIs for number formatting.
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:872
udisplaycontext.h
C API: Display context types (enum values)
UDAT_WEEK_OF_MONTH_FIELD
@ UDAT_WEEK_OF_MONTH_FIELD
FieldPosition and UFieldPosition selector for 'W' field alignment, corresponding to the UCAL_WEEK_OF_...
Definition: udat.h:624
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.
UDAT_ERA_FIELD
@ UDAT_ERA_FIELD
FieldPosition and UFieldPosition selector for 'G' field alignment, corresponding to the UCAL_ERA fiel...
Definition: udat.h:521
icu::DateFormat::fNumberFormat
NumberFormat * fNumberFormat
The number formatter that DateFormat uses to format numbers in dates and times.
Definition: datefmt.h:880
icu::ParsePosition
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:52
UDAT_AM_PM_FIELD
@ UDAT_AM_PM_FIELD
FieldPosition and UFieldPosition selector for 'a' field alignment, corresponding to the UCAL_AM_PM fi...
Definition: udat.h:631
udat.h
C API: DateFormat.
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
UDAT_MONTH_FIELD
@ UDAT_MONTH_FIELD
FieldPosition and UFieldPosition selector for 'M' field alignment, corresponding to the UCAL_MONTH fi...
Definition: udat.h:535