jpayne@69
|
1 // © 2016 and later: Unicode, Inc. and others.
|
jpayne@69
|
2 // License & terms of use: http://www.unicode.org/copyright.html
|
jpayne@69
|
3 /*
|
jpayne@69
|
4 *******************************************************************************
|
jpayne@69
|
5 * Copyright (C) 2008-2016, International Business Machines Corporation and
|
jpayne@69
|
6 * others. All Rights Reserved.
|
jpayne@69
|
7 *******************************************************************************
|
jpayne@69
|
8 *
|
jpayne@69
|
9 * File DTITVINF.H
|
jpayne@69
|
10 *
|
jpayne@69
|
11 *******************************************************************************
|
jpayne@69
|
12 */
|
jpayne@69
|
13
|
jpayne@69
|
14 #ifndef __DTITVINF_H__
|
jpayne@69
|
15 #define __DTITVINF_H__
|
jpayne@69
|
16
|
jpayne@69
|
17 #include "unicode/utypes.h"
|
jpayne@69
|
18
|
jpayne@69
|
19 #if U_SHOW_CPLUSPLUS_API
|
jpayne@69
|
20
|
jpayne@69
|
21 /**
|
jpayne@69
|
22 * \file
|
jpayne@69
|
23 * \brief C++ API: Date/Time interval patterns for formatting date/time interval
|
jpayne@69
|
24 */
|
jpayne@69
|
25
|
jpayne@69
|
26 #if !UCONFIG_NO_FORMATTING
|
jpayne@69
|
27
|
jpayne@69
|
28 #include "unicode/udat.h"
|
jpayne@69
|
29 #include "unicode/locid.h"
|
jpayne@69
|
30 #include "unicode/ucal.h"
|
jpayne@69
|
31 #include "unicode/dtptngen.h"
|
jpayne@69
|
32
|
jpayne@69
|
33 U_NAMESPACE_BEGIN
|
jpayne@69
|
34
|
jpayne@69
|
35 /**
|
jpayne@69
|
36 * DateIntervalInfo is a public class for encapsulating localizable
|
jpayne@69
|
37 * date time interval patterns. It is used by DateIntervalFormat.
|
jpayne@69
|
38 *
|
jpayne@69
|
39 * <P>
|
jpayne@69
|
40 * For most users, ordinary use of DateIntervalFormat does not need to create
|
jpayne@69
|
41 * DateIntervalInfo object directly.
|
jpayne@69
|
42 * DateIntervalFormat will take care of it when creating a date interval
|
jpayne@69
|
43 * formatter when user pass in skeleton and locale.
|
jpayne@69
|
44 *
|
jpayne@69
|
45 * <P>
|
jpayne@69
|
46 * For power users, who want to create their own date interval patterns,
|
jpayne@69
|
47 * or want to re-set date interval patterns, they could do so by
|
jpayne@69
|
48 * directly creating DateIntervalInfo and manupulating it.
|
jpayne@69
|
49 *
|
jpayne@69
|
50 * <P>
|
jpayne@69
|
51 * Logically, the interval patterns are mappings
|
jpayne@69
|
52 * from (skeleton, the_largest_different_calendar_field)
|
jpayne@69
|
53 * to (date_interval_pattern).
|
jpayne@69
|
54 *
|
jpayne@69
|
55 * <P>
|
jpayne@69
|
56 * A skeleton
|
jpayne@69
|
57 * <ol>
|
jpayne@69
|
58 * <li>
|
jpayne@69
|
59 * only keeps the field pattern letter and ignores all other parts
|
jpayne@69
|
60 * in a pattern, such as space, punctuations, and string literals.
|
jpayne@69
|
61 * <li>
|
jpayne@69
|
62 * hides the order of fields.
|
jpayne@69
|
63 * <li>
|
jpayne@69
|
64 * might hide a field's pattern letter length.
|
jpayne@69
|
65 *
|
jpayne@69
|
66 * For those non-digit calendar fields, the pattern letter length is
|
jpayne@69
|
67 * important, such as MMM, MMMM, and MMMMM; EEE and EEEE,
|
jpayne@69
|
68 * and the field's pattern letter length is honored.
|
jpayne@69
|
69 *
|
jpayne@69
|
70 * For the digit calendar fields, such as M or MM, d or dd, yy or yyyy,
|
jpayne@69
|
71 * the field pattern length is ignored and the best match, which is defined
|
jpayne@69
|
72 * in date time patterns, will be returned without honor the field pattern
|
jpayne@69
|
73 * letter length in skeleton.
|
jpayne@69
|
74 * </ol>
|
jpayne@69
|
75 *
|
jpayne@69
|
76 * <P>
|
jpayne@69
|
77 * The calendar fields we support for interval formatting are:
|
jpayne@69
|
78 * year, month, date, day-of-week, am-pm, hour, hour-of-day, and minute.
|
jpayne@69
|
79 * Those calendar fields can be defined in the following order:
|
jpayne@69
|
80 * year > month > date > am-pm > hour > minute
|
jpayne@69
|
81 *
|
jpayne@69
|
82 * The largest different calendar fields between 2 calendars is the
|
jpayne@69
|
83 * first different calendar field in above order.
|
jpayne@69
|
84 *
|
jpayne@69
|
85 * For example: the largest different calendar fields between "Jan 10, 2007"
|
jpayne@69
|
86 * and "Feb 20, 2008" is year.
|
jpayne@69
|
87 *
|
jpayne@69
|
88 * <P>
|
jpayne@69
|
89 * There is a set of pre-defined static skeleton strings.
|
jpayne@69
|
90 * There are pre-defined interval patterns for those pre-defined skeletons
|
jpayne@69
|
91 * in locales' resource files.
|
jpayne@69
|
92 * For example, for a skeleton UDAT_YEAR_ABBR_MONTH_DAY, which is "yMMMd",
|
jpayne@69
|
93 * in en_US, if the largest different calendar field between date1 and date2
|
jpayne@69
|
94 * is "year", the date interval pattern is "MMM d, yyyy - MMM d, yyyy",
|
jpayne@69
|
95 * such as "Jan 10, 2007 - Jan 10, 2008".
|
jpayne@69
|
96 * If the largest different calendar field between date1 and date2 is "month",
|
jpayne@69
|
97 * the date interval pattern is "MMM d - MMM d, yyyy",
|
jpayne@69
|
98 * such as "Jan 10 - Feb 10, 2007".
|
jpayne@69
|
99 * If the largest different calendar field between date1 and date2 is "day",
|
jpayne@69
|
100 * the date interval pattern is "MMM d-d, yyyy", such as "Jan 10-20, 2007".
|
jpayne@69
|
101 *
|
jpayne@69
|
102 * For date skeleton, the interval patterns when year, or month, or date is
|
jpayne@69
|
103 * different are defined in resource files.
|
jpayne@69
|
104 * For time skeleton, the interval patterns when am/pm, or hour, or minute is
|
jpayne@69
|
105 * different are defined in resource files.
|
jpayne@69
|
106 *
|
jpayne@69
|
107 *
|
jpayne@69
|
108 * <P>
|
jpayne@69
|
109 * There are 2 dates in interval pattern. For most locales, the first date
|
jpayne@69
|
110 * in an interval pattern is the earlier date. There might be a locale in which
|
jpayne@69
|
111 * the first date in an interval pattern is the later date.
|
jpayne@69
|
112 * We use fallback format for the default order for the locale.
|
jpayne@69
|
113 * For example, if the fallback format is "{0} - {1}", it means
|
jpayne@69
|
114 * the first date in the interval pattern for this locale is earlier date.
|
jpayne@69
|
115 * If the fallback format is "{1} - {0}", it means the first date is the
|
jpayne@69
|
116 * later date.
|
jpayne@69
|
117 * For a particular interval pattern, the default order can be overriden
|
jpayne@69
|
118 * by prefixing "latestFirst:" or "earliestFirst:" to the interval pattern.
|
jpayne@69
|
119 * For example, if the fallback format is "{0}-{1}",
|
jpayne@69
|
120 * but for skeleton "yMMMd", the interval pattern when day is different is
|
jpayne@69
|
121 * "latestFirst:d-d MMM yy", it means by default, the first date in interval
|
jpayne@69
|
122 * pattern is the earlier date. But for skeleton "yMMMd", when day is different,
|
jpayne@69
|
123 * the first date in "d-d MMM yy" is the later date.
|
jpayne@69
|
124 *
|
jpayne@69
|
125 * <P>
|
jpayne@69
|
126 * The recommended way to create a DateIntervalFormat object is to pass in
|
jpayne@69
|
127 * the locale.
|
jpayne@69
|
128 * By using a Locale parameter, the DateIntervalFormat object is
|
jpayne@69
|
129 * initialized with the pre-defined interval patterns for a given or
|
jpayne@69
|
130 * default locale.
|
jpayne@69
|
131 * <P>
|
jpayne@69
|
132 * Users can also create DateIntervalFormat object
|
jpayne@69
|
133 * by supplying their own interval patterns.
|
jpayne@69
|
134 * It provides flexibility for power users.
|
jpayne@69
|
135 *
|
jpayne@69
|
136 * <P>
|
jpayne@69
|
137 * After a DateIntervalInfo object is created, clients may modify
|
jpayne@69
|
138 * the interval patterns using setIntervalPattern function as so desired.
|
jpayne@69
|
139 * Currently, users can only set interval patterns when the following
|
jpayne@69
|
140 * calendar fields are different: ERA, YEAR, MONTH, DATE, DAY_OF_MONTH,
|
jpayne@69
|
141 * DAY_OF_WEEK, AM_PM, HOUR, HOUR_OF_DAY, MINUTE, SECOND, and MILLISECOND.
|
jpayne@69
|
142 * Interval patterns when other calendar fields are different is not supported.
|
jpayne@69
|
143 * <P>
|
jpayne@69
|
144 * DateIntervalInfo objects are cloneable.
|
jpayne@69
|
145 * When clients obtain a DateIntervalInfo object,
|
jpayne@69
|
146 * they can feel free to modify it as necessary.
|
jpayne@69
|
147 * <P>
|
jpayne@69
|
148 * DateIntervalInfo are not expected to be subclassed.
|
jpayne@69
|
149 * Data for a calendar is loaded out of resource bundles.
|
jpayne@69
|
150 * Through ICU 4.4, date interval patterns are only supported in the Gregorian
|
jpayne@69
|
151 * calendar; non-Gregorian calendars are supported from ICU 4.4.1.
|
jpayne@69
|
152 * @stable ICU 4.0
|
jpayne@69
|
153 **/
|
jpayne@69
|
154 class U_I18N_API DateIntervalInfo U_FINAL : public UObject {
|
jpayne@69
|
155 public:
|
jpayne@69
|
156 /**
|
jpayne@69
|
157 * Default constructor.
|
jpayne@69
|
158 * It does not initialize any interval patterns except
|
jpayne@69
|
159 * that it initialize default fall-back pattern as "{0} - {1}",
|
jpayne@69
|
160 * which can be reset by setFallbackIntervalPattern().
|
jpayne@69
|
161 * It should be followed by setFallbackIntervalPattern() and
|
jpayne@69
|
162 * setIntervalPattern(),
|
jpayne@69
|
163 * and is recommended to be used only for power users who
|
jpayne@69
|
164 * wants to create their own interval patterns and use them to create
|
jpayne@69
|
165 * date interval formatter.
|
jpayne@69
|
166 * @param status output param set to success/failure code on exit
|
jpayne@69
|
167 * @internal ICU 4.0
|
jpayne@69
|
168 */
|
jpayne@69
|
169 DateIntervalInfo(UErrorCode& status);
|
jpayne@69
|
170
|
jpayne@69
|
171
|
jpayne@69
|
172 /**
|
jpayne@69
|
173 * Construct DateIntervalInfo for the given locale,
|
jpayne@69
|
174 * @param locale the interval patterns are loaded from the appropriate calendar
|
jpayne@69
|
175 * data (specified calendar or default calendar) in this locale.
|
jpayne@69
|
176 * @param status output param set to success/failure code on exit
|
jpayne@69
|
177 * @stable ICU 4.0
|
jpayne@69
|
178 */
|
jpayne@69
|
179 DateIntervalInfo(const Locale& locale, UErrorCode& status);
|
jpayne@69
|
180
|
jpayne@69
|
181
|
jpayne@69
|
182 /**
|
jpayne@69
|
183 * Copy constructor.
|
jpayne@69
|
184 * @stable ICU 4.0
|
jpayne@69
|
185 */
|
jpayne@69
|
186 DateIntervalInfo(const DateIntervalInfo&);
|
jpayne@69
|
187
|
jpayne@69
|
188 /**
|
jpayne@69
|
189 * Assignment operator
|
jpayne@69
|
190 * @stable ICU 4.0
|
jpayne@69
|
191 */
|
jpayne@69
|
192 DateIntervalInfo& operator=(const DateIntervalInfo&);
|
jpayne@69
|
193
|
jpayne@69
|
194 /**
|
jpayne@69
|
195 * Clone this object polymorphically.
|
jpayne@69
|
196 * The caller owns the result and should delete it when done.
|
jpayne@69
|
197 * @return a copy of the object
|
jpayne@69
|
198 * @stable ICU 4.0
|
jpayne@69
|
199 */
|
jpayne@69
|
200 virtual DateIntervalInfo* clone() const;
|
jpayne@69
|
201
|
jpayne@69
|
202 /**
|
jpayne@69
|
203 * Destructor.
|
jpayne@69
|
204 * It is virtual to be safe, but it is not designed to be subclassed.
|
jpayne@69
|
205 * @stable ICU 4.0
|
jpayne@69
|
206 */
|
jpayne@69
|
207 virtual ~DateIntervalInfo();
|
jpayne@69
|
208
|
jpayne@69
|
209
|
jpayne@69
|
210 /**
|
jpayne@69
|
211 * Return true if another object is semantically equal to this one.
|
jpayne@69
|
212 *
|
jpayne@69
|
213 * @param other the DateIntervalInfo object to be compared with.
|
jpayne@69
|
214 * @return true if other is semantically equal to this.
|
jpayne@69
|
215 * @stable ICU 4.0
|
jpayne@69
|
216 */
|
jpayne@69
|
217 virtual UBool operator==(const DateIntervalInfo& other) const;
|
jpayne@69
|
218
|
jpayne@69
|
219 /**
|
jpayne@69
|
220 * Return true if another object is semantically unequal to this one.
|
jpayne@69
|
221 *
|
jpayne@69
|
222 * @param other the DateIntervalInfo object to be compared with.
|
jpayne@69
|
223 * @return true if other is semantically unequal to this.
|
jpayne@69
|
224 * @stable ICU 4.0
|
jpayne@69
|
225 */
|
jpayne@69
|
226 UBool operator!=(const DateIntervalInfo& other) const;
|
jpayne@69
|
227
|
jpayne@69
|
228
|
jpayne@69
|
229
|
jpayne@69
|
230 /**
|
jpayne@69
|
231 * Provides a way for client to build interval patterns.
|
jpayne@69
|
232 * User could construct DateIntervalInfo by providing a list of skeletons
|
jpayne@69
|
233 * and their patterns.
|
jpayne@69
|
234 * <P>
|
jpayne@69
|
235 * For example:
|
jpayne@69
|
236 * <pre>
|
jpayne@69
|
237 * UErrorCode status = U_ZERO_ERROR;
|
jpayne@69
|
238 * DateIntervalInfo dIntervalInfo = new DateIntervalInfo();
|
jpayne@69
|
239 * dIntervalInfo->setFallbackIntervalPattern("{0} ~ {1}");
|
jpayne@69
|
240 * dIntervalInfo->setIntervalPattern("yMd", UCAL_YEAR, "'from' yyyy-M-d 'to' yyyy-M-d", status);
|
jpayne@69
|
241 * dIntervalInfo->setIntervalPattern("yMMMd", UCAL_MONTH, "'from' yyyy MMM d 'to' MMM d", status);
|
jpayne@69
|
242 * dIntervalInfo->setIntervalPattern("yMMMd", UCAL_DAY, "yyyy MMM d-d", status, status);
|
jpayne@69
|
243 * </pre>
|
jpayne@69
|
244 *
|
jpayne@69
|
245 * Restriction:
|
jpayne@69
|
246 * Currently, users can only set interval patterns when the following
|
jpayne@69
|
247 * calendar fields are different: ERA, YEAR, MONTH, DATE, DAY_OF_MONTH,
|
jpayne@69
|
248 * DAY_OF_WEEK, AM_PM, HOUR, HOUR_OF_DAY, MINUTE, SECOND and MILLISECOND.
|
jpayne@69
|
249 * Interval patterns when other calendar fields are different are
|
jpayne@69
|
250 * not supported.
|
jpayne@69
|
251 *
|
jpayne@69
|
252 * @param skeleton the skeleton on which interval pattern based
|
jpayne@69
|
253 * @param lrgDiffCalUnit the largest different calendar unit.
|
jpayne@69
|
254 * @param intervalPattern the interval pattern on the largest different
|
jpayne@69
|
255 * calendar unit.
|
jpayne@69
|
256 * For example, if lrgDiffCalUnit is
|
jpayne@69
|
257 * "year", the interval pattern for en_US when year
|
jpayne@69
|
258 * is different could be "'from' yyyy 'to' yyyy".
|
jpayne@69
|
259 * @param status output param set to success/failure code on exit
|
jpayne@69
|
260 * @stable ICU 4.0
|
jpayne@69
|
261 */
|
jpayne@69
|
262 void setIntervalPattern(const UnicodeString& skeleton,
|
jpayne@69
|
263 UCalendarDateFields lrgDiffCalUnit,
|
jpayne@69
|
264 const UnicodeString& intervalPattern,
|
jpayne@69
|
265 UErrorCode& status);
|
jpayne@69
|
266
|
jpayne@69
|
267 /**
|
jpayne@69
|
268 * Get the interval pattern given skeleton and
|
jpayne@69
|
269 * the largest different calendar field.
|
jpayne@69
|
270 * @param skeleton the skeleton
|
jpayne@69
|
271 * @param field the largest different calendar field
|
jpayne@69
|
272 * @param result output param to receive the pattern
|
jpayne@69
|
273 * @param status output param set to success/failure code on exit
|
jpayne@69
|
274 * @return a reference to 'result'
|
jpayne@69
|
275 * @stable ICU 4.0
|
jpayne@69
|
276 */
|
jpayne@69
|
277 UnicodeString& getIntervalPattern(const UnicodeString& skeleton,
|
jpayne@69
|
278 UCalendarDateFields field,
|
jpayne@69
|
279 UnicodeString& result,
|
jpayne@69
|
280 UErrorCode& status) const;
|
jpayne@69
|
281
|
jpayne@69
|
282 /**
|
jpayne@69
|
283 * Get the fallback interval pattern.
|
jpayne@69
|
284 * @param result output param to receive the pattern
|
jpayne@69
|
285 * @return a reference to 'result'
|
jpayne@69
|
286 * @stable ICU 4.0
|
jpayne@69
|
287 */
|
jpayne@69
|
288 UnicodeString& getFallbackIntervalPattern(UnicodeString& result) const;
|
jpayne@69
|
289
|
jpayne@69
|
290
|
jpayne@69
|
291 /**
|
jpayne@69
|
292 * Re-set the fallback interval pattern.
|
jpayne@69
|
293 *
|
jpayne@69
|
294 * In construction, default fallback pattern is set as "{0} - {1}".
|
jpayne@69
|
295 * And constructor taking locale as parameter will set the
|
jpayne@69
|
296 * fallback pattern as what defined in the locale resource file.
|
jpayne@69
|
297 *
|
jpayne@69
|
298 * This method provides a way for user to replace the fallback pattern.
|
jpayne@69
|
299 *
|
jpayne@69
|
300 * @param fallbackPattern fall-back interval pattern.
|
jpayne@69
|
301 * @param status output param set to success/failure code on exit
|
jpayne@69
|
302 * @stable ICU 4.0
|
jpayne@69
|
303 */
|
jpayne@69
|
304 void setFallbackIntervalPattern(const UnicodeString& fallbackPattern,
|
jpayne@69
|
305 UErrorCode& status);
|
jpayne@69
|
306
|
jpayne@69
|
307
|
jpayne@69
|
308 /** Get default order -- whether the first date in pattern is later date
|
jpayne@69
|
309 or not.
|
jpayne@69
|
310 * return default date ordering in interval pattern. TRUE if the first date
|
jpayne@69
|
311 * in pattern is later date, FALSE otherwise.
|
jpayne@69
|
312 * @stable ICU 4.0
|
jpayne@69
|
313 */
|
jpayne@69
|
314 UBool getDefaultOrder() const;
|
jpayne@69
|
315
|
jpayne@69
|
316
|
jpayne@69
|
317 /**
|
jpayne@69
|
318 * ICU "poor man's RTTI", returns a UClassID for the actual class.
|
jpayne@69
|
319 *
|
jpayne@69
|
320 * @stable ICU 4.0
|
jpayne@69
|
321 */
|
jpayne@69
|
322 virtual UClassID getDynamicClassID() const;
|
jpayne@69
|
323
|
jpayne@69
|
324 /**
|
jpayne@69
|
325 * ICU "poor man's RTTI", returns a UClassID for this class.
|
jpayne@69
|
326 *
|
jpayne@69
|
327 * @stable ICU 4.0
|
jpayne@69
|
328 */
|
jpayne@69
|
329 static UClassID U_EXPORT2 getStaticClassID();
|
jpayne@69
|
330
|
jpayne@69
|
331
|
jpayne@69
|
332 private:
|
jpayne@69
|
333 /**
|
jpayne@69
|
334 * DateIntervalFormat will need access to
|
jpayne@69
|
335 * getBestSkeleton(), parseSkeleton(), enum IntervalPatternIndex,
|
jpayne@69
|
336 * and calendarFieldToPatternIndex().
|
jpayne@69
|
337 *
|
jpayne@69
|
338 * Instead of making above public,
|
jpayne@69
|
339 * make DateIntervalFormat a friend of DateIntervalInfo.
|
jpayne@69
|
340 */
|
jpayne@69
|
341 friend class DateIntervalFormat;
|
jpayne@69
|
342
|
jpayne@69
|
343 /**
|
jpayne@69
|
344 * Internal struct used to load resource bundle data.
|
jpayne@69
|
345 */
|
jpayne@69
|
346 struct DateIntervalSink;
|
jpayne@69
|
347
|
jpayne@69
|
348 /**
|
jpayne@69
|
349 * Following is for saving the interval patterns.
|
jpayne@69
|
350 * We only support interval patterns on
|
jpayne@69
|
351 * ERA, YEAR, MONTH, DAY, AM_PM, HOUR, MINUTE, SECOND and MILLISECOND.
|
jpayne@69
|
352 */
|
jpayne@69
|
353 enum IntervalPatternIndex
|
jpayne@69
|
354 {
|
jpayne@69
|
355 kIPI_ERA,
|
jpayne@69
|
356 kIPI_YEAR,
|
jpayne@69
|
357 kIPI_MONTH,
|
jpayne@69
|
358 kIPI_DATE,
|
jpayne@69
|
359 kIPI_AM_PM,
|
jpayne@69
|
360 kIPI_HOUR,
|
jpayne@69
|
361 kIPI_MINUTE,
|
jpayne@69
|
362 kIPI_SECOND,
|
jpayne@69
|
363 kIPI_MILLISECOND,
|
jpayne@69
|
364 kIPI_MAX_INDEX
|
jpayne@69
|
365 };
|
jpayne@69
|
366 public:
|
jpayne@69
|
367 #ifndef U_HIDE_INTERNAL_API
|
jpayne@69
|
368 /**
|
jpayne@69
|
369 * Max index for stored interval patterns
|
jpayne@69
|
370 * @internal ICU 4.4
|
jpayne@69
|
371 */
|
jpayne@69
|
372 enum {
|
jpayne@69
|
373 kMaxIntervalPatternIndex = kIPI_MAX_INDEX
|
jpayne@69
|
374 };
|
jpayne@69
|
375 #endif /* U_HIDE_INTERNAL_API */
|
jpayne@69
|
376 private:
|
jpayne@69
|
377
|
jpayne@69
|
378
|
jpayne@69
|
379 /**
|
jpayne@69
|
380 * Initialize the DateIntervalInfo from locale
|
jpayne@69
|
381 * @param locale the given locale.
|
jpayne@69
|
382 * @param status output param set to success/failure code on exit
|
jpayne@69
|
383 */
|
jpayne@69
|
384 void initializeData(const Locale& locale, UErrorCode& status);
|
jpayne@69
|
385
|
jpayne@69
|
386
|
jpayne@69
|
387 /* Set Interval pattern.
|
jpayne@69
|
388 *
|
jpayne@69
|
389 * It sets interval pattern into the hash map.
|
jpayne@69
|
390 *
|
jpayne@69
|
391 * @param skeleton skeleton on which the interval pattern based
|
jpayne@69
|
392 * @param lrgDiffCalUnit the largest different calendar unit.
|
jpayne@69
|
393 * @param intervalPattern the interval pattern on the largest different
|
jpayne@69
|
394 * calendar unit.
|
jpayne@69
|
395 * @param status output param set to success/failure code on exit
|
jpayne@69
|
396 */
|
jpayne@69
|
397 void setIntervalPatternInternally(const UnicodeString& skeleton,
|
jpayne@69
|
398 UCalendarDateFields lrgDiffCalUnit,
|
jpayne@69
|
399 const UnicodeString& intervalPattern,
|
jpayne@69
|
400 UErrorCode& status);
|
jpayne@69
|
401
|
jpayne@69
|
402
|
jpayne@69
|
403 /**given an input skeleton, get the best match skeleton
|
jpayne@69
|
404 * which has pre-defined interval pattern in resource file.
|
jpayne@69
|
405 * Also return the difference between the input skeleton
|
jpayne@69
|
406 * and the best match skeleton.
|
jpayne@69
|
407 *
|
jpayne@69
|
408 * TODO (xji): set field weight or
|
jpayne@69
|
409 * isolate the funtionality in DateTimePatternGenerator
|
jpayne@69
|
410 * @param skeleton input skeleton
|
jpayne@69
|
411 * @param bestMatchDistanceInfo the difference between input skeleton
|
jpayne@69
|
412 * and best match skeleton.
|
jpayne@69
|
413 * 0, if there is exact match for input skeleton
|
jpayne@69
|
414 * 1, if there is only field width difference between
|
jpayne@69
|
415 * the best match and the input skeleton
|
jpayne@69
|
416 * 2, the only field difference is 'v' and 'z'
|
jpayne@69
|
417 * -1, if there is calendar field difference between
|
jpayne@69
|
418 * the best match and the input skeleton
|
jpayne@69
|
419 * @return best match skeleton
|
jpayne@69
|
420 */
|
jpayne@69
|
421 const UnicodeString* getBestSkeleton(const UnicodeString& skeleton,
|
jpayne@69
|
422 int8_t& bestMatchDistanceInfo) const;
|
jpayne@69
|
423
|
jpayne@69
|
424
|
jpayne@69
|
425 /**
|
jpayne@69
|
426 * Parse skeleton, save each field's width.
|
jpayne@69
|
427 * It is used for looking for best match skeleton,
|
jpayne@69
|
428 * and adjust pattern field width.
|
jpayne@69
|
429 * @param skeleton skeleton to be parsed
|
jpayne@69
|
430 * @param skeletonFieldWidth parsed skeleton field width
|
jpayne@69
|
431 */
|
jpayne@69
|
432 static void U_EXPORT2 parseSkeleton(const UnicodeString& skeleton,
|
jpayne@69
|
433 int32_t* skeletonFieldWidth);
|
jpayne@69
|
434
|
jpayne@69
|
435
|
jpayne@69
|
436 /**
|
jpayne@69
|
437 * Check whether one field width is numeric while the other is string.
|
jpayne@69
|
438 *
|
jpayne@69
|
439 * TODO (xji): make it general
|
jpayne@69
|
440 *
|
jpayne@69
|
441 * @param fieldWidth one field width
|
jpayne@69
|
442 * @param anotherFieldWidth another field width
|
jpayne@69
|
443 * @param patternLetter pattern letter char
|
jpayne@69
|
444 * @return true if one field width is numeric and the other is string,
|
jpayne@69
|
445 * false otherwise.
|
jpayne@69
|
446 */
|
jpayne@69
|
447 static UBool U_EXPORT2 stringNumeric(int32_t fieldWidth,
|
jpayne@69
|
448 int32_t anotherFieldWidth,
|
jpayne@69
|
449 char patternLetter);
|
jpayne@69
|
450
|
jpayne@69
|
451
|
jpayne@69
|
452 /**
|
jpayne@69
|
453 * Convert calendar field to the interval pattern index in
|
jpayne@69
|
454 * hash table.
|
jpayne@69
|
455 *
|
jpayne@69
|
456 * Since we only support the following calendar fields:
|
jpayne@69
|
457 * ERA, YEAR, MONTH, DATE, DAY_OF_MONTH, DAY_OF_WEEK,
|
jpayne@69
|
458 * AM_PM, HOUR, HOUR_OF_DAY, MINUTE, SECOND, and MILLISECOND.
|
jpayne@69
|
459 * We reserve only 4 interval patterns for a skeleton.
|
jpayne@69
|
460 *
|
jpayne@69
|
461 * @param field calendar field
|
jpayne@69
|
462 * @param status output param set to success/failure code on exit
|
jpayne@69
|
463 * @return interval pattern index in hash table
|
jpayne@69
|
464 */
|
jpayne@69
|
465 static IntervalPatternIndex U_EXPORT2 calendarFieldToIntervalIndex(
|
jpayne@69
|
466 UCalendarDateFields field,
|
jpayne@69
|
467 UErrorCode& status);
|
jpayne@69
|
468
|
jpayne@69
|
469
|
jpayne@69
|
470 /**
|
jpayne@69
|
471 * delete hash table (of type fIntervalPatterns).
|
jpayne@69
|
472 *
|
jpayne@69
|
473 * @param hTable hash table to be deleted
|
jpayne@69
|
474 */
|
jpayne@69
|
475 void deleteHash(Hashtable* hTable);
|
jpayne@69
|
476
|
jpayne@69
|
477
|
jpayne@69
|
478 /**
|
jpayne@69
|
479 * initialize hash table (of type fIntervalPatterns).
|
jpayne@69
|
480 *
|
jpayne@69
|
481 * @param status output param set to success/failure code on exit
|
jpayne@69
|
482 * @return hash table initialized
|
jpayne@69
|
483 */
|
jpayne@69
|
484 Hashtable* initHash(UErrorCode& status);
|
jpayne@69
|
485
|
jpayne@69
|
486
|
jpayne@69
|
487
|
jpayne@69
|
488 /**
|
jpayne@69
|
489 * copy hash table (of type fIntervalPatterns).
|
jpayne@69
|
490 *
|
jpayne@69
|
491 * @param source the source to copy from
|
jpayne@69
|
492 * @param target the target to copy to
|
jpayne@69
|
493 * @param status output param set to success/failure code on exit
|
jpayne@69
|
494 */
|
jpayne@69
|
495 void copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status);
|
jpayne@69
|
496
|
jpayne@69
|
497
|
jpayne@69
|
498 // data members
|
jpayne@69
|
499 // fallback interval pattern
|
jpayne@69
|
500 UnicodeString fFallbackIntervalPattern;
|
jpayne@69
|
501 // default order
|
jpayne@69
|
502 UBool fFirstDateInPtnIsLaterDate;
|
jpayne@69
|
503
|
jpayne@69
|
504 // HashMap<UnicodeString, UnicodeString[kIPI_MAX_INDEX]>
|
jpayne@69
|
505 // HashMap( skeleton, pattern[largest_different_field] )
|
jpayne@69
|
506 Hashtable* fIntervalPatterns;
|
jpayne@69
|
507
|
jpayne@69
|
508 };// end class DateIntervalInfo
|
jpayne@69
|
509
|
jpayne@69
|
510
|
jpayne@69
|
511 inline UBool
|
jpayne@69
|
512 DateIntervalInfo::operator!=(const DateIntervalInfo& other) const {
|
jpayne@69
|
513 return !operator==(other);
|
jpayne@69
|
514 }
|
jpayne@69
|
515
|
jpayne@69
|
516
|
jpayne@69
|
517 U_NAMESPACE_END
|
jpayne@69
|
518
|
jpayne@69
|
519 #endif
|
jpayne@69
|
520
|
jpayne@69
|
521 #endif /* U_SHOW_CPLUSPLUS_API */
|
jpayne@69
|
522
|
jpayne@69
|
523 #endif
|
jpayne@69
|
524
|