Loading...
Searching...
No Matches
smpdtfmt.h
Go to the documentation of this file.
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
* Copyright (C) 1997-2016, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*
* File SMPDTFMT.H
*
* Modification History:
*
* Date Name Description
* 02/19/97 aliu Converted from java.
* 07/09/97 helena Make ParsePosition into a class.
* 07/21/98 stephen Added GMT_PLUS, GMT_MINUS
* Changed setTwoDigitStartDate to set2DigitYearStart
* Changed getTwoDigitStartDate to get2DigitYearStart
* Removed subParseLong
* Removed getZoneIndex (added in DateFormatSymbols)
* 06/14/99 stephen Removed fgTimeZoneDataSuffix
* 10/14/99 aliu Updated class doc to describe 2-digit year parsing
* {j28 4182066}.
*******************************************************************************
*/
#ifndef SMPDTFMT_H
#define SMPDTFMT_H
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#if !UCONFIG_NO_FORMATTING
#include "unicode/datefmt.h"
#include "unicode/udisplaycontext.h"
#include "unicode/tzfmt.h" /* for UTimeZoneFormatTimeType */
#include "unicode/brkiter.h"
U_NAMESPACE_BEGIN
class DateFormatSymbols;
class DateFormat;
class MessageFormat;
class FieldPositionHandler;
class TimeZoneFormat;
class SharedNumberFormat;
class SimpleDateFormatMutableNFs;
class DateIntervalFormat;
namespace number {
class LocalizedNumberFormatter;
class SimpleNumberFormatter;
}
class U_I18N_API_CLASS SimpleDateFormat: public DateFormat {
public:
U_I18N_API SimpleDateFormat(UErrorCode& status);
U_I18N_API SimpleDateFormat(const UnicodeString& pattern,
UErrorCode& status);
U_I18N_API SimpleDateFormat(const UnicodeString& pattern,
const UnicodeString& override,
UErrorCode& status);
U_I18N_API SimpleDateFormat(const UnicodeString& pattern, const Locale& locale, UErrorCode& status);
U_I18N_API SimpleDateFormat(const UnicodeString& pattern,
const UnicodeString& override,
const Locale& locale,
UErrorCode& status);
U_I18N_API SimpleDateFormat(const UnicodeString& pattern,
DateFormatSymbols* formatDataToAdopt,
UErrorCode& status);
U_I18N_API SimpleDateFormat(const UnicodeString& pattern,
const DateFormatSymbols& formatData,
UErrorCode& status);
U_I18N_API SimpleDateFormat(const SimpleDateFormat&);
U_I18N_API SimpleDateFormat& operator=(const SimpleDateFormat&);
U_I18N_API virtual ~SimpleDateFormat();
U_I18N_API virtual SimpleDateFormat* clone() const override;
U_I18N_API virtual bool operator==(const Format& other) const override;
using DateFormat::format;
U_I18N_API virtual UnicodeString& format(Calendar& cal,
UnicodeString& appendTo,
FieldPosition& pos) const override;
U_I18N_API virtual UnicodeString& format(Calendar& cal,
UnicodeString& appendTo,
FieldPositionIterator* posIter,
UErrorCode& status) const override;
using DateFormat::parse;
U_I18N_API virtual void parse(const UnicodeString& text,
Calendar& cal,
ParsePosition& pos) const override;
U_I18N_API virtual void set2DigitYearStart(UDate d, UErrorCode& status);
U_I18N_API UDate get2DigitYearStart(UErrorCode& status) const;
U_I18N_API virtual UnicodeString& toPattern(UnicodeString& result) const;
U_I18N_API virtual UnicodeString& toLocalizedPattern(UnicodeString& result,
UErrorCode& status) const;
U_I18N_API virtual void applyPattern(const UnicodeString& pattern);
U_I18N_API virtual void applyLocalizedPattern(const UnicodeString& pattern, UErrorCode& status);
U_I18N_API virtual const DateFormatSymbols* getDateFormatSymbols() const;
U_I18N_API virtual void adoptDateFormatSymbols(DateFormatSymbols* newFormatSymbols);
U_I18N_API virtual void setDateFormatSymbols(const DateFormatSymbols& newFormatSymbols);
U_I18N_API static UClassID getStaticClassID();
U_I18N_API virtual UClassID getDynamicClassID() const override;
U_I18N_API virtual void adoptCalendar(Calendar* calendarToAdopt) override;
/* Cannot use #ifndef U_HIDE_INTERNAL_API for the following methods since they are virtual */
U_I18N_API virtual void adoptTimeZoneFormat(TimeZoneFormat* timeZoneFormatToAdopt);
U_I18N_API virtual void setTimeZoneFormat(const TimeZoneFormat& newTimeZoneFormat);
U_I18N_API virtual const TimeZoneFormat* getTimeZoneFormat() const;
U_I18N_API virtual void setContext(UDisplayContext value, UErrorCode& status) override;
U_I18N_API void adoptNumberFormat(NumberFormat* formatToAdopt) override;
U_I18N_API void adoptNumberFormat(const UnicodeString& fields,
NumberFormat* formatToAdopt,
UErrorCode& status);
U_I18N_API const NumberFormat* getNumberFormatForField(char16_t field) const;
#ifndef U_HIDE_INTERNAL_API
U_I18N_API UBool isFieldUnitIgnored(UCalendarDateFields field) const;
U_I18N_API static UBool isFieldUnitIgnored(const UnicodeString& pattern, UCalendarDateFields field);
U_I18N_API const Locale& getSmpFmtLocale() const;
#endif /* U_HIDE_INTERNAL_API */
private:
friend class DateFormat;
friend class DateIntervalFormat;
void initializeDefaultCentury();
void initializeBooleanAttributes();
SimpleDateFormat() = delete; // default constructor not implemented
SimpleDateFormat(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
SimpleDateFormat(const Locale& locale, UErrorCode& status); // Use default pattern
UnicodeString& _format(Calendar& cal, UnicodeString& appendTo, FieldPositionHandler& handler, UErrorCode& status) const;
void subFormat(UnicodeString &appendTo,
char16_t ch,
int32_t count,
UDisplayContext capitalizationContext,
int32_t fieldNum,
char16_t fieldToOutput,
FieldPositionHandler& handler,
Calendar& cal,
UErrorCode& status) const; // in case of illegal argument
void zeroPaddingNumber(const NumberFormat *currentNumberFormat,
UnicodeString &appendTo,
int32_t value,
int32_t minDigits,
int32_t maxDigits) const;
static UBool isNumeric(char16_t formatChar, int32_t count);
static UBool isAtNumericField(const UnicodeString &pattern, int32_t patternOffset);
static UBool isAfterNonNumericField(const UnicodeString &pattern, int32_t patternOffset);
Calendar *initializeCalendar(TimeZone* adoptZone, const Locale& locale, UErrorCode& status);
void construct(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
void initialize(const Locale& locale, UErrorCode& status);
int32_t matchString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
const UnicodeString* stringArray, int32_t stringArrayCount,
const UnicodeString* monthPattern, Calendar& cal) const;
int32_t matchAlphaMonthStrings(const UnicodeString& text, int32_t start,
const UnicodeString* wideStringArray, const UnicodeString* shortStringArray,
int32_t stringArrayCount, Calendar& cal) const;
int32_t matchQuarterString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
const UnicodeString* stringArray, int32_t stringArrayCount, Calendar& cal) const;
int32_t matchDayPeriodStrings(const UnicodeString& text, int32_t start,
const UnicodeString* stringArray, int32_t stringArrayCount,
int32_t &dayPeriod) const;
static UBool matchLiterals(const UnicodeString &pattern, int32_t &patternOffset,
const UnicodeString &text, int32_t &textOffset,
UBool whitespaceLenient, UBool partialMatchLenient, UBool oldLeniency);
int32_t subParse(const UnicodeString& text, int32_t& start, char16_t ch, int32_t count,
UBool obeyCount, UBool allowNegative, UBool ambiguousYear[], int32_t& saveHebrewMonth, Calendar& cal,
int32_t patLoc, MessageFormat * numericLeapMonthFormatter, UTimeZoneFormatTimeType *tzTimeType,
int32_t *dayPeriod=nullptr) const;
void parseInt(const UnicodeString& text,
Formattable& number,
ParsePosition& pos,
UBool allowNegative,
const NumberFormat *fmt) const;
void parseInt(const UnicodeString& text,
Formattable& number,
int32_t maxDigits,
ParsePosition& pos,
UBool allowNegative,
const NumberFormat *fmt) const;
int32_t checkIntSuffix(const UnicodeString& text, int32_t start,
int32_t patLoc, UBool isNegative) const;
int32_t countDigits(const UnicodeString& text, int32_t start, int32_t end) const;
static void translatePattern(const UnicodeString& originalPattern,
UnicodeString& translatedPattern,
const UnicodeString& from,
const UnicodeString& to,
UErrorCode& status);
void parseAmbiguousDatesAsAfter(UDate startDate, UErrorCode& status);
int32_t compareSimpleAffix(const UnicodeString& affix,
const UnicodeString& input,
int32_t pos) const;
int32_t skipPatternWhiteSpace(const UnicodeString& text, int32_t pos) const;
int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos) const;
void initSimpleNumberFormatter(UErrorCode &status);
void initNumberFormatters(const Locale &locale,UErrorCode &status);
void processOverrideString(const Locale &locale, const UnicodeString &str, int8_t type, UErrorCode &status);
static const UCalendarDateFields fgPatternIndexToCalendarField[];
static const UDateFormatField fgPatternIndexToDateFormatField[];
TimeZoneFormat *tzFormat(UErrorCode &status) const;
const NumberFormat* getNumberFormatByIndex(UDateFormatField index) const;
static const int32_t fgCalendarFieldToLevel[];
static int32_t getLevelFromChar(char16_t ch);
static UBool isSyntaxChar(char16_t ch);
UnicodeString fPattern;
UnicodeString fDateOverride;
UnicodeString fTimeOverride;
Locale fLocale;
DateFormatSymbols* fSymbols = nullptr; // Owned
TimeZoneFormat* fTimeZoneFormat = nullptr;
UDate fDefaultCenturyStart;
UBool fHasMinute;
UBool fHasSecond;
UBool fHasHanYearChar; // pattern contains the Han year character \u5E74
void parsePattern();
/*transient*/ int32_t fDefaultCenturyStartYear;
struct NSOverride : public UMemory {
const SharedNumberFormat *snf;
int32_t hash;
NSOverride *next;
void free();
NSOverride() : snf(nullptr), hash(0), next(nullptr) {
}
~NSOverride();
};
const SharedNumberFormat **fSharedNumberFormatters = nullptr;
const number::SimpleNumberFormatter* fSimpleNumberFormatter = nullptr;
UBool fHaveDefaultCentury;
const BreakIterator* fCapitalizationBrkIter = nullptr;
};
inline UDate
SimpleDateFormat::get2DigitYearStart(UErrorCode& /*status*/) const
{
return fDefaultCenturyStart;
}
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_FORMATTING */
#endif /* U_SHOW_CPLUSPLUS_API */
#endif // _SMPDTFMT
//eof
brkiter.h
C++ API: Break Iterator.
icu::Calendar
Calendar is an abstract base class for converting between a UDate object and a set of integer fields ...
Definition calendar.h:189
icu::DateFormatSymbols
DateFormatSymbols is a public class for encapsulating localizable date-time formatting data – includi...
Definition dtfmtsym.h:84
icu::DateFormat::format
virtual U_I18N_API UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const override
Format an object to produce a string.
icu::DateFormat::parse
virtual U_I18N_API UDate parse(const UnicodeString &text, UErrorCode &status) const
Parse a date/time string.
icu::DateFormat::EStyle
EStyle
Constants for various style patterns.
Definition datefmt.h:155
icu::FieldPositionIterator
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition fpositer.h:58
icu::FieldPosition
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition fieldpos.h:110
icu::Format
Base class for all formats.
Definition format.h:98
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition fmtable.h:63
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:198
icu::MessageFormat
Definition msgfmt.h:345
icu::NumberFormat
Definition numfmt.h:175
icu::ParsePosition
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition parsepos.h:52
icu::SimpleDateFormat::SimpleDateFormat
U_I18N_API SimpleDateFormat(const UnicodeString &pattern, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern and the default locale.
icu::SimpleDateFormat::isFieldUnitIgnored
static U_I18N_API UBool isFieldUnitIgnored(const UnicodeString &pattern, UCalendarDateFields field)
This is for ICU internal use only.
icu::SimpleDateFormat::adoptCalendar
virtual U_I18N_API void adoptCalendar(Calendar *calendarToAdopt) override
Set the calendar to be used by this date format.
icu::SimpleDateFormat::SimpleDateFormat
U_I18N_API SimpleDateFormat(const UnicodeString &pattern, const DateFormatSymbols &formatData, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern and locale-specific symbol data.
icu::SimpleDateFormat::setDateFormatSymbols
virtual U_I18N_API void setDateFormatSymbols(const DateFormatSymbols &newFormatSymbols)
Set the date/time formatting data.
icu::SimpleDateFormat::getSmpFmtLocale
U_I18N_API const Locale & getSmpFmtLocale() const
This is for ICU internal use only.
icu::SimpleDateFormat::get2DigitYearStart
U_I18N_API UDate get2DigitYearStart(UErrorCode &status) const
Get the start UDate used to interpret two-digit year strings.
Definition smpdtfmt.h:1313
icu::SimpleDateFormat::operator==
virtual U_I18N_API bool operator==(const Format &other) const override
Return true if the given Format objects are semantically equal.
icu::SimpleDateFormat::setContext
virtual U_I18N_API void setContext(UDisplayContext value, UErrorCode &status) override
Set a particular UDisplayContext value in the formatter, such as UDISPCTX_CAPITALIZATION_FOR_STANDALO...
icu::SimpleDateFormat::clone
virtual U_I18N_API SimpleDateFormat * clone() const override
Clone this Format object polymorphically.
icu::SimpleDateFormat::getNumberFormatForField
U_I18N_API const NumberFormat * getNumberFormatForField(char16_t field) const
Get the numbering system to be used for a particular field.
icu::SimpleDateFormat::setTimeZoneFormat
virtual U_I18N_API void setTimeZoneFormat(const TimeZoneFormat &newTimeZoneFormat)
Sets the TimeZoneFormat to be used by this date/time formatter.
icu::SimpleDateFormat::set2DigitYearStart
virtual U_I18N_API void set2DigitYearStart(UDate d, UErrorCode &status)
Set the start UDate used to interpret two-digit year strings.
icu::SimpleDateFormat::adoptNumberFormat
U_I18N_API void adoptNumberFormat(const UnicodeString &fields, NumberFormat *formatToAdopt, UErrorCode &status)
Allow the user to set the NumberFormat for several fields It can be a single field like: "y"(year) or...
icu::SimpleDateFormat::operator=
U_I18N_API SimpleDateFormat & operator=(const SimpleDateFormat &)
Assignment operator.
icu::SimpleDateFormat::applyPattern
virtual U_I18N_API void applyPattern(const UnicodeString &pattern)
Apply the given unlocalized pattern string to this date format.
icu::SimpleDateFormat::SimpleDateFormat
U_I18N_API SimpleDateFormat(UErrorCode &status)
Construct a SimpleDateFormat using the default pattern for the default locale.
icu::SimpleDateFormat::isFieldUnitIgnored
U_I18N_API UBool isFieldUnitIgnored(UCalendarDateFields field) const
This is for ICU internal use only.
icu::SimpleDateFormat::SimpleDateFormat
U_I18N_API SimpleDateFormat(const UnicodeString &pattern, const Locale &locale, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern and locale.
icu::SimpleDateFormat::SimpleDateFormat
U_I18N_API SimpleDateFormat(const UnicodeString &pattern, const UnicodeString &override, const Locale &locale, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern, numbering system override, and locale.
icu::SimpleDateFormat::format
virtual U_I18N_API UnicodeString & format(Calendar &cal, UnicodeString &appendTo, FieldPosition &pos) const override
Format a date or time, which is the standard millis since 24:00 GMT, Jan 1, 1970.
icu::SimpleDateFormat::adoptNumberFormat
U_I18N_API void adoptNumberFormat(NumberFormat *formatToAdopt) override
Overrides base class method and This method clears per field NumberFormat instances previously set by...
icu::SimpleDateFormat::SimpleDateFormat
U_I18N_API SimpleDateFormat(const UnicodeString &pattern, const UnicodeString &override, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern, numbering system override, and the default loca...
icu::SimpleDateFormat::toPattern
virtual U_I18N_API UnicodeString & toPattern(UnicodeString &result) const
Return a pattern string describing this date format.
icu::SimpleDateFormat::getDynamicClassID
virtual U_I18N_API UClassID getDynamicClassID() const override
Returns a unique class ID POLYMORPHICALLY.
icu::SimpleDateFormat::adoptTimeZoneFormat
virtual U_I18N_API void adoptTimeZoneFormat(TimeZoneFormat *timeZoneFormatToAdopt)
Sets the TimeZoneFormat to be used by this date/time formatter.
icu::SimpleDateFormat::parse
virtual U_I18N_API void parse(const UnicodeString &text, Calendar &cal, ParsePosition &pos) const override
Parse a date/time string beginning at the given parse position.
icu::SimpleDateFormat::getTimeZoneFormat
virtual U_I18N_API const TimeZoneFormat * getTimeZoneFormat() const
Gets the time zone format object associated with this date/time formatter.
icu::SimpleDateFormat::adoptDateFormatSymbols
virtual U_I18N_API void adoptDateFormatSymbols(DateFormatSymbols *newFormatSymbols)
Set the date/time formatting symbols.
icu::SimpleDateFormat::format
virtual U_I18N_API UnicodeString & format(Calendar &cal, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const override
Format a date or time, which is the standard millis since 24:00 GMT, Jan 1, 1970.
icu::SimpleDateFormat::toLocalizedPattern
virtual U_I18N_API UnicodeString & toLocalizedPattern(UnicodeString &result, UErrorCode &status) const
Return a localized pattern string describing this date format.
icu::SimpleDateFormat::getDateFormatSymbols
virtual U_I18N_API const DateFormatSymbols * getDateFormatSymbols() const
Gets the date/time formatting symbols (this is an object carrying the various strings and other symbo...
icu::SimpleDateFormat::SimpleDateFormat
U_I18N_API SimpleDateFormat(const UnicodeString &pattern, DateFormatSymbols *formatDataToAdopt, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern and locale-specific symbol data.
icu::SimpleDateFormat::~SimpleDateFormat
virtual U_I18N_API ~SimpleDateFormat()
Destructor.
icu::SimpleDateFormat::getStaticClassID
static U_I18N_API UClassID getStaticClassID()
Return the class ID for this class.
icu::SimpleDateFormat::applyLocalizedPattern
virtual U_I18N_API void applyLocalizedPattern(const UnicodeString &pattern, UErrorCode &status)
Apply the given localized pattern string to this date format.
icu::SimpleDateFormat::SimpleDateFormat
U_I18N_API SimpleDateFormat(const SimpleDateFormat &)
Copy constructor.
icu::TimeZoneFormat
TimeZoneFormat supports time zone display name formatting and parsing.
Definition tzfmt.h:274
icu::TimeZone
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition timezone.h:133
icu::UMemory
UMemory is the common ICU base class.
Definition uobject.h:115
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:303
datefmt.h
C++ API: Abstract class for converting dates.
tzfmt.h
C++ API: TimeZoneFormat.
UTimeZoneFormatTimeType
UTimeZoneFormatTimeType
Constants for time types used by TimeZoneFormat APIs for receiving time type (standard time,...
Definition tzfmt.h:206
UCalendarDateFields
UCalendarDateFields
Possible fields in a UCalendar.
Definition ucal.h:202
UDateFormatField
UDateFormatField
FieldPosition and UFieldPosition selectors for format fields defined by DateFormat and UDateFormat.
Definition udat.h:515
udisplaycontext.h
C API: Display context types (enum values).
UDisplayContext
UDisplayContext
Display context settings.
Definition udisplaycontext.h:64
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition umachine.h:269
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:509
U_I18N_API_CLASS
#define U_I18N_API_CLASS
Set to export library symbols from inside the i18n library, and to import them from outside,...
Definition utypes.h:457
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:316
UDate
double UDate
Date and Time data type.
Definition utypes.h:218