ICU 76.1 76.1
Loading...
Searching...
No Matches
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"
37
43U_NAMESPACE_BEGIN
44
45class TimeZone;
46class DateTimePatternGenerator;
47
53#if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN && !defined(U_IN_DOXYGEN)
54template class U_I18N_API EnumSet<UDateFormatBooleanAttribute,
55 0,
57#endif
157public:
158
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 override = 0;
233
238 virtual bool operator==(const Format&) const override;
239
240
241 using Format::format;
242
258 UnicodeString& appendTo,
259 FieldPosition& pos,
260 UErrorCode& status) const override;
261
278 UnicodeString& appendTo,
280 UErrorCode& status) const override;
315 UnicodeString& appendTo,
316 FieldPosition& fieldPosition) const = 0;
317
337 UnicodeString& appendTo,
339 UErrorCode& status) const;
368 UnicodeString& appendTo,
370
385 UnicodeString& appendTo,
387 UErrorCode& status) 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
499 ParsePosition& pos) const;
500
524 virtual void parseObject(const UnicodeString& source,
526 ParsePosition& parse_pos) const override;
527
536
549 const Locale& aLocale = Locale::getDefault());
550
567 const Locale& aLocale = Locale::getDefault());
568
588 EStyle timeStyle = kDefault,
589 const Locale& aLocale = Locale::getDefault());
590
591#ifndef U_HIDE_INTERNAL_API
601 const Locale &locale,
602 const UnicodeString &skeleton,
604#endif /* U_HIDE_INTERNAL_API */
605
620 const UnicodeString& skeleton,
622
637 const UnicodeString& skeleton,
638 const Locale &locale,
640
657 const UnicodeString& skeleton,
658 const Locale &locale,
660
661
670
676 virtual UBool isLenient() const;
677
698 virtual void setLenient(UBool lenient);
699
700
705 virtual UBool isCalendarLenient() const;
706
716 virtual void setCalendarLenient(UBool lenient);
717
718
727 virtual const Calendar* getCalendar() const;
728
739
747 virtual void setCalendar(const Calendar& newCalendar);
748
749
756 virtual const NumberFormat* getNumberFormat() const;
757
765
772
778 virtual const TimeZone& getTimeZone() const;
779
787
793 virtual void setTimeZone(const TimeZone& zone);
794
805
817
832
843
844protected:
852
858
864
872
880
881
882private:
883
893
894
899
900
901 UDisplayContext fCapitalizationContext;
902 friend class DateFmtKeyByStyle;
903
904public:
905#ifndef U_HIDE_OBSOLETE_API
912 {
913 // Obsolete; use UDateFormatField instead
914 kEraField = UDAT_ERA_FIELD,
915 kYearField = UDAT_YEAR_FIELD,
916 kMonthField = UDAT_MONTH_FIELD,
917 kDateField = UDAT_DATE_FIELD,
918 kHourOfDay1Field = UDAT_HOUR_OF_DAY1_FIELD,
919 kHourOfDay0Field = UDAT_HOUR_OF_DAY0_FIELD,
920 kMinuteField = UDAT_MINUTE_FIELD,
921 kSecondField = UDAT_SECOND_FIELD,
922 kMillisecondField = UDAT_FRACTIONAL_SECOND_FIELD,
923 kDayOfWeekField = UDAT_DAY_OF_WEEK_FIELD,
924 kDayOfYearField = UDAT_DAY_OF_YEAR_FIELD,
925 kDayOfWeekInMonthField = UDAT_DAY_OF_WEEK_IN_MONTH_FIELD,
926 kWeekOfYearField = UDAT_WEEK_OF_YEAR_FIELD,
927 kWeekOfMonthField = UDAT_WEEK_OF_MONTH_FIELD,
928 kAmPmField = UDAT_AM_PM_FIELD,
929 kHour1Field = UDAT_HOUR1_FIELD,
930 kHour0Field = UDAT_HOUR0_FIELD,
931 kTimezoneField = UDAT_TIMEZONE_FIELD,
932 kYearWOYField = UDAT_YEAR_WOY_FIELD,
933 kDOWLocalField = UDAT_DOW_LOCAL_FIELD,
934 kExtendedYearField = UDAT_EXTENDED_YEAR_FIELD,
935 kJulianDayField = UDAT_JULIAN_DAY_FIELD,
936 kMillisecondsInDayField = UDAT_MILLISECONDS_IN_DAY_FIELD,
937
938 // Obsolete; use UDateFormatField instead
939 ERA_FIELD = UDAT_ERA_FIELD,
940 YEAR_FIELD = UDAT_YEAR_FIELD,
941 MONTH_FIELD = UDAT_MONTH_FIELD,
942 DATE_FIELD = UDAT_DATE_FIELD,
943 HOUR_OF_DAY1_FIELD = UDAT_HOUR_OF_DAY1_FIELD,
944 HOUR_OF_DAY0_FIELD = UDAT_HOUR_OF_DAY0_FIELD,
945 MINUTE_FIELD = UDAT_MINUTE_FIELD,
946 SECOND_FIELD = UDAT_SECOND_FIELD,
947 MILLISECOND_FIELD = UDAT_FRACTIONAL_SECOND_FIELD,
948 DAY_OF_WEEK_FIELD = UDAT_DAY_OF_WEEK_FIELD,
949 DAY_OF_YEAR_FIELD = UDAT_DAY_OF_YEAR_FIELD,
950 DAY_OF_WEEK_IN_MONTH_FIELD = UDAT_DAY_OF_WEEK_IN_MONTH_FIELD,
951 WEEK_OF_YEAR_FIELD = UDAT_WEEK_OF_YEAR_FIELD,
952 WEEK_OF_MONTH_FIELD = UDAT_WEEK_OF_MONTH_FIELD,
953 AM_PM_FIELD = UDAT_AM_PM_FIELD,
954 HOUR1_FIELD = UDAT_HOUR1_FIELD,
955 HOUR0_FIELD = UDAT_HOUR0_FIELD,
956 TIMEZONE_FIELD = UDAT_TIMEZONE_FIELD
957 };
958#endif /* U_HIDE_OBSOLETE_API */
959};
960
961U_NAMESPACE_END
962
963#endif /* #if !UCONFIG_NO_FORMATTING */
964
965#endif /* U_SHOW_CPLUSPLUS_API */
966
967#endif // _DATEFMT
968//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:189
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition datefmt.h:156
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 bool operator==(const Format &) const override
Equality operator.
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:871
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:879
static const Locale * getAvailableLocales(int32_t &count)
Gets the set of locales for which DateFormats are installed.
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const override
Parse a string to produce an object.
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.
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 void setLenient(UBool lenient)
Specifies whether date/time parsing is to be lenient.
virtual const Calendar * getCalendar() const
Gets the calendar associated with this date/time formatter.
virtual UBool isCalendarLenient() const
Returns whether date/time parsing in the encapsulated Calendar object processing is lenient.
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 const TimeZone & getTimeZone() const
Returns a reference to the TimeZone used by this DateFormat's calendar.
virtual void setCalendar(const Calendar &newCalendar)
Set the calendar to be used by this date format.
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const override
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.
static DateFormat * createInstance()
Create a default date/time formatter that uses the SHORT style for both the date and the time.
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 UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const override
Format an object to produce a string.
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 DateFormat * clone() const override=0
Clones this object polymorphically.
EStyle
Constants for various style patterns.
Definition datefmt.h:167
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:912
virtual void adoptCalendar(Calendar *calendarToAdopt)
Set the calendar to be used by this date format.
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.
virtual const NumberFormat * getNumberFormat() const
Gets the number formatter which this date/time formatter uses to format and parse the numeric portion...
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.
virtual UBool isLenient() const
Returns whether both date/time parsing in the encapsulated Calendar object and DateFormat whitespace ...
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition fpositer.h:58
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition fieldpos.h:110
Base class for all formats.
Definition format.h:98
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition fmtable.h:63
"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:195
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition parsepos.h:52
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition timezone.h:133
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:296
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:631
@ UDAT_TIMEZONE_FIELD
FieldPosition and UFieldPosition selector for 'z' field alignment, corresponding to the UCAL_ZONE_OFF...
Definition udat.h:657
@ UDAT_DOW_LOCAL_FIELD
FieldPosition and UFieldPosition selector for 'e' field alignment, corresponding to the UCAL_DOW_LOCA...
Definition udat.h:671
@ UDAT_DATE_FIELD
FieldPosition and UFieldPosition selector for 'd' field alignment, corresponding to the UCAL_DATE fie...
Definition udat.h:542
@ UDAT_MONTH_FIELD
FieldPosition and UFieldPosition selector for 'M' field alignment, corresponding to the UCAL_MONTH fi...
Definition udat.h:535
@ UDAT_JULIAN_DAY_FIELD
FieldPosition and UFieldPosition selector for 'g' field alignment, corresponding to the UCAL_JULIAN_D...
Definition udat.h:685
@ UDAT_EXTENDED_YEAR_FIELD
FieldPosition and UFieldPosition selector for 'u' field alignment, corresponding to the UCAL_EXTENDED...
Definition udat.h:678
@ UDAT_DAY_OF_WEEK_FIELD
FieldPosition and UFieldPosition selector for 'E' field alignment, corresponding to the UCAL_DAY_OF_W...
Definition udat.h:596
@ UDAT_MILLISECONDS_IN_DAY_FIELD
FieldPosition and UFieldPosition selector for 'A' field alignment, corresponding to the UCAL_MILLISEC...
Definition udat.h:692
@ UDAT_YEAR_FIELD
FieldPosition and UFieldPosition selector for 'y' field alignment, corresponding to the UCAL_YEAR fie...
Definition udat.h:528
@ UDAT_ERA_FIELD
FieldPosition and UFieldPosition selector for 'G' field alignment, corresponding to the UCAL_ERA fiel...
Definition udat.h:521
@ 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_WEEK_OF_MONTH_FIELD
FieldPosition and UFieldPosition selector for 'W' field alignment, corresponding to the UCAL_WEEK_OF_...
Definition udat.h:624
@ UDAT_FRACTIONAL_SECOND_FIELD
FieldPosition and UFieldPosition selector for 'S' field alignment, corresponding to the UCAL_MILLISEC...
Definition udat.h:589
@ 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_SECOND_FIELD
FieldPosition and UFieldPosition selector for 's' field alignment, corresponding to the UCAL_SECOND f...
Definition udat.h:574
@ UDAT_HOUR1_FIELD
FieldPosition and UFieldPosition selector for 'h' field alignment, corresponding to the UCAL_HOUR fie...
Definition udat.h:640
@ UDAT_MINUTE_FIELD
FieldPosition and UFieldPosition selector for 'm' field alignment, corresponding to the UCAL_MINUTE f...
Definition udat.h:567
@ UDAT_HOUR0_FIELD
FieldPosition and UFieldPosition selector for 'K' field alignment, corresponding to the UCAL_HOUR fie...
Definition udat.h:649
@ UDAT_YEAR_WOY_FIELD
FieldPosition and UFieldPosition selector for 'Y' field alignment, corresponding to the UCAL_YEAR_WOY...
Definition udat.h:664
@ 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
FieldPosition and UFieldPosition selector for 'H' field alignment, corresponding to the UCAL_HOUR_OF_...
Definition udat.h:560
@ UDAT_HOUR_OF_DAY1_FIELD
FieldPosition and UFieldPosition selector for 'k' field alignment, corresponding to the UCAL_HOUR_OF_...
Definition udat.h:551
UDateFormatBooleanAttribute
DateFormat boolean attributes.
Definition udat.h:917
@ UDAT_BOOLEAN_ATTRIBUTE_COUNT
One more than the highest normal UDateFormatBooleanAttribute value.
Definition udat.h:949
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, a signed-byte integer.
Definition umachine.h:247
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:430
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:316
double UDate
Date and Time data type.
Definition utypes.h:218