ICU 57.1 57.1
datefmt.h
Go to the documentation of this file.
1/*
2 ********************************************************************************
3 * Copyright (C) 1997-2016, 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
41class TimeZone;
43
44// explicit template instantiation. see digitlst.h
45#if defined (_MSC_VER)
47 0,
49#endif
50
148public:
149
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
242 FieldPosition& pos,
243 UErrorCode& status) const;
244
263 UErrorCode& status) const;
299 FieldPosition& fieldPosition) const = 0;
300
322 UErrorCode& status) const;
353
370 UErrorCode& status) 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
482 ParsePosition& pos) const;
483
507 virtual void parseObject(const UnicodeString& source,
509 ParsePosition& parse_pos) const;
510
519
533
551
571 EStyle timeStyle = kDefault,
573
574#ifndef U_HIDE_INTERNAL_API
584 const Locale &locale,
585 const UnicodeString &skeleton,
587#endif /* U_HIDE_INTERNAL_API */
588
603 const UnicodeString& skeleton,
605
620 const UnicodeString& skeleton,
621 const Locale &locale,
623
640 const UnicodeString& skeleton,
641 const Locale &locale,
643
644
653
659 virtual UBool isLenient(void) const;
660
681 virtual void setLenient(UBool lenient);
682
683
688 virtual UBool isCalendarLenient(void) const;
689
690
700 virtual void setCalendarLenient(UBool lenient);
701
702
711 virtual const Calendar* getCalendar(void) const;
712
723
731 virtual void setCalendar(const Calendar& newCalendar);
732
733
740 virtual const NumberFormat* getNumberFormat(void) const;
741
749
756
762 virtual const TimeZone& getTimeZone(void) const;
763
771
777 virtual void setTimeZone(const TimeZone& zone);
778
789
801
816
827
828protected:
836
842
848
856
864
865
866private:
867
877
878
883
884
885 UDisplayContext fCapitalizationContext;
886 friend class DateFmtKeyByStyle;
887
888public:
889#ifndef U_HIDE_OBSOLETE_API
896 {
897 // Obsolete; use UDateFormatField instead
898 kEraField = UDAT_ERA_FIELD,
899 kYearField = UDAT_YEAR_FIELD,
900 kMonthField = UDAT_MONTH_FIELD,
901 kDateField = UDAT_DATE_FIELD,
902 kHourOfDay1Field = UDAT_HOUR_OF_DAY1_FIELD,
903 kHourOfDay0Field = UDAT_HOUR_OF_DAY0_FIELD,
904 kMinuteField = UDAT_MINUTE_FIELD,
905 kSecondField = UDAT_SECOND_FIELD,
906 kMillisecondField = UDAT_FRACTIONAL_SECOND_FIELD,
907 kDayOfWeekField = UDAT_DAY_OF_WEEK_FIELD,
908 kDayOfYearField = UDAT_DAY_OF_YEAR_FIELD,
909 kDayOfWeekInMonthField = UDAT_DAY_OF_WEEK_IN_MONTH_FIELD,
910 kWeekOfYearField = UDAT_WEEK_OF_YEAR_FIELD,
911 kWeekOfMonthField = UDAT_WEEK_OF_MONTH_FIELD,
912 kAmPmField = UDAT_AM_PM_FIELD,
913 kHour1Field = UDAT_HOUR1_FIELD,
914 kHour0Field = UDAT_HOUR0_FIELD,
915 kTimezoneField = UDAT_TIMEZONE_FIELD,
916 kYearWOYField = UDAT_YEAR_WOY_FIELD,
917 kDOWLocalField = UDAT_DOW_LOCAL_FIELD,
918 kExtendedYearField = UDAT_EXTENDED_YEAR_FIELD,
919 kJulianDayField = UDAT_JULIAN_DAY_FIELD,
920 kMillisecondsInDayField = UDAT_MILLISECONDS_IN_DAY_FIELD,
921
922 // Obsolete; use UDateFormatField instead
923 ERA_FIELD = UDAT_ERA_FIELD,
924 YEAR_FIELD = UDAT_YEAR_FIELD,
925 MONTH_FIELD = UDAT_MONTH_FIELD,
926 DATE_FIELD = UDAT_DATE_FIELD,
927 HOUR_OF_DAY1_FIELD = UDAT_HOUR_OF_DAY1_FIELD,
928 HOUR_OF_DAY0_FIELD = UDAT_HOUR_OF_DAY0_FIELD,
929 MINUTE_FIELD = UDAT_MINUTE_FIELD,
930 SECOND_FIELD = UDAT_SECOND_FIELD,
931 MILLISECOND_FIELD = UDAT_FRACTIONAL_SECOND_FIELD,
932 DAY_OF_WEEK_FIELD = UDAT_DAY_OF_WEEK_FIELD,
933 DAY_OF_YEAR_FIELD = UDAT_DAY_OF_YEAR_FIELD,
934 DAY_OF_WEEK_IN_MONTH_FIELD = UDAT_DAY_OF_WEEK_IN_MONTH_FIELD,
935 WEEK_OF_YEAR_FIELD = UDAT_WEEK_OF_YEAR_FIELD,
936 WEEK_OF_MONTH_FIELD = UDAT_WEEK_OF_MONTH_FIELD,
937 AM_PM_FIELD = UDAT_AM_PM_FIELD,
938 HOUR1_FIELD = UDAT_HOUR1_FIELD,
939 HOUR0_FIELD = UDAT_HOUR0_FIELD,
940 TIMEZONE_FIELD = UDAT_TIMEZONE_FIELD
941 };
942#endif /* U_HIDE_OBSOLETE_API */
943};
944
946
947#endif /* #if !UCONFIG_NO_FORMATTING */
948
949#endif // _DATEFMT
950//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:200
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition datefmt.h:147
virtual void setContext(UDisplayContext value, UErrorCode &status)
Set a particular UDisplayContext value in the formatter, such as UDISPCTX_CAPITALIZATION_FOR_STANDALO...
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:855
virtual UnicodeString & format(Calendar &cal, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const
Formats a date into a date/time string.
EField
Field selector for FieldPosition for DateFormat fields.
Definition datefmt.h:896
UnicodeString & format(UDate date, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const
Formats a UDate into a date/time string.
virtual void setTimeZone(const TimeZone &zone)
Sets the time zone for the calendar of this DateFormat object.
NumberFormat * fNumberFormat
The number formatter that DateFormat uses to format numbers in dates and times.
Definition datefmt.h:863
virtual const TimeZone & getTimeZone(void) const
Returns a reference to the TimeZone used by this DateFormat's calendar.
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.
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.
UnicodeString & format(UDate date, UnicodeString &appendTo, FieldPosition &fieldPosition) const
Formats a UDate into a date/time string.
static DateFormat * createTimeInstance(EStyle style=kDefault, const Locale &aLocale=Locale::getDefault())
Creates a time formatter with the given formatting style for the given locale.
virtual UnicodeString & format(Calendar &cal, UnicodeString &appendTo, FieldPosition &fieldPosition) const =0
Formats a date into a date/time string.
virtual void setCalendar(const Calendar &newCalendar)
Set the calendar to be used by this date format.
virtual void adoptNumberFormat(NumberFormat *formatToAdopt)
Allows you to set the number formatter.
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const
Format an object to produce a string.
virtual void setLenient(UBool lenient)
Specifies whether date/time parsing is to be lenient.
virtual UBool isCalendarLenient(void) const
Returns whether date/time parsing in the encapsulated Calendar object processing is lenient.
UDate parse(const UnicodeString &text, ParsePosition &pos) const
Parse a date/time string beginning at the given parse position.
virtual void parse(const UnicodeString &text, Calendar &cal, ParsePosition &pos) const =0
Parse a date/time string beginning at the given parse position.
virtual void adoptTimeZone(TimeZone *zoneToAdopt)
Sets the time zone for the calendar of this DateFormat object.
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Format an object to produce a string.
virtual void adoptCalendar(Calendar *calendarToAdopt)
Set the calendar to be used by this date format.
virtual UDisplayContext getContext(UDisplayContextType type, UErrorCode &status) const
Get the formatter's UDisplayContext value for the specified UDisplayContextType, such as UDISPCTX_TYP...
static DateFormat * createInstance(void)
Create a default date/time formatter that uses the SHORT style for both the date and the time.
static UnicodeString getBestPattern(const Locale &locale, const UnicodeString &skeleton, UErrorCode &status)
Returns the best pattern given a skeleton and locale.
EStyle
Constants for various style patterns.
Definition datefmt.h:158
static DateFormat * createInstanceForSkeleton(const UnicodeString &skeleton, UErrorCode &status)
Creates a date/time formatter for the given skeleton and default locale.
virtual const NumberFormat * getNumberFormat(void) const
Gets the number formatter which this date/time formatter uses to format and parse the numeric portion...
virtual UBool operator==(const Format &) const
Equality operator.
DateFormat(const DateFormat &)
Copy constructor.
virtual void setCalendarLenient(UBool lenient)
Specifies whether encapsulated Calendar date/time parsing is to be lenient.
virtual const Calendar * getCalendar(void) const
Gets the calendar associated with this date/time formatter.
virtual DateFormat & setBooleanAttribute(UDateFormatBooleanAttribute attr, UBool newvalue, UErrorCode &status)
Sets an boolean attribute on this DateFormat.
virtual void setNumberFormat(const NumberFormat &newNumberFormat)
Allows you to set the number formatter.
static DateFormat * createInstanceForSkeleton(Calendar *calendarToAdopt, const UnicodeString &skeleton, const Locale &locale, UErrorCode &status)
Creates a date/time formatter for the given 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.
static DateFormat * createInstanceForSkeleton(const UnicodeString &skeleton, const Locale &locale, UErrorCode &status)
Creates a date/time formatter for the given skeleton and locale.
UnicodeString & format(UDate date, UnicodeString &appendTo) const
Formats a UDate into a date/time string.
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const
Parse a string to produce an object.
DateFormat & operator=(const DateFormat &)
Default assignment operator.
static const Locale * getAvailableLocales(int32_t &count)
Gets the set of locales for which DateFormats are installed.
virtual UBool isLenient(void) const
Returns whether both date/time parsing in the encapsulated Calendar object and DateFormat whitespace ...
This class provides flexible generation of date format patterns, like "yy-MM-dd".
Definition dtptngen.h:50
enum bitset for boolean fields.
Definition enumset.h:31
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition fpositer.h:53
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition fieldpos.h:106
Base class for all formats.
Definition format.h:94
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition fmtable.h:66
"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:185
static const Locale & getDefault(void)
Common methods of getting the current default Locale.
Abstract base class for all number formats.
Definition numfmt.h:167
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition parsepos.h:47
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition timezone.h:129
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:294
C++: internal template EnumSet<>
C++ API: Base class for all formats.
C++ API: Locale ID object.
C++ API: Abstract base class for all number formats.
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:604
@ UDAT_TIMEZONE_FIELD
FieldPosition and UFieldPosition selector for 'z' field alignment, corresponding to the UCAL_ZONE_OFF...
Definition udat.h:630
@ UDAT_DOW_LOCAL_FIELD
FieldPosition and UFieldPosition selector for 'e' field alignment, corresponding to the UCAL_DOW_LOCA...
Definition udat.h:644
@ UDAT_DATE_FIELD
FieldPosition and UFieldPosition selector for 'd' field alignment, corresponding to the UCAL_DATE fie...
Definition udat.h:515
@ UDAT_MONTH_FIELD
FieldPosition and UFieldPosition selector for 'M' field alignment, corresponding to the UCAL_MONTH fi...
Definition udat.h:508
@ UDAT_JULIAN_DAY_FIELD
FieldPosition and UFieldPosition selector for 'g' field alignment, corresponding to the UCAL_JULIAN_D...
Definition udat.h:658
@ UDAT_EXTENDED_YEAR_FIELD
FieldPosition and UFieldPosition selector for 'u' field alignment, corresponding to the UCAL_EXTENDED...
Definition udat.h:651
@ 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_MILLISECONDS_IN_DAY_FIELD
FieldPosition and UFieldPosition selector for 'A' field alignment, corresponding to the UCAL_MILLISEC...
Definition udat.h:665
@ UDAT_YEAR_FIELD
FieldPosition and UFieldPosition selector for 'y' field alignment, corresponding to the UCAL_YEAR fie...
Definition udat.h:501
@ UDAT_ERA_FIELD
FieldPosition and UFieldPosition selector for 'G' field alignment, corresponding to the UCAL_ERA fiel...
Definition udat.h:494
@ UDAT_DAY_OF_YEAR_FIELD
FieldPosition and UFieldPosition selector for 'D' field alignment, corresponding to the UCAL_DAY_OF_Y...
Definition udat.h:576
@ UDAT_WEEK_OF_MONTH_FIELD
FieldPosition and UFieldPosition selector for 'W' field alignment, corresponding to the UCAL_WEEK_OF_...
Definition udat.h:597
@ UDAT_FRACTIONAL_SECOND_FIELD
FieldPosition and UFieldPosition selector for 'S' field alignment, corresponding to the UCAL_MILLISEC...
Definition udat.h:562
@ 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
@ UDAT_SECOND_FIELD
FieldPosition and UFieldPosition selector for 's' field alignment, corresponding to the UCAL_SECOND f...
Definition udat.h:547
@ UDAT_HOUR1_FIELD
FieldPosition and UFieldPosition selector for 'h' field alignment, corresponding to the UCAL_HOUR fie...
Definition udat.h:613
@ UDAT_MINUTE_FIELD
FieldPosition and UFieldPosition selector for 'm' field alignment, corresponding to the UCAL_MINUTE f...
Definition udat.h:540
@ UDAT_HOUR0_FIELD
FieldPosition and UFieldPosition selector for 'K' field alignment, corresponding to the UCAL_HOUR fie...
Definition udat.h:622
@ UDAT_YEAR_WOY_FIELD
FieldPosition and UFieldPosition selector for 'Y' field alignment, corresponding to the UCAL_YEAR_WOY...
Definition udat.h:637
@ UDAT_WEEK_OF_YEAR_FIELD
FieldPosition and UFieldPosition selector for 'w' field alignment, corresponding to the UCAL_WEEK_OF_...
Definition udat.h:590
@ UDAT_HOUR_OF_DAY0_FIELD
FieldPosition and UFieldPosition selector for 'H' field alignment, corresponding to the UCAL_HOUR_OF_...
Definition udat.h:533
@ UDAT_HOUR_OF_DAY1_FIELD
FieldPosition and UFieldPosition selector for 'k' field alignment, corresponding to the UCAL_HOUR_OF_...
Definition udat.h:524
UDateFormatBooleanAttribute
DateFormat boolean attributes.
Definition udat.h:879
@ UDAT_BOOLEAN_ATTRIBUTE_COUNT
count boolean date format constants
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.
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:476
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:358
double UDate
Date and Time data type.
Definition utypes.h:201
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:130
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:129