Loading...
Searching...
No Matches
dtitvfmt.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) 2008-2016, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*
* File DTITVFMT.H
*
*******************************************************************************
*/
#ifndef __DTITVFMT_H__
#define __DTITVFMT_H__
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#if !UCONFIG_NO_FORMATTING
#include "unicode/ucal.h"
#include "unicode/smpdtfmt.h"
#include "unicode/dtintrv.h"
#include "unicode/dtitvinf.h"
#include "unicode/dtptngen.h"
#include "unicode/formattedvalue.h"
#include "unicode/udisplaycontext.h"
U_NAMESPACE_BEGIN
class FormattedDateIntervalData;
class DateIntervalFormat;
class U_I18N_API FormattedDateInterval : public UMemory, public FormattedValue {
public:
FormattedDateInterval() : fData(nullptr), fErrorCode(U_INVALID_STATE_ERROR) {}
FormattedDateInterval(FormattedDateInterval&& src) noexcept;
virtual ~FormattedDateInterval() override;
FormattedDateInterval(const FormattedDateInterval&) = delete;
FormattedDateInterval& operator=(const FormattedDateInterval&) = delete;
FormattedDateInterval& operator=(FormattedDateInterval&& src) noexcept;
UnicodeString toString(UErrorCode& status) const override;
UnicodeString toTempString(UErrorCode& status) const override;
Appendable &appendTo(Appendable& appendable, UErrorCode& status) const override;
UBool nextPosition(ConstrainedFieldPosition& cfpos, UErrorCode& status) const override;
private:
FormattedDateIntervalData *fData;
UErrorCode fErrorCode;
explicit FormattedDateInterval(FormattedDateIntervalData *results)
: fData(results), fErrorCode(U_ZERO_ERROR) {}
explicit FormattedDateInterval(UErrorCode errorCode)
: fData(nullptr), fErrorCode(errorCode) {}
friend class DateIntervalFormat;
};
class U_I18N_API_CLASS DateIntervalFormat : public Format {
public:
U_I18N_API static DateIntervalFormat* createInstance(const UnicodeString& skeleton,
UErrorCode& status);
U_I18N_API static DateIntervalFormat* createInstance(const UnicodeString& skeleton,
const Locale& locale,
UErrorCode& status);
U_I18N_API static DateIntervalFormat* createInstance(const UnicodeString& skeleton,
const DateIntervalInfo& dtitvinf,
UErrorCode& status);
U_I18N_API static DateIntervalFormat* createInstance(const UnicodeString& skeleton,
const Locale& locale,
const DateIntervalInfo& dtitvinf,
UErrorCode& status);
U_I18N_API virtual ~DateIntervalFormat();
U_I18N_API virtual DateIntervalFormat* clone() const override;
U_I18N_API virtual bool operator==(const Format& other) const override;
U_I18N_API bool operator!=(const Format& other) const;
using Format::format;
U_I18N_API virtual UnicodeString& format(const Formattable& obj,
UnicodeString& appendTo,
FieldPosition& fieldPosition,
UErrorCode& status) const override;
U_I18N_API UnicodeString& format(const DateInterval* dtInterval,
UnicodeString& appendTo,
FieldPosition& fieldPosition,
UErrorCode& status) const;
U_I18N_API FormattedDateInterval formatToValue(const DateInterval& dtInterval,
UErrorCode& status) const;
U_I18N_API UnicodeString& format(Calendar& fromCalendar,
Calendar& toCalendar,
UnicodeString& appendTo,
FieldPosition& fieldPosition,
UErrorCode& status) const;
U_I18N_API FormattedDateInterval formatToValue(Calendar& fromCalendar,
Calendar& toCalendar,
UErrorCode& status) const;
U_I18N_API virtual void parseObject(const UnicodeString& source,
Formattable& result,
ParsePosition& parse_pos) const override;
U_I18N_API const DateIntervalInfo* getDateIntervalInfo() const;
U_I18N_API void setDateIntervalInfo(const DateIntervalInfo& newIntervalPatterns, UErrorCode& status);
U_I18N_API const DateFormat* getDateFormat() const;
U_I18N_API virtual const TimeZone& getTimeZone() const;
U_I18N_API virtual void adoptTimeZone(TimeZone* zoneToAdopt);
U_I18N_API virtual void setTimeZone(const TimeZone& zone);
U_I18N_API virtual void setContext(UDisplayContext value, UErrorCode& status);
U_I18N_API virtual UDisplayContext getContext(UDisplayContextType type, UErrorCode& status) const;
U_I18N_API static UClassID getStaticClassID();
U_I18N_API virtual UClassID getDynamicClassID() const override;
protected:
DateIntervalFormat(const DateIntervalFormat&);
DateIntervalFormat& operator=(const DateIntervalFormat&);
private:
/*
* This is for ICU internal use only. Please do not use.
* Save the interval pattern information.
* Interval pattern consists of 2 single date patterns and the separator.
* For example, interval pattern "MMM d - MMM d, yyyy" consists
* a single date pattern "MMM d", another single date pattern "MMM d, yyyy",
* and a separator "-".
* The pattern is divided into 2 parts. For above example,
* the first part is "MMM d - ", and the second part is "MMM d, yyyy".
* Also, the first date appears in an interval pattern could be
* the earlier date or the later date.
* And such information is saved in the interval pattern as well.
*/
struct PatternInfo {
UnicodeString firstPart;
UnicodeString secondPart;
UBool laterDateFirst;
};
DateIntervalFormat();
DateIntervalFormat(const Locale& locale, DateIntervalInfo* dtItvInfo,
const UnicodeString* skeleton, UErrorCode& status);
U_I18N_API static DateIntervalFormat* create(const Locale& locale,
DateIntervalInfo* dtitvinf,
const UnicodeString* skeleton,
UErrorCode& status);
void fallbackFormatRange(
Calendar& fromCalendar,
Calendar& toCalendar,
UnicodeString& appendTo,
int8_t& firstIndex,
FieldPositionHandler& fphandler,
UErrorCode& status) const;
UnicodeString& fallbackFormat(Calendar& fromCalendar,
Calendar& toCalendar,
UBool fromToOnSameDay,
UnicodeString& appendTo,
int8_t& firstIndex,
FieldPositionHandler& fphandler,
UErrorCode& status) const;
void initializePattern(UErrorCode& status);
void setFallbackPattern(UCalendarDateFields field,
const UnicodeString& skeleton,
UErrorCode& status);
UnicodeString normalizeHourMetacharacters(const UnicodeString& skeleton) const;
U_I18N_API static void getDateTimeSkeleton(const UnicodeString& skeleton,
UnicodeString& date,
UnicodeString& normalizedDate,
UnicodeString& time,
UnicodeString& normalizedTime);
UBool setSeparateDateTimePtn(const UnicodeString& dateSkeleton,
const UnicodeString& timeSkeleton);
UBool setIntervalPattern(UCalendarDateFields field,
const UnicodeString* skeleton,
const UnicodeString* bestSkeleton,
int8_t differenceInfo,
UnicodeString* extendedSkeleton = nullptr,
UnicodeString* extendedBestSkeleton = nullptr);
U_I18N_API static void adjustFieldWidth(const UnicodeString& inputSkeleton,
const UnicodeString& bestMatchSkeleton,
const UnicodeString& bestMatchIntervalPattern,
int8_t differenceInfo,
UBool suppressDayPeriodField,
UnicodeString& adjustedIntervalPattern);
U_I18N_API static void findReplaceInPattern(UnicodeString& targetString,
const UnicodeString& strToReplace,
const UnicodeString& strToReplaceWith);
void concatSingleDate2TimeInterval(UnicodeString& format,
const UnicodeString& datePattern,
UCalendarDateFields field,
UErrorCode& status);
U_I18N_API static UBool fieldExistsInSkeleton(UCalendarDateFields field,
const UnicodeString& skeleton);
U_I18N_API static int32_t splitPatternInto2Part(const UnicodeString& intervalPattern);
void setIntervalPattern(UCalendarDateFields field,
const UnicodeString& intervalPattern);
void setIntervalPattern(UCalendarDateFields field,
const UnicodeString& intervalPattern,
UBool laterDateFirst);
void setPatternInfo(UCalendarDateFields field,
const UnicodeString* firstPart,
const UnicodeString* secondPart,
UBool laterDateFirst);
UnicodeString& formatImpl(Calendar& fromCalendar,
Calendar& toCalendar,
UnicodeString& appendTo,
int8_t& firstIndex,
FieldPositionHandler& fphandler,
UErrorCode& status) const ;
UnicodeString& formatIntervalImpl(const DateInterval& dtInterval,
UnicodeString& appendTo,
int8_t& firstIndex,
FieldPositionHandler& fphandler,
UErrorCode& status) const;
// from calendar field to pattern letter
static const char16_t fgCalendarFieldToPatternLetter[];
DateIntervalInfo* fInfo;
SimpleDateFormat* fDateFormat;
Calendar* fFromCalendar;
Calendar* fToCalendar;
Locale fLocale;
UnicodeString fSkeleton;
PatternInfo fIntervalPatterns[DateIntervalInfo::kIPI_MAX_INDEX];
UnicodeString* fDatePattern;
UnicodeString* fTimePattern;
UnicodeString* fDateTimeFormat;
UDisplayContext fCapitalizationContext;
};
inline bool
DateIntervalFormat::operator!=(const Format& other) const {
return !operator==(other);
}
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_FORMATTING */
#endif /* U_SHOW_CPLUSPLUS_API */
#endif // _DTITVFMT_H__
//eof
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::ConstrainedFieldPosition
Represents a span of a string containing a given field.
Definition formattedvalue.h:41
icu::DateFormat
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition datefmt.h:144
icu::DateIntervalFormat
DateIntervalFormat is a class for formatting and parsing date intervals in a language-independent man...
Definition dtitvfmt.h:300
icu::DateIntervalFormat::operator!=
U_I18N_API bool operator!=(const Format &other) const
Return true if the given Format objects are not semantically equal.
Definition dtitvfmt.h:1170
icu::DateIntervalFormat::setDateIntervalInfo
U_I18N_API void setDateIntervalInfo(const DateIntervalInfo &newIntervalPatterns, UErrorCode &status)
Set the date time interval patterns.
icu::DateIntervalFormat::createInstance
static U_I18N_API DateIntervalFormat * createInstance(const UnicodeString &skeleton, UErrorCode &status)
Construct a DateIntervalFormat from skeleton and the default locale.
icu::DateIntervalFormat::clone
virtual U_I18N_API DateIntervalFormat * clone() const override
Clone this Format object polymorphically.
icu::DateIntervalFormat::createInstance
static U_I18N_API DateIntervalFormat * createInstance(const UnicodeString &skeleton, const Locale &locale, const DateIntervalInfo &dtitvinf, UErrorCode &status)
Construct a DateIntervalFormat from skeleton a DateIntervalInfo, and the given locale.
icu::DateIntervalFormat::getStaticClassID
static U_I18N_API UClassID getStaticClassID()
Return the class ID for this class.
icu::DateIntervalFormat::getDateIntervalInfo
U_I18N_API const DateIntervalInfo * getDateIntervalInfo() const
Gets the date time interval patterns.
icu::DateIntervalFormat::formatToValue
U_I18N_API FormattedDateInterval formatToValue(Calendar &fromCalendar, Calendar &toCalendar, UErrorCode &status) const
Format 2 Calendars to produce a FormattedDateInterval.
icu::DateIntervalFormat::operator==
virtual U_I18N_API bool operator==(const Format &other) const override
Return true if the given Format objects are semantically equal.
icu::DateIntervalFormat::format
U_I18N_API UnicodeString & format(Calendar &fromCalendar, Calendar &toCalendar, UnicodeString &appendTo, FieldPosition &fieldPosition, UErrorCode &status) const
Format 2 Calendars to produce a string.
icu::DateIntervalFormat::setContext
virtual U_I18N_API void setContext(UDisplayContext value, UErrorCode &status)
Set a particular UDisplayContext value in the formatter, such as UDISPCTX_CAPITALIZATION_FOR_STANDALO...
icu::DateIntervalFormat::setTimeZone
virtual U_I18N_API void setTimeZone(const TimeZone &zone)
Sets the time zone for the calendar used by this DateIntervalFormat object.
icu::DateIntervalFormat::createInstance
static U_I18N_API DateIntervalFormat * createInstance(const UnicodeString &skeleton, const Locale &locale, UErrorCode &status)
Construct a DateIntervalFormat from skeleton and a given locale.
icu::DateIntervalFormat::getContext
virtual U_I18N_API UDisplayContext getContext(UDisplayContextType type, UErrorCode &status) const
Get the formatter's UDisplayContext value for the specified UDisplayContextType, such as UDISPCTX_TYP...
icu::DateIntervalFormat::format
U_I18N_API UnicodeString & format(const DateInterval *dtInterval, UnicodeString &appendTo, FieldPosition &fieldPosition, UErrorCode &status) const
Format a DateInterval to produce a string.
icu::DateIntervalFormat::getDateFormat
U_I18N_API const DateFormat * getDateFormat() const
Gets the date formatter.
icu::DateIntervalFormat::getTimeZone
virtual U_I18N_API const TimeZone & getTimeZone() const
Returns a reference to the TimeZone used by this DateIntervalFormat's calendar.
icu::DateIntervalFormat::parseObject
virtual U_I18N_API void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const override
Date interval parsing is not supported.
icu::DateIntervalFormat::DateIntervalFormat
DateIntervalFormat(const DateIntervalFormat &)
Copy constructor.
icu::DateIntervalFormat::formatToValue
U_I18N_API FormattedDateInterval formatToValue(const DateInterval &dtInterval, UErrorCode &status) const
Format a DateInterval to produce a FormattedDateInterval.
icu::DateIntervalFormat::adoptTimeZone
virtual U_I18N_API void adoptTimeZone(TimeZone *zoneToAdopt)
Sets the time zone for the calendar used by this DateIntervalFormat object.
icu::DateIntervalFormat::operator=
DateIntervalFormat & operator=(const DateIntervalFormat &)
Assignment operator.
icu::DateIntervalFormat::format
virtual U_I18N_API UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &fieldPosition, UErrorCode &status) const override
Format an object to produce a string.
icu::DateIntervalFormat::getDynamicClassID
virtual U_I18N_API UClassID getDynamicClassID() const override
Returns a unique class ID POLYMORPHICALLY.
icu::DateIntervalFormat::~DateIntervalFormat
virtual U_I18N_API ~DateIntervalFormat()
Destructor.
icu::DateIntervalFormat::createInstance
static U_I18N_API DateIntervalFormat * createInstance(const UnicodeString &skeleton, const DateIntervalInfo &dtitvinf, UErrorCode &status)
Construct a DateIntervalFormat from skeleton DateIntervalInfo, and default locale.
icu::DateIntervalInfo
DateIntervalInfo is a public class for encapsulating localizable date time interval patterns.
Definition dtitvinf.h:154
icu::DateInterval
This class represents a date interval.
Definition dtintrv.h:36
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::operator!=
U_I18N_API bool operator!=(const Format &other) const
Return true if the given Format objects are not semantically equal.
Definition format.h:123
icu::Format::Format
U_I18N_API Format()
Default constructor for subclass use only.
icu::Format::format
U_I18N_API UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition fmtable.h:63
icu::FormattedDateInterval
An immutable class containing the result of a date interval formatting operation.
Definition dtitvfmt.h:59
icu::FormattedDateInterval::operator=
FormattedDateInterval & operator=(FormattedDateInterval &&src) noexcept
Move assignment: Leaves the source FormattedDateInterval in an undefined state.
icu::FormattedDateInterval::FormattedDateInterval
FormattedDateInterval(const FormattedDateInterval &)=delete
Copying not supported; use move constructor instead.
icu::FormattedDateInterval::nextPosition
UBool nextPosition(ConstrainedFieldPosition &cfpos, UErrorCode &status) const override
Iterates over field positions in the FormattedValue.
icu::FormattedDateInterval::~FormattedDateInterval
virtual ~FormattedDateInterval() override
Destruct an instance of FormattedDateInterval.
icu::FormattedDateInterval::FormattedDateInterval
FormattedDateInterval()
Default constructor; makes an empty FormattedDateInterval.
Definition dtitvfmt.h:65
icu::FormattedDateInterval::toString
UnicodeString toString(UErrorCode &status) const override
Returns the formatted string as a self-contained UnicodeString.
icu::FormattedDateInterval::toTempString
UnicodeString toTempString(UErrorCode &status) const override
Returns the formatted string as a read-only alias to memory owned by the FormattedValue.
icu::FormattedDateInterval::appendTo
Appendable & appendTo(Appendable &appendable, UErrorCode &status) const override
Appends the formatted string to an Appendable.
icu::FormattedDateInterval::operator=
FormattedDateInterval & operator=(const FormattedDateInterval &)=delete
Copying not supported; use move assignment instead.
icu::FormattedDateInterval::FormattedDateInterval
FormattedDateInterval(FormattedDateInterval &&src) noexcept
Move constructor: Leaves the source FormattedDateInterval in an undefined state.
icu::FormattedValue
An abstract formatted value: a string with associated field attributes.
Definition formattedvalue.h:241
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:198
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 is a concrete class for formatting and parsing dates in a language-independent manne...
Definition smpdtfmt.h:385
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
dtintrv.h
C++ API: Date Interval data type.
dtitvinf.h
C++ API: Date/Time interval patterns for formatting date/time interval.
dtptngen.h
C++ API: Date/Time Pattern Generator.
formattedvalue.h
C++ API: Abstract operations for localized strings.
smpdtfmt.h
C++ API: Format and parse dates in a language-independent manner.
ucal.h
C API: Calendar.
UCalendarDateFields
UCalendarDateFields
Possible fields in a UCalendar.
Definition ucal.h:202
udisplaycontext.h
C API: Display context types (enum values).
UDisplayContextType
UDisplayContextType
Display context types, for getting values of a particular setting.
Definition udisplaycontext.h:27
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_INVALID_STATE_ERROR
@ U_INVALID_STATE_ERROR
Requested operation can not be completed with ICU in its current state.
Definition utypes.h:573
U_ZERO_ERROR
@ U_ZERO_ERROR
No error, no warning.
Definition utypes.h:544
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