ICU 62.1 62.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 !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"
35
42
43class TimeZone;
44class DateTimePatternGenerator;
45
46// explicit template instantiation. see digitlst.h
47// (When building DLLs for Windows this is required.)
48#if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
49template class U_I18N_API EnumSet<UDateFormatBooleanAttribute,
50 0,
52#endif
53
151public:
152
161 {
162 kNone = -1,
163
164 kFull = 0,
165 kLong = 1,
166 kMedium = 2,
167 kShort = 3,
168
169 kDateOffset = kShort + 1,
170 // kFull + kDateOffset = 4
171 // kLong + kDateOffset = 5
172 // kMedium + kDateOffset = 6
173 // kShort + kDateOffset = 7
174
175 kDateTime = 8,
176 // Default DateTime
177
178 kDateTimeOffset = kDateTime + 1,
179 // kFull + kDateTimeOffset = 9
180 // kLong + kDateTimeOffset = 10
181 // kMedium + kDateTimeOffset = 11
182 // kShort + kDateTimeOffset = 12
183
184 // relative dates
185 kRelative = (1 << 7),
186
187 kFullRelative = (kFull | kRelative),
188
189 kLongRelative = kLong | kRelative,
190
191 kMediumRelative = kMedium | kRelative,
192
193 kShortRelative = kShort | kRelative,
194
195
196 kDefault = kMedium,
197
198
199
204 FULL = kFull,
205 LONG = kLong,
206 MEDIUM = kMedium,
207 SHORT = kShort,
208 DEFAULT = kDefault,
209 DATE_OFFSET = kDateOffset,
210 NONE = kNone,
211 DATE_TIME = kDateTime
212 };
213
218 virtual ~DateFormat();
219
224 virtual UBool operator==(const Format&) const;
225
226
227 using Format::format;
228
244 UnicodeString& appendTo,
245 FieldPosition& pos,
246 UErrorCode& status) const;
247
264 UnicodeString& appendTo,
266 UErrorCode& status) const;
301 UnicodeString& appendTo,
302 FieldPosition& fieldPosition) const = 0;
303
323 UnicodeString& appendTo,
325 UErrorCode& status) const;
354 UnicodeString& appendTo,
356
371 UnicodeString& appendTo,
373 UErrorCode& status) const;
386
421 virtual UDate parse( const UnicodeString& text,
422 UErrorCode& status) const;
423
450 virtual void parse( const UnicodeString& text,
451 Calendar& cal,
452 ParsePosition& pos) const = 0;
453
485 ParsePosition& pos) const;
486
510 virtual void parseObject(const UnicodeString& source,
512 ParsePosition& parse_pos) const;
513
522
535 const Locale& aLocale = Locale::getDefault());
536
553 const Locale& aLocale = Locale::getDefault());
554
574 EStyle timeStyle = kDefault,
575 const Locale& aLocale = Locale::getDefault());
576
577#ifndef U_HIDE_INTERNAL_API
587 const Locale &locale,
588 const UnicodeString &skeleton,
590#endif /* U_HIDE_INTERNAL_API */
591
606 const UnicodeString& skeleton,
608
623 const UnicodeString& skeleton,
624 const Locale &locale,
626
643 const UnicodeString& skeleton,
644 const Locale &locale,
646
647
655 static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
656
662 virtual UBool isLenient(void) const;
663
684 virtual void setLenient(UBool lenient);
685
686
691 virtual UBool isCalendarLenient(void) const;
692
693
703 virtual void setCalendarLenient(UBool lenient);
704
705
714 virtual const Calendar* getCalendar(void) const;
715
726
734 virtual void setCalendar(const Calendar& newCalendar);
735
736
743 virtual const NumberFormat* getNumberFormat(void) const;
744
752
759
765 virtual const TimeZone& getTimeZone(void) const;
766
774
780 virtual void setTimeZone(const TimeZone& zone);
781
792
804
819
830
831protected:
839
845
851
859
867
868
869private:
870
880
881
886
887
888 UDisplayContext fCapitalizationContext;
889 friend class DateFmtKeyByStyle;
890
891public:
892#ifndef U_HIDE_OBSOLETE_API
899 {
900 // Obsolete; use UDateFormatField instead
901 kEraField = UDAT_ERA_FIELD,
902 kYearField = UDAT_YEAR_FIELD,
903 kMonthField = UDAT_MONTH_FIELD,
904 kDateField = UDAT_DATE_FIELD,
905 kHourOfDay1Field = UDAT_HOUR_OF_DAY1_FIELD,
906 kHourOfDay0Field = UDAT_HOUR_OF_DAY0_FIELD,
907 kMinuteField = UDAT_MINUTE_FIELD,
908 kSecondField = UDAT_SECOND_FIELD,
909 kMillisecondField = UDAT_FRACTIONAL_SECOND_FIELD,
910 kDayOfWeekField = UDAT_DAY_OF_WEEK_FIELD,
911 kDayOfYearField = UDAT_DAY_OF_YEAR_FIELD,
912 kDayOfWeekInMonthField = UDAT_DAY_OF_WEEK_IN_MONTH_FIELD,
913 kWeekOfYearField = UDAT_WEEK_OF_YEAR_FIELD,
914 kWeekOfMonthField = UDAT_WEEK_OF_MONTH_FIELD,
915 kAmPmField = UDAT_AM_PM_FIELD,
916 kHour1Field = UDAT_HOUR1_FIELD,
917 kHour0Field = UDAT_HOUR0_FIELD,
918 kTimezoneField = UDAT_TIMEZONE_FIELD,
919 kYearWOYField = UDAT_YEAR_WOY_FIELD,
920 kDOWLocalField = UDAT_DOW_LOCAL_FIELD,
921 kExtendedYearField = UDAT_EXTENDED_YEAR_FIELD,
922 kJulianDayField = UDAT_JULIAN_DAY_FIELD,
923 kMillisecondsInDayField = UDAT_MILLISECONDS_IN_DAY_FIELD,
924
925 // Obsolete; use UDateFormatField instead
926 ERA_FIELD = UDAT_ERA_FIELD,
927 YEAR_FIELD = UDAT_YEAR_FIELD,
928 MONTH_FIELD = UDAT_MONTH_FIELD,
929 DATE_FIELD = UDAT_DATE_FIELD,
930 HOUR_OF_DAY1_FIELD = UDAT_HOUR_OF_DAY1_FIELD,
931 HOUR_OF_DAY0_FIELD = UDAT_HOUR_OF_DAY0_FIELD,
932 MINUTE_FIELD = UDAT_MINUTE_FIELD,
933 SECOND_FIELD = UDAT_SECOND_FIELD,
934 MILLISECOND_FIELD = UDAT_FRACTIONAL_SECOND_FIELD,
935 DAY_OF_WEEK_FIELD = UDAT_DAY_OF_WEEK_FIELD,
936 DAY_OF_YEAR_FIELD = UDAT_DAY_OF_YEAR_FIELD,
937 DAY_OF_WEEK_IN_MONTH_FIELD = UDAT_DAY_OF_WEEK_IN_MONTH_FIELD,
938 WEEK_OF_YEAR_FIELD = UDAT_WEEK_OF_YEAR_FIELD,
939 WEEK_OF_MONTH_FIELD = UDAT_WEEK_OF_MONTH_FIELD,
940 AM_PM_FIELD = UDAT_AM_PM_FIELD,
941 HOUR1_FIELD = UDAT_HOUR1_FIELD,
942 HOUR0_FIELD = UDAT_HOUR0_FIELD,
943 TIMEZONE_FIELD = UDAT_TIMEZONE_FIELD
944 };
945#endif /* U_HIDE_OBSOLETE_API */
946};
947
949
950#endif /* #if !UCONFIG_NO_FORMATTING */
951
952#endif // _DATEFMT
953//eof
C++ API: Calendar object.
Calendar is an abstract base class for converting between a UDate object and a set of integer fields ...
Definition calendar.h:202
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition datefmt.h:150
virtual UBool getBooleanAttribute(UDateFormatBooleanAttribute attr, UErrorCode &status) const
Returns a boolean from this DateFormat May return U_UNSUPPORTED_ERROR if this instance does not suppo...
virtual UDate parse(const UnicodeString &text, UErrorCode &status) const
Parse a date/time string.
DateFormat()
Default constructor.
virtual ~DateFormat()
Destructor.
Calendar * fCalendar
The calendar that DateFormat uses to produce the time field values needed to implement date/time form...
Definition datefmt.h:858
virtual const TimeZone & getTimeZone(void) const
Returns a reference to the TimeZone used by this DateFormat's calendar.
static UnicodeString getBestPattern(const Locale &locale, const UnicodeString &skeleton, UErrorCode &status)
Returns the best pattern given a skeleton and locale.
static DateFormat * createDateInstance(EStyle style=kDefault, const Locale &aLocale=Locale::getDefault())
Creates a date formatter with the given formatting style for the given const locale.
virtual UnicodeString & format(Calendar &cal, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const
Formats a date into a date/time string.
NumberFormat * fNumberFormat
The number formatter that DateFormat uses to format numbers in dates and times.
Definition datefmt.h:866
static const Locale * getAvailableLocales(int32_t &count)
Gets the set of locales for which DateFormats are installed.
virtual const NumberFormat * getNumberFormat(void) const
Gets the number formatter which this date/time formatter uses to format and parse the numeric portion...
static DateFormat * createInstanceForSkeleton(Calendar *calendarToAdopt, const UnicodeString &skeleton, const Locale &locale, UErrorCode &status)
Creates a date/time formatter for the given skeleton and locale.
virtual void setCalendarLenient(UBool lenient)
Specifies whether encapsulated Calendar date/time parsing is to be lenient.
DateFormat(const DateFormat &)
Copy constructor.
virtual UBool operator==(const Format &) const
Equality operator.
UnicodeString & format(UDate date, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const
Formats a UDate into a date/time string.
virtual UDisplayContext getContext(UDisplayContextType type, UErrorCode &status) const
Get the formatter's UDisplayContext value for the specified UDisplayContextType, such as UDISPCTX_TYP...
UnicodeString & format(UDate date, UnicodeString &appendTo) const
Formats a UDate into a date/time string.
virtual DateFormat & setBooleanAttribute(UDateFormatBooleanAttribute attr, UBool newvalue, UErrorCode &status)
Sets an boolean attribute on this DateFormat.
virtual UBool isCalendarLenient(void) const
Returns whether date/time parsing in the encapsulated Calendar object processing is lenient.
virtual void setLenient(UBool lenient)
Specifies whether date/time parsing is to be lenient.
virtual const Calendar * getCalendar(void) const
Gets the calendar associated with this date/time formatter.
virtual void setTimeZone(const TimeZone &zone)
Sets the time zone for the calendar of this DateFormat object.
virtual void adoptNumberFormat(NumberFormat *formatToAdopt)
Allows you to set the number formatter.
virtual void setCalendar(const Calendar &newCalendar)
Set the calendar to be used by this date format.
static DateFormat * createInstance(void)
Create a default date/time formatter that uses the SHORT style for both the date and the time.
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const
Format an object to produce a string.
virtual void parse(const UnicodeString &text, Calendar &cal, ParsePosition &pos) const =0
Parse a date/time string beginning at the given parse position.
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Format an object to produce a string.
static DateFormat * createDateTimeInstance(EStyle dateStyle=kDefault, EStyle timeStyle=kDefault, const Locale &aLocale=Locale::getDefault())
Creates a date/time formatter with the given formatting styles for the given locale.
virtual void setNumberFormat(const NumberFormat &newNumberFormat)
Allows you to set the number formatter.
virtual void setContext(UDisplayContext value, UErrorCode &status)
Set a particular UDisplayContext value in the formatter, such as UDISPCTX_CAPITALIZATION_FOR_STANDALO...
DateFormat & operator=(const DateFormat &)
Default assignment operator.
virtual UnicodeString & format(Calendar &cal, UnicodeString &appendTo, FieldPosition &fieldPosition) const =0
Formats a date into a date/time string.
static DateFormat * createInstanceForSkeleton(const UnicodeString &skeleton, const Locale &locale, UErrorCode &status)
Creates a date/time formatter for the given skeleton and locale.
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const
Parse a string to produce an object.
EStyle
Constants for various style patterns.
Definition datefmt.h:161
UDate parse(const UnicodeString &text, ParsePosition &pos) const
Parse a date/time string beginning at the given parse position.
EField
Field selector for FieldPosition for DateFormat fields.
Definition datefmt.h:899
virtual void adoptCalendar(Calendar *calendarToAdopt)
Set the calendar to be used by this date format.
virtual UBool isLenient(void) const
Returns whether both date/time parsing in the encapsulated Calendar object and DateFormat whitespace ...
virtual void adoptTimeZone(TimeZone *zoneToAdopt)
Sets the time zone for the calendar of this DateFormat object.
static DateFormat * createInstanceForSkeleton(const UnicodeString &skeleton, UErrorCode &status)
Creates a date/time formatter for the given skeleton and default locale.
static DateFormat * createTimeInstance(EStyle style=kDefault, const Locale &aLocale=Locale::getDefault())
Creates a time formatter with the given formatting style for the given locale.
UnicodeString & format(UDate date, UnicodeString &appendTo, FieldPosition &fieldPosition) const
Formats a UDate into a date/time string.
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition fpositer.h:55
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition fieldpos.h:108
Base class for all formats.
Definition format.h:96
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition fmtable.h:62
"Smart pointer" base class; do not use directly: use LocalPointer etc.
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:188
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition parsepos.h:49
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition timezone.h:131
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:287
C++: internal template EnumSet<>
C++ API: Base class for all formats.
C++ API: Locale ID object.
C++ API: Compatibility APIs for number formatting.
C API: DateFormat.
@ UDAT_AM_PM_FIELD
FieldPosition and UFieldPosition selector for 'a' field alignment, corresponding to the UCAL_AM_PM fi...
Definition udat.h:606
@ UDAT_TIMEZONE_FIELD
FieldPosition and UFieldPosition selector for 'z' field alignment, corresponding to the UCAL_ZONE_OFF...
Definition udat.h:632
@ UDAT_DOW_LOCAL_FIELD
FieldPosition and UFieldPosition selector for 'e' field alignment, corresponding to the UCAL_DOW_LOCA...
Definition udat.h:646
@ UDAT_DATE_FIELD
FieldPosition and UFieldPosition selector for 'd' field alignment, corresponding to the UCAL_DATE fie...
Definition udat.h:517
@ UDAT_MONTH_FIELD
FieldPosition and UFieldPosition selector for 'M' field alignment, corresponding to the UCAL_MONTH fi...
Definition udat.h:510
@ UDAT_JULIAN_DAY_FIELD
FieldPosition and UFieldPosition selector for 'g' field alignment, corresponding to the UCAL_JULIAN_D...
Definition udat.h:660
@ UDAT_EXTENDED_YEAR_FIELD
FieldPosition and UFieldPosition selector for 'u' field alignment, corresponding to the UCAL_EXTENDED...
Definition udat.h:653
@ UDAT_DAY_OF_WEEK_FIELD
FieldPosition and UFieldPosition selector for 'E' field alignment, corresponding to the UCAL_DAY_OF_W...
Definition udat.h:571
@ UDAT_MILLISECONDS_IN_DAY_FIELD
FieldPosition and UFieldPosition selector for 'A' field alignment, corresponding to the UCAL_MILLISEC...
Definition udat.h:667
@ UDAT_YEAR_FIELD
FieldPosition and UFieldPosition selector for 'y' field alignment, corresponding to the UCAL_YEAR fie...
Definition udat.h:503
@ UDAT_ERA_FIELD
FieldPosition and UFieldPosition selector for 'G' field alignment, corresponding to the UCAL_ERA fiel...
Definition udat.h:496
@ UDAT_DAY_OF_YEAR_FIELD
FieldPosition and UFieldPosition selector for 'D' field alignment, corresponding to the UCAL_DAY_OF_Y...
Definition udat.h:578
@ UDAT_WEEK_OF_MONTH_FIELD
FieldPosition and UFieldPosition selector for 'W' field alignment, corresponding to the UCAL_WEEK_OF_...
Definition udat.h:599
@ UDAT_FRACTIONAL_SECOND_FIELD
FieldPosition and UFieldPosition selector for 'S' field alignment, corresponding to the UCAL_MILLISEC...
Definition udat.h:564
@ 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:585
@ UDAT_SECOND_FIELD
FieldPosition and UFieldPosition selector for 's' field alignment, corresponding to the UCAL_SECOND f...
Definition udat.h:549
@ UDAT_HOUR1_FIELD
FieldPosition and UFieldPosition selector for 'h' field alignment, corresponding to the UCAL_HOUR fie...
Definition udat.h:615
@ UDAT_MINUTE_FIELD
FieldPosition and UFieldPosition selector for 'm' field alignment, corresponding to the UCAL_MINUTE f...
Definition udat.h:542
@ UDAT_HOUR0_FIELD
FieldPosition and UFieldPosition selector for 'K' field alignment, corresponding to the UCAL_HOUR fie...
Definition udat.h:624
@ UDAT_YEAR_WOY_FIELD
FieldPosition and UFieldPosition selector for 'Y' field alignment, corresponding to the UCAL_YEAR_WOY...
Definition udat.h:639
@ UDAT_WEEK_OF_YEAR_FIELD
FieldPosition and UFieldPosition selector for 'w' field alignment, corresponding to the UCAL_WEEK_OF_...
Definition udat.h:592
@ UDAT_HOUR_OF_DAY0_FIELD
FieldPosition and UFieldPosition selector for 'H' field alignment, corresponding to the UCAL_HOUR_OF_...
Definition udat.h:535
@ UDAT_HOUR_OF_DAY1_FIELD
FieldPosition and UFieldPosition selector for 'k' field alignment, corresponding to the UCAL_HOUR_OF_...
Definition udat.h:526
UDateFormatBooleanAttribute
DateFormat boolean attributes.
Definition udat.h:878
@ UDAT_BOOLEAN_ATTRIBUTE_COUNT
One more than the highest normal UDateFormatBooleanAttribute value.
Definition udat.h:909
C API: Display context types (enum values)
UDisplayContextType
Display context types, for getting values of a particular setting.
UDisplayContext
Display context settings.
int8_t UBool
The ICU boolean type.
Definition umachine.h:236
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition utypes.h:396
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:360
double UDate
Date and Time data type.
Definition utypes.h:203
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:138
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:137