11cb0ef41Sopenharmony_ci// © 2016 and later: Unicode, Inc. and others. 21cb0ef41Sopenharmony_ci// License & terms of use: http://www.unicode.org/copyright.html 31cb0ef41Sopenharmony_ci/* 41cb0ef41Sopenharmony_ci ******************************************************************************* 51cb0ef41Sopenharmony_ci * Copyright (C) 2008-2016, International Business Machines Corporation and 61cb0ef41Sopenharmony_ci * others. All Rights Reserved. 71cb0ef41Sopenharmony_ci ******************************************************************************* 81cb0ef41Sopenharmony_ci * 91cb0ef41Sopenharmony_ci * File DTITVINF.H 101cb0ef41Sopenharmony_ci * 111cb0ef41Sopenharmony_ci ******************************************************************************* 121cb0ef41Sopenharmony_ci */ 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci#ifndef __DTITVINF_H__ 151cb0ef41Sopenharmony_ci#define __DTITVINF_H__ 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci#include "unicode/utypes.h" 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci#if U_SHOW_CPLUSPLUS_API 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci/** 221cb0ef41Sopenharmony_ci * \file 231cb0ef41Sopenharmony_ci * \brief C++ API: Date/Time interval patterns for formatting date/time interval 241cb0ef41Sopenharmony_ci */ 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci#if !UCONFIG_NO_FORMATTING 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci#include "unicode/udat.h" 291cb0ef41Sopenharmony_ci#include "unicode/locid.h" 301cb0ef41Sopenharmony_ci#include "unicode/ucal.h" 311cb0ef41Sopenharmony_ci#include "unicode/dtptngen.h" 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ciU_NAMESPACE_BEGIN 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci/** 361cb0ef41Sopenharmony_ci * DateIntervalInfo is a public class for encapsulating localizable 371cb0ef41Sopenharmony_ci * date time interval patterns. It is used by DateIntervalFormat. 381cb0ef41Sopenharmony_ci * 391cb0ef41Sopenharmony_ci * <P> 401cb0ef41Sopenharmony_ci * For most users, ordinary use of DateIntervalFormat does not need to create 411cb0ef41Sopenharmony_ci * DateIntervalInfo object directly. 421cb0ef41Sopenharmony_ci * DateIntervalFormat will take care of it when creating a date interval 431cb0ef41Sopenharmony_ci * formatter when user pass in skeleton and locale. 441cb0ef41Sopenharmony_ci * 451cb0ef41Sopenharmony_ci * <P> 461cb0ef41Sopenharmony_ci * For power users, who want to create their own date interval patterns, 471cb0ef41Sopenharmony_ci * or want to re-set date interval patterns, they could do so by 481cb0ef41Sopenharmony_ci * directly creating DateIntervalInfo and manipulating it. 491cb0ef41Sopenharmony_ci * 501cb0ef41Sopenharmony_ci * <P> 511cb0ef41Sopenharmony_ci * Logically, the interval patterns are mappings 521cb0ef41Sopenharmony_ci * from (skeleton, the_largest_different_calendar_field) 531cb0ef41Sopenharmony_ci * to (date_interval_pattern). 541cb0ef41Sopenharmony_ci * 551cb0ef41Sopenharmony_ci * <P> 561cb0ef41Sopenharmony_ci * A skeleton 571cb0ef41Sopenharmony_ci * <ol> 581cb0ef41Sopenharmony_ci * <li> 591cb0ef41Sopenharmony_ci * only keeps the field pattern letter and ignores all other parts 601cb0ef41Sopenharmony_ci * in a pattern, such as space, punctuations, and string literals. 611cb0ef41Sopenharmony_ci * <li> 621cb0ef41Sopenharmony_ci * hides the order of fields. 631cb0ef41Sopenharmony_ci * <li> 641cb0ef41Sopenharmony_ci * might hide a field's pattern letter length. 651cb0ef41Sopenharmony_ci * 661cb0ef41Sopenharmony_ci * For those non-digit calendar fields, the pattern letter length is 671cb0ef41Sopenharmony_ci * important, such as MMM, MMMM, and MMMMM; EEE and EEEE, 681cb0ef41Sopenharmony_ci * and the field's pattern letter length is honored. 691cb0ef41Sopenharmony_ci * 701cb0ef41Sopenharmony_ci * For the digit calendar fields, such as M or MM, d or dd, yy or yyyy, 711cb0ef41Sopenharmony_ci * the field pattern length is ignored and the best match, which is defined 721cb0ef41Sopenharmony_ci * in date time patterns, will be returned without honor the field pattern 731cb0ef41Sopenharmony_ci * letter length in skeleton. 741cb0ef41Sopenharmony_ci * </ol> 751cb0ef41Sopenharmony_ci * 761cb0ef41Sopenharmony_ci * <P> 771cb0ef41Sopenharmony_ci * The calendar fields we support for interval formatting are: 781cb0ef41Sopenharmony_ci * year, month, date, day-of-week, am-pm, hour, hour-of-day, and minute. 791cb0ef41Sopenharmony_ci * Those calendar fields can be defined in the following order: 801cb0ef41Sopenharmony_ci * year > month > date > am-pm > hour > minute 811cb0ef41Sopenharmony_ci * 821cb0ef41Sopenharmony_ci * The largest different calendar fields between 2 calendars is the 831cb0ef41Sopenharmony_ci * first different calendar field in above order. 841cb0ef41Sopenharmony_ci * 851cb0ef41Sopenharmony_ci * For example: the largest different calendar fields between "Jan 10, 2007" 861cb0ef41Sopenharmony_ci * and "Feb 20, 2008" is year. 871cb0ef41Sopenharmony_ci * 881cb0ef41Sopenharmony_ci * <P> 891cb0ef41Sopenharmony_ci * There is a set of pre-defined static skeleton strings. 901cb0ef41Sopenharmony_ci * There are pre-defined interval patterns for those pre-defined skeletons 911cb0ef41Sopenharmony_ci * in locales' resource files. 921cb0ef41Sopenharmony_ci * For example, for a skeleton UDAT_YEAR_ABBR_MONTH_DAY, which is "yMMMd", 931cb0ef41Sopenharmony_ci * in en_US, if the largest different calendar field between date1 and date2 941cb0ef41Sopenharmony_ci * is "year", the date interval pattern is "MMM d, yyyy - MMM d, yyyy", 951cb0ef41Sopenharmony_ci * such as "Jan 10, 2007 - Jan 10, 2008". 961cb0ef41Sopenharmony_ci * If the largest different calendar field between date1 and date2 is "month", 971cb0ef41Sopenharmony_ci * the date interval pattern is "MMM d - MMM d, yyyy", 981cb0ef41Sopenharmony_ci * such as "Jan 10 - Feb 10, 2007". 991cb0ef41Sopenharmony_ci * If the largest different calendar field between date1 and date2 is "day", 1001cb0ef41Sopenharmony_ci * the date interval pattern is "MMM d-d, yyyy", such as "Jan 10-20, 2007". 1011cb0ef41Sopenharmony_ci * 1021cb0ef41Sopenharmony_ci * For date skeleton, the interval patterns when year, or month, or date is 1031cb0ef41Sopenharmony_ci * different are defined in resource files. 1041cb0ef41Sopenharmony_ci * For time skeleton, the interval patterns when am/pm, or hour, or minute is 1051cb0ef41Sopenharmony_ci * different are defined in resource files. 1061cb0ef41Sopenharmony_ci * 1071cb0ef41Sopenharmony_ci * 1081cb0ef41Sopenharmony_ci * <P> 1091cb0ef41Sopenharmony_ci * There are 2 dates in interval pattern. For most locales, the first date 1101cb0ef41Sopenharmony_ci * in an interval pattern is the earlier date. There might be a locale in which 1111cb0ef41Sopenharmony_ci * the first date in an interval pattern is the later date. 1121cb0ef41Sopenharmony_ci * We use fallback format for the default order for the locale. 1131cb0ef41Sopenharmony_ci * For example, if the fallback format is "{0} - {1}", it means 1141cb0ef41Sopenharmony_ci * the first date in the interval pattern for this locale is earlier date. 1151cb0ef41Sopenharmony_ci * If the fallback format is "{1} - {0}", it means the first date is the 1161cb0ef41Sopenharmony_ci * later date. 1171cb0ef41Sopenharmony_ci * For a particular interval pattern, the default order can be overridden 1181cb0ef41Sopenharmony_ci * by prefixing "latestFirst:" or "earliestFirst:" to the interval pattern. 1191cb0ef41Sopenharmony_ci * For example, if the fallback format is "{0}-{1}", 1201cb0ef41Sopenharmony_ci * but for skeleton "yMMMd", the interval pattern when day is different is 1211cb0ef41Sopenharmony_ci * "latestFirst:d-d MMM yy", it means by default, the first date in interval 1221cb0ef41Sopenharmony_ci * pattern is the earlier date. But for skeleton "yMMMd", when day is different, 1231cb0ef41Sopenharmony_ci * the first date in "d-d MMM yy" is the later date. 1241cb0ef41Sopenharmony_ci * 1251cb0ef41Sopenharmony_ci * <P> 1261cb0ef41Sopenharmony_ci * The recommended way to create a DateIntervalFormat object is to pass in 1271cb0ef41Sopenharmony_ci * the locale. 1281cb0ef41Sopenharmony_ci * By using a Locale parameter, the DateIntervalFormat object is 1291cb0ef41Sopenharmony_ci * initialized with the pre-defined interval patterns for a given or 1301cb0ef41Sopenharmony_ci * default locale. 1311cb0ef41Sopenharmony_ci * <P> 1321cb0ef41Sopenharmony_ci * Users can also create DateIntervalFormat object 1331cb0ef41Sopenharmony_ci * by supplying their own interval patterns. 1341cb0ef41Sopenharmony_ci * It provides flexibility for power users. 1351cb0ef41Sopenharmony_ci * 1361cb0ef41Sopenharmony_ci * <P> 1371cb0ef41Sopenharmony_ci * After a DateIntervalInfo object is created, clients may modify 1381cb0ef41Sopenharmony_ci * the interval patterns using setIntervalPattern function as so desired. 1391cb0ef41Sopenharmony_ci * Currently, users can only set interval patterns when the following 1401cb0ef41Sopenharmony_ci * calendar fields are different: ERA, YEAR, MONTH, DATE, DAY_OF_MONTH, 1411cb0ef41Sopenharmony_ci * DAY_OF_WEEK, AM_PM, HOUR, HOUR_OF_DAY, MINUTE, SECOND, and MILLISECOND. 1421cb0ef41Sopenharmony_ci * Interval patterns when other calendar fields are different is not supported. 1431cb0ef41Sopenharmony_ci * <P> 1441cb0ef41Sopenharmony_ci * DateIntervalInfo objects are cloneable. 1451cb0ef41Sopenharmony_ci * When clients obtain a DateIntervalInfo object, 1461cb0ef41Sopenharmony_ci * they can feel free to modify it as necessary. 1471cb0ef41Sopenharmony_ci * <P> 1481cb0ef41Sopenharmony_ci * DateIntervalInfo are not expected to be subclassed. 1491cb0ef41Sopenharmony_ci * Data for a calendar is loaded out of resource bundles. 1501cb0ef41Sopenharmony_ci * Through ICU 4.4, date interval patterns are only supported in the Gregorian 1511cb0ef41Sopenharmony_ci * calendar; non-Gregorian calendars are supported from ICU 4.4.1. 1521cb0ef41Sopenharmony_ci * @stable ICU 4.0 1531cb0ef41Sopenharmony_ci**/ 1541cb0ef41Sopenharmony_ciclass U_I18N_API DateIntervalInfo final : public UObject { 1551cb0ef41Sopenharmony_cipublic: 1561cb0ef41Sopenharmony_ci /** 1571cb0ef41Sopenharmony_ci * Default constructor. 1581cb0ef41Sopenharmony_ci * It does not initialize any interval patterns except 1591cb0ef41Sopenharmony_ci * that it initialize default fall-back pattern as "{0} - {1}", 1601cb0ef41Sopenharmony_ci * which can be reset by setFallbackIntervalPattern(). 1611cb0ef41Sopenharmony_ci * It should be followed by setFallbackIntervalPattern() and 1621cb0ef41Sopenharmony_ci * setIntervalPattern(), 1631cb0ef41Sopenharmony_ci * and is recommended to be used only for power users who 1641cb0ef41Sopenharmony_ci * wants to create their own interval patterns and use them to create 1651cb0ef41Sopenharmony_ci * date interval formatter. 1661cb0ef41Sopenharmony_ci * @param status output param set to success/failure code on exit 1671cb0ef41Sopenharmony_ci * @internal ICU 4.0 1681cb0ef41Sopenharmony_ci */ 1691cb0ef41Sopenharmony_ci DateIntervalInfo(UErrorCode& status); 1701cb0ef41Sopenharmony_ci 1711cb0ef41Sopenharmony_ci 1721cb0ef41Sopenharmony_ci /** 1731cb0ef41Sopenharmony_ci * Construct DateIntervalInfo for the given locale, 1741cb0ef41Sopenharmony_ci * @param locale the interval patterns are loaded from the appropriate calendar 1751cb0ef41Sopenharmony_ci * data (specified calendar or default calendar) in this locale. 1761cb0ef41Sopenharmony_ci * @param status output param set to success/failure code on exit 1771cb0ef41Sopenharmony_ci * @stable ICU 4.0 1781cb0ef41Sopenharmony_ci */ 1791cb0ef41Sopenharmony_ci DateIntervalInfo(const Locale& locale, UErrorCode& status); 1801cb0ef41Sopenharmony_ci 1811cb0ef41Sopenharmony_ci 1821cb0ef41Sopenharmony_ci /** 1831cb0ef41Sopenharmony_ci * Copy constructor. 1841cb0ef41Sopenharmony_ci * @stable ICU 4.0 1851cb0ef41Sopenharmony_ci */ 1861cb0ef41Sopenharmony_ci DateIntervalInfo(const DateIntervalInfo&); 1871cb0ef41Sopenharmony_ci 1881cb0ef41Sopenharmony_ci /** 1891cb0ef41Sopenharmony_ci * Assignment operator 1901cb0ef41Sopenharmony_ci * @stable ICU 4.0 1911cb0ef41Sopenharmony_ci */ 1921cb0ef41Sopenharmony_ci DateIntervalInfo& operator=(const DateIntervalInfo&); 1931cb0ef41Sopenharmony_ci 1941cb0ef41Sopenharmony_ci /** 1951cb0ef41Sopenharmony_ci * Clone this object polymorphically. 1961cb0ef41Sopenharmony_ci * The caller owns the result and should delete it when done. 1971cb0ef41Sopenharmony_ci * @return a copy of the object 1981cb0ef41Sopenharmony_ci * @stable ICU 4.0 1991cb0ef41Sopenharmony_ci */ 2001cb0ef41Sopenharmony_ci virtual DateIntervalInfo* clone() const; 2011cb0ef41Sopenharmony_ci 2021cb0ef41Sopenharmony_ci /** 2031cb0ef41Sopenharmony_ci * Destructor. 2041cb0ef41Sopenharmony_ci * It is virtual to be safe, but it is not designed to be subclassed. 2051cb0ef41Sopenharmony_ci * @stable ICU 4.0 2061cb0ef41Sopenharmony_ci */ 2071cb0ef41Sopenharmony_ci virtual ~DateIntervalInfo(); 2081cb0ef41Sopenharmony_ci 2091cb0ef41Sopenharmony_ci 2101cb0ef41Sopenharmony_ci /** 2111cb0ef41Sopenharmony_ci * Return true if another object is semantically equal to this one. 2121cb0ef41Sopenharmony_ci * 2131cb0ef41Sopenharmony_ci * @param other the DateIntervalInfo object to be compared with. 2141cb0ef41Sopenharmony_ci * @return true if other is semantically equal to this. 2151cb0ef41Sopenharmony_ci * @stable ICU 4.0 2161cb0ef41Sopenharmony_ci */ 2171cb0ef41Sopenharmony_ci virtual bool operator==(const DateIntervalInfo& other) const; 2181cb0ef41Sopenharmony_ci 2191cb0ef41Sopenharmony_ci /** 2201cb0ef41Sopenharmony_ci * Return true if another object is semantically unequal to this one. 2211cb0ef41Sopenharmony_ci * 2221cb0ef41Sopenharmony_ci * @param other the DateIntervalInfo object to be compared with. 2231cb0ef41Sopenharmony_ci * @return true if other is semantically unequal to this. 2241cb0ef41Sopenharmony_ci * @stable ICU 4.0 2251cb0ef41Sopenharmony_ci */ 2261cb0ef41Sopenharmony_ci bool operator!=(const DateIntervalInfo& other) const; 2271cb0ef41Sopenharmony_ci 2281cb0ef41Sopenharmony_ci 2291cb0ef41Sopenharmony_ci 2301cb0ef41Sopenharmony_ci /** 2311cb0ef41Sopenharmony_ci * Provides a way for client to build interval patterns. 2321cb0ef41Sopenharmony_ci * User could construct DateIntervalInfo by providing a list of skeletons 2331cb0ef41Sopenharmony_ci * and their patterns. 2341cb0ef41Sopenharmony_ci * <P> 2351cb0ef41Sopenharmony_ci * For example: 2361cb0ef41Sopenharmony_ci * <pre> 2371cb0ef41Sopenharmony_ci * UErrorCode status = U_ZERO_ERROR; 2381cb0ef41Sopenharmony_ci * DateIntervalInfo dIntervalInfo = new DateIntervalInfo(); 2391cb0ef41Sopenharmony_ci * dIntervalInfo->setFallbackIntervalPattern("{0} ~ {1}"); 2401cb0ef41Sopenharmony_ci * dIntervalInfo->setIntervalPattern("yMd", UCAL_YEAR, "'from' yyyy-M-d 'to' yyyy-M-d", status); 2411cb0ef41Sopenharmony_ci * dIntervalInfo->setIntervalPattern("yMMMd", UCAL_MONTH, "'from' yyyy MMM d 'to' MMM d", status); 2421cb0ef41Sopenharmony_ci * dIntervalInfo->setIntervalPattern("yMMMd", UCAL_DAY, "yyyy MMM d-d", status, status); 2431cb0ef41Sopenharmony_ci * </pre> 2441cb0ef41Sopenharmony_ci * 2451cb0ef41Sopenharmony_ci * Restriction: 2461cb0ef41Sopenharmony_ci * Currently, users can only set interval patterns when the following 2471cb0ef41Sopenharmony_ci * calendar fields are different: ERA, YEAR, MONTH, DATE, DAY_OF_MONTH, 2481cb0ef41Sopenharmony_ci * DAY_OF_WEEK, AM_PM, HOUR, HOUR_OF_DAY, MINUTE, SECOND and MILLISECOND. 2491cb0ef41Sopenharmony_ci * Interval patterns when other calendar fields are different are 2501cb0ef41Sopenharmony_ci * not supported. 2511cb0ef41Sopenharmony_ci * 2521cb0ef41Sopenharmony_ci * @param skeleton the skeleton on which interval pattern based 2531cb0ef41Sopenharmony_ci * @param lrgDiffCalUnit the largest different calendar unit. 2541cb0ef41Sopenharmony_ci * @param intervalPattern the interval pattern on the largest different 2551cb0ef41Sopenharmony_ci * calendar unit. 2561cb0ef41Sopenharmony_ci * For example, if lrgDiffCalUnit is 2571cb0ef41Sopenharmony_ci * "year", the interval pattern for en_US when year 2581cb0ef41Sopenharmony_ci * is different could be "'from' yyyy 'to' yyyy". 2591cb0ef41Sopenharmony_ci * @param status output param set to success/failure code on exit 2601cb0ef41Sopenharmony_ci * @stable ICU 4.0 2611cb0ef41Sopenharmony_ci */ 2621cb0ef41Sopenharmony_ci void setIntervalPattern(const UnicodeString& skeleton, 2631cb0ef41Sopenharmony_ci UCalendarDateFields lrgDiffCalUnit, 2641cb0ef41Sopenharmony_ci const UnicodeString& intervalPattern, 2651cb0ef41Sopenharmony_ci UErrorCode& status); 2661cb0ef41Sopenharmony_ci 2671cb0ef41Sopenharmony_ci /** 2681cb0ef41Sopenharmony_ci * Get the interval pattern given skeleton and 2691cb0ef41Sopenharmony_ci * the largest different calendar field. 2701cb0ef41Sopenharmony_ci * @param skeleton the skeleton 2711cb0ef41Sopenharmony_ci * @param field the largest different calendar field 2721cb0ef41Sopenharmony_ci * @param result output param to receive the pattern 2731cb0ef41Sopenharmony_ci * @param status output param set to success/failure code on exit 2741cb0ef41Sopenharmony_ci * @return a reference to 'result' 2751cb0ef41Sopenharmony_ci * @stable ICU 4.0 2761cb0ef41Sopenharmony_ci */ 2771cb0ef41Sopenharmony_ci UnicodeString& getIntervalPattern(const UnicodeString& skeleton, 2781cb0ef41Sopenharmony_ci UCalendarDateFields field, 2791cb0ef41Sopenharmony_ci UnicodeString& result, 2801cb0ef41Sopenharmony_ci UErrorCode& status) const; 2811cb0ef41Sopenharmony_ci 2821cb0ef41Sopenharmony_ci /** 2831cb0ef41Sopenharmony_ci * Get the fallback interval pattern. 2841cb0ef41Sopenharmony_ci * @param result output param to receive the pattern 2851cb0ef41Sopenharmony_ci * @return a reference to 'result' 2861cb0ef41Sopenharmony_ci * @stable ICU 4.0 2871cb0ef41Sopenharmony_ci */ 2881cb0ef41Sopenharmony_ci UnicodeString& getFallbackIntervalPattern(UnicodeString& result) const; 2891cb0ef41Sopenharmony_ci 2901cb0ef41Sopenharmony_ci 2911cb0ef41Sopenharmony_ci /** 2921cb0ef41Sopenharmony_ci * Re-set the fallback interval pattern. 2931cb0ef41Sopenharmony_ci * 2941cb0ef41Sopenharmony_ci * In construction, default fallback pattern is set as "{0} - {1}". 2951cb0ef41Sopenharmony_ci * And constructor taking locale as parameter will set the 2961cb0ef41Sopenharmony_ci * fallback pattern as what defined in the locale resource file. 2971cb0ef41Sopenharmony_ci * 2981cb0ef41Sopenharmony_ci * This method provides a way for user to replace the fallback pattern. 2991cb0ef41Sopenharmony_ci * 3001cb0ef41Sopenharmony_ci * @param fallbackPattern fall-back interval pattern. 3011cb0ef41Sopenharmony_ci * @param status output param set to success/failure code on exit 3021cb0ef41Sopenharmony_ci * @stable ICU 4.0 3031cb0ef41Sopenharmony_ci */ 3041cb0ef41Sopenharmony_ci void setFallbackIntervalPattern(const UnicodeString& fallbackPattern, 3051cb0ef41Sopenharmony_ci UErrorCode& status); 3061cb0ef41Sopenharmony_ci 3071cb0ef41Sopenharmony_ci 3081cb0ef41Sopenharmony_ci /** Get default order -- whether the first date in pattern is later date 3091cb0ef41Sopenharmony_ci or not. 3101cb0ef41Sopenharmony_ci * return default date ordering in interval pattern. true if the first date 3111cb0ef41Sopenharmony_ci * in pattern is later date, false otherwise. 3121cb0ef41Sopenharmony_ci * @stable ICU 4.0 3131cb0ef41Sopenharmony_ci */ 3141cb0ef41Sopenharmony_ci UBool getDefaultOrder() const; 3151cb0ef41Sopenharmony_ci 3161cb0ef41Sopenharmony_ci 3171cb0ef41Sopenharmony_ci /** 3181cb0ef41Sopenharmony_ci * ICU "poor man's RTTI", returns a UClassID for the actual class. 3191cb0ef41Sopenharmony_ci * 3201cb0ef41Sopenharmony_ci * @stable ICU 4.0 3211cb0ef41Sopenharmony_ci */ 3221cb0ef41Sopenharmony_ci virtual UClassID getDynamicClassID() const override; 3231cb0ef41Sopenharmony_ci 3241cb0ef41Sopenharmony_ci /** 3251cb0ef41Sopenharmony_ci * ICU "poor man's RTTI", returns a UClassID for this class. 3261cb0ef41Sopenharmony_ci * 3271cb0ef41Sopenharmony_ci * @stable ICU 4.0 3281cb0ef41Sopenharmony_ci */ 3291cb0ef41Sopenharmony_ci static UClassID U_EXPORT2 getStaticClassID(); 3301cb0ef41Sopenharmony_ci 3311cb0ef41Sopenharmony_ci 3321cb0ef41Sopenharmony_ciprivate: 3331cb0ef41Sopenharmony_ci /** 3341cb0ef41Sopenharmony_ci * DateIntervalFormat will need access to 3351cb0ef41Sopenharmony_ci * getBestSkeleton(), parseSkeleton(), enum IntervalPatternIndex, 3361cb0ef41Sopenharmony_ci * and calendarFieldToPatternIndex(). 3371cb0ef41Sopenharmony_ci * 3381cb0ef41Sopenharmony_ci * Instead of making above public, 3391cb0ef41Sopenharmony_ci * make DateIntervalFormat a friend of DateIntervalInfo. 3401cb0ef41Sopenharmony_ci */ 3411cb0ef41Sopenharmony_ci friend class DateIntervalFormat; 3421cb0ef41Sopenharmony_ci 3431cb0ef41Sopenharmony_ci /** 3441cb0ef41Sopenharmony_ci * Internal struct used to load resource bundle data. 3451cb0ef41Sopenharmony_ci */ 3461cb0ef41Sopenharmony_ci struct U_HIDDEN DateIntervalSink; 3471cb0ef41Sopenharmony_ci 3481cb0ef41Sopenharmony_ci /** 3491cb0ef41Sopenharmony_ci * Following is for saving the interval patterns. 3501cb0ef41Sopenharmony_ci * We only support interval patterns on 3511cb0ef41Sopenharmony_ci * ERA, YEAR, MONTH, DAY, AM_PM, HOUR, MINUTE, SECOND and MILLISECOND. 3521cb0ef41Sopenharmony_ci */ 3531cb0ef41Sopenharmony_ci enum IntervalPatternIndex 3541cb0ef41Sopenharmony_ci { 3551cb0ef41Sopenharmony_ci kIPI_ERA, 3561cb0ef41Sopenharmony_ci kIPI_YEAR, 3571cb0ef41Sopenharmony_ci kIPI_MONTH, 3581cb0ef41Sopenharmony_ci kIPI_DATE, 3591cb0ef41Sopenharmony_ci kIPI_AM_PM, 3601cb0ef41Sopenharmony_ci kIPI_HOUR, 3611cb0ef41Sopenharmony_ci kIPI_MINUTE, 3621cb0ef41Sopenharmony_ci kIPI_SECOND, 3631cb0ef41Sopenharmony_ci kIPI_MILLISECOND, 3641cb0ef41Sopenharmony_ci kIPI_MAX_INDEX 3651cb0ef41Sopenharmony_ci }; 3661cb0ef41Sopenharmony_cipublic: 3671cb0ef41Sopenharmony_ci#ifndef U_HIDE_INTERNAL_API 3681cb0ef41Sopenharmony_ci /** 3691cb0ef41Sopenharmony_ci * Max index for stored interval patterns 3701cb0ef41Sopenharmony_ci * @internal ICU 4.4 3711cb0ef41Sopenharmony_ci */ 3721cb0ef41Sopenharmony_ci enum { 3731cb0ef41Sopenharmony_ci kMaxIntervalPatternIndex = kIPI_MAX_INDEX 3741cb0ef41Sopenharmony_ci }; 3751cb0ef41Sopenharmony_ci#endif /* U_HIDE_INTERNAL_API */ 3761cb0ef41Sopenharmony_ciprivate: 3771cb0ef41Sopenharmony_ci 3781cb0ef41Sopenharmony_ci 3791cb0ef41Sopenharmony_ci /** 3801cb0ef41Sopenharmony_ci * Initialize the DateIntervalInfo from locale 3811cb0ef41Sopenharmony_ci * @param locale the given locale. 3821cb0ef41Sopenharmony_ci * @param status output param set to success/failure code on exit 3831cb0ef41Sopenharmony_ci */ 3841cb0ef41Sopenharmony_ci void initializeData(const Locale& locale, UErrorCode& status); 3851cb0ef41Sopenharmony_ci 3861cb0ef41Sopenharmony_ci 3871cb0ef41Sopenharmony_ci /* Set Interval pattern. 3881cb0ef41Sopenharmony_ci * 3891cb0ef41Sopenharmony_ci * It sets interval pattern into the hash map. 3901cb0ef41Sopenharmony_ci * 3911cb0ef41Sopenharmony_ci * @param skeleton skeleton on which the interval pattern based 3921cb0ef41Sopenharmony_ci * @param lrgDiffCalUnit the largest different calendar unit. 3931cb0ef41Sopenharmony_ci * @param intervalPattern the interval pattern on the largest different 3941cb0ef41Sopenharmony_ci * calendar unit. 3951cb0ef41Sopenharmony_ci * @param status output param set to success/failure code on exit 3961cb0ef41Sopenharmony_ci */ 3971cb0ef41Sopenharmony_ci void setIntervalPatternInternally(const UnicodeString& skeleton, 3981cb0ef41Sopenharmony_ci UCalendarDateFields lrgDiffCalUnit, 3991cb0ef41Sopenharmony_ci const UnicodeString& intervalPattern, 4001cb0ef41Sopenharmony_ci UErrorCode& status); 4011cb0ef41Sopenharmony_ci 4021cb0ef41Sopenharmony_ci 4031cb0ef41Sopenharmony_ci /**given an input skeleton, get the best match skeleton 4041cb0ef41Sopenharmony_ci * which has pre-defined interval pattern in resource file. 4051cb0ef41Sopenharmony_ci * Also return the difference between the input skeleton 4061cb0ef41Sopenharmony_ci * and the best match skeleton. 4071cb0ef41Sopenharmony_ci * 4081cb0ef41Sopenharmony_ci * TODO (xji): set field weight or 4091cb0ef41Sopenharmony_ci * isolate the functionality in DateTimePatternGenerator 4101cb0ef41Sopenharmony_ci * @param skeleton input skeleton 4111cb0ef41Sopenharmony_ci * @param bestMatchDistanceInfo the difference between input skeleton 4121cb0ef41Sopenharmony_ci * and best match skeleton. 4131cb0ef41Sopenharmony_ci * 0, if there is exact match for input skeleton 4141cb0ef41Sopenharmony_ci * 1, if there is only field width difference between 4151cb0ef41Sopenharmony_ci * the best match and the input skeleton 4161cb0ef41Sopenharmony_ci * 2, the only field difference is 'v' and 'z' 4171cb0ef41Sopenharmony_ci * -1, if there is calendar field difference between 4181cb0ef41Sopenharmony_ci * the best match and the input skeleton 4191cb0ef41Sopenharmony_ci * @return best match skeleton 4201cb0ef41Sopenharmony_ci */ 4211cb0ef41Sopenharmony_ci const UnicodeString* getBestSkeleton(const UnicodeString& skeleton, 4221cb0ef41Sopenharmony_ci int8_t& bestMatchDistanceInfo) const; 4231cb0ef41Sopenharmony_ci 4241cb0ef41Sopenharmony_ci 4251cb0ef41Sopenharmony_ci /** 4261cb0ef41Sopenharmony_ci * Parse skeleton, save each field's width. 4271cb0ef41Sopenharmony_ci * It is used for looking for best match skeleton, 4281cb0ef41Sopenharmony_ci * and adjust pattern field width. 4291cb0ef41Sopenharmony_ci * @param skeleton skeleton to be parsed 4301cb0ef41Sopenharmony_ci * @param skeletonFieldWidth parsed skeleton field width 4311cb0ef41Sopenharmony_ci */ 4321cb0ef41Sopenharmony_ci static void U_EXPORT2 parseSkeleton(const UnicodeString& skeleton, 4331cb0ef41Sopenharmony_ci int32_t* skeletonFieldWidth); 4341cb0ef41Sopenharmony_ci 4351cb0ef41Sopenharmony_ci 4361cb0ef41Sopenharmony_ci /** 4371cb0ef41Sopenharmony_ci * Check whether one field width is numeric while the other is string. 4381cb0ef41Sopenharmony_ci * 4391cb0ef41Sopenharmony_ci * TODO (xji): make it general 4401cb0ef41Sopenharmony_ci * 4411cb0ef41Sopenharmony_ci * @param fieldWidth one field width 4421cb0ef41Sopenharmony_ci * @param anotherFieldWidth another field width 4431cb0ef41Sopenharmony_ci * @param patternLetter pattern letter char 4441cb0ef41Sopenharmony_ci * @return true if one field width is numeric and the other is string, 4451cb0ef41Sopenharmony_ci * false otherwise. 4461cb0ef41Sopenharmony_ci */ 4471cb0ef41Sopenharmony_ci static UBool U_EXPORT2 stringNumeric(int32_t fieldWidth, 4481cb0ef41Sopenharmony_ci int32_t anotherFieldWidth, 4491cb0ef41Sopenharmony_ci char patternLetter); 4501cb0ef41Sopenharmony_ci 4511cb0ef41Sopenharmony_ci 4521cb0ef41Sopenharmony_ci /** 4531cb0ef41Sopenharmony_ci * Convert calendar field to the interval pattern index in 4541cb0ef41Sopenharmony_ci * hash table. 4551cb0ef41Sopenharmony_ci * 4561cb0ef41Sopenharmony_ci * Since we only support the following calendar fields: 4571cb0ef41Sopenharmony_ci * ERA, YEAR, MONTH, DATE, DAY_OF_MONTH, DAY_OF_WEEK, 4581cb0ef41Sopenharmony_ci * AM_PM, HOUR, HOUR_OF_DAY, MINUTE, SECOND, and MILLISECOND. 4591cb0ef41Sopenharmony_ci * We reserve only 4 interval patterns for a skeleton. 4601cb0ef41Sopenharmony_ci * 4611cb0ef41Sopenharmony_ci * @param field calendar field 4621cb0ef41Sopenharmony_ci * @param status output param set to success/failure code on exit 4631cb0ef41Sopenharmony_ci * @return interval pattern index in hash table 4641cb0ef41Sopenharmony_ci */ 4651cb0ef41Sopenharmony_ci static IntervalPatternIndex U_EXPORT2 calendarFieldToIntervalIndex( 4661cb0ef41Sopenharmony_ci UCalendarDateFields field, 4671cb0ef41Sopenharmony_ci UErrorCode& status); 4681cb0ef41Sopenharmony_ci 4691cb0ef41Sopenharmony_ci 4701cb0ef41Sopenharmony_ci /** 4711cb0ef41Sopenharmony_ci * delete hash table (of type fIntervalPatterns). 4721cb0ef41Sopenharmony_ci * 4731cb0ef41Sopenharmony_ci * @param hTable hash table to be deleted 4741cb0ef41Sopenharmony_ci */ 4751cb0ef41Sopenharmony_ci void deleteHash(Hashtable* hTable); 4761cb0ef41Sopenharmony_ci 4771cb0ef41Sopenharmony_ci 4781cb0ef41Sopenharmony_ci /** 4791cb0ef41Sopenharmony_ci * initialize hash table (of type fIntervalPatterns). 4801cb0ef41Sopenharmony_ci * 4811cb0ef41Sopenharmony_ci * @param status output param set to success/failure code on exit 4821cb0ef41Sopenharmony_ci * @return hash table initialized 4831cb0ef41Sopenharmony_ci */ 4841cb0ef41Sopenharmony_ci Hashtable* initHash(UErrorCode& status); 4851cb0ef41Sopenharmony_ci 4861cb0ef41Sopenharmony_ci 4871cb0ef41Sopenharmony_ci 4881cb0ef41Sopenharmony_ci /** 4891cb0ef41Sopenharmony_ci * copy hash table (of type fIntervalPatterns). 4901cb0ef41Sopenharmony_ci * 4911cb0ef41Sopenharmony_ci * @param source the source to copy from 4921cb0ef41Sopenharmony_ci * @param target the target to copy to 4931cb0ef41Sopenharmony_ci * @param status output param set to success/failure code on exit 4941cb0ef41Sopenharmony_ci */ 4951cb0ef41Sopenharmony_ci void copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status); 4961cb0ef41Sopenharmony_ci 4971cb0ef41Sopenharmony_ci 4981cb0ef41Sopenharmony_ci // data members 4991cb0ef41Sopenharmony_ci // fallback interval pattern 5001cb0ef41Sopenharmony_ci UnicodeString fFallbackIntervalPattern; 5011cb0ef41Sopenharmony_ci // default order 5021cb0ef41Sopenharmony_ci UBool fFirstDateInPtnIsLaterDate; 5031cb0ef41Sopenharmony_ci 5041cb0ef41Sopenharmony_ci // HashMap<UnicodeString, UnicodeString[kIPI_MAX_INDEX]> 5051cb0ef41Sopenharmony_ci // HashMap( skeleton, pattern[largest_different_field] ) 5061cb0ef41Sopenharmony_ci Hashtable* fIntervalPatterns; 5071cb0ef41Sopenharmony_ci 5081cb0ef41Sopenharmony_ci};// end class DateIntervalInfo 5091cb0ef41Sopenharmony_ci 5101cb0ef41Sopenharmony_ci 5111cb0ef41Sopenharmony_ciinline bool 5121cb0ef41Sopenharmony_ciDateIntervalInfo::operator!=(const DateIntervalInfo& other) const { 5131cb0ef41Sopenharmony_ci return !operator==(other); 5141cb0ef41Sopenharmony_ci} 5151cb0ef41Sopenharmony_ci 5161cb0ef41Sopenharmony_ci 5171cb0ef41Sopenharmony_ciU_NAMESPACE_END 5181cb0ef41Sopenharmony_ci 5191cb0ef41Sopenharmony_ci#endif 5201cb0ef41Sopenharmony_ci 5211cb0ef41Sopenharmony_ci#endif /* U_SHOW_CPLUSPLUS_API */ 5221cb0ef41Sopenharmony_ci 5231cb0ef41Sopenharmony_ci#endif 5241cb0ef41Sopenharmony_ci 525