Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /******************************************************************************** |
michael@0 | 2 | * Copyright (C) 2008-2013, International Business Machines Corporation and |
michael@0 | 3 | * others. All Rights Reserved. |
michael@0 | 4 | ******************************************************************************* |
michael@0 | 5 | * |
michael@0 | 6 | * File DTITVFMT.H |
michael@0 | 7 | * |
michael@0 | 8 | ******************************************************************************* |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | #ifndef __DTITVFMT_H__ |
michael@0 | 12 | #define __DTITVFMT_H__ |
michael@0 | 13 | |
michael@0 | 14 | |
michael@0 | 15 | #include "unicode/utypes.h" |
michael@0 | 16 | |
michael@0 | 17 | /** |
michael@0 | 18 | * \file |
michael@0 | 19 | * \brief C++ API: Format and parse date interval in a language-independent manner. |
michael@0 | 20 | */ |
michael@0 | 21 | |
michael@0 | 22 | #if !UCONFIG_NO_FORMATTING |
michael@0 | 23 | |
michael@0 | 24 | #include "unicode/ucal.h" |
michael@0 | 25 | #include "unicode/smpdtfmt.h" |
michael@0 | 26 | #include "unicode/dtintrv.h" |
michael@0 | 27 | #include "unicode/dtitvinf.h" |
michael@0 | 28 | #include "unicode/dtptngen.h" |
michael@0 | 29 | |
michael@0 | 30 | U_NAMESPACE_BEGIN |
michael@0 | 31 | |
michael@0 | 32 | |
michael@0 | 33 | |
michael@0 | 34 | /** |
michael@0 | 35 | * DateIntervalFormat is a class for formatting and parsing date |
michael@0 | 36 | * intervals in a language-independent manner. |
michael@0 | 37 | * Only formatting is supported, parsing is not supported. |
michael@0 | 38 | * |
michael@0 | 39 | * <P> |
michael@0 | 40 | * Date interval means from one date to another date, |
michael@0 | 41 | * for example, from "Jan 11, 2008" to "Jan 18, 2008". |
michael@0 | 42 | * We introduced class DateInterval to represent it. |
michael@0 | 43 | * DateInterval is a pair of UDate, which is |
michael@0 | 44 | * the standard milliseconds since 24:00 GMT, Jan 1, 1970. |
michael@0 | 45 | * |
michael@0 | 46 | * <P> |
michael@0 | 47 | * DateIntervalFormat formats a DateInterval into |
michael@0 | 48 | * text as compactly as possible. |
michael@0 | 49 | * For example, the date interval format from "Jan 11, 2008" to "Jan 18,. 2008" |
michael@0 | 50 | * is "Jan 11-18, 2008" for English. |
michael@0 | 51 | * And it parses text into DateInterval, |
michael@0 | 52 | * although initially, parsing is not supported. |
michael@0 | 53 | * |
michael@0 | 54 | * <P> |
michael@0 | 55 | * There is no structural information in date time patterns. |
michael@0 | 56 | * For any punctuations and string literals inside a date time pattern, |
michael@0 | 57 | * we do not know whether it is just a separator, or a prefix, or a suffix. |
michael@0 | 58 | * Without such information, so, it is difficult to generate a sub-pattern |
michael@0 | 59 | * (or super-pattern) by algorithm. |
michael@0 | 60 | * So, formatting a DateInterval is pattern-driven. It is very |
michael@0 | 61 | * similar to formatting in SimpleDateFormat. |
michael@0 | 62 | * We introduce class DateIntervalInfo to save date interval |
michael@0 | 63 | * patterns, similar to date time pattern in SimpleDateFormat. |
michael@0 | 64 | * |
michael@0 | 65 | * <P> |
michael@0 | 66 | * Logically, the interval patterns are mappings |
michael@0 | 67 | * from (skeleton, the_largest_different_calendar_field) |
michael@0 | 68 | * to (date_interval_pattern). |
michael@0 | 69 | * |
michael@0 | 70 | * <P> |
michael@0 | 71 | * A skeleton |
michael@0 | 72 | * <ol> |
michael@0 | 73 | * <li> |
michael@0 | 74 | * only keeps the field pattern letter and ignores all other parts |
michael@0 | 75 | * in a pattern, such as space, punctuations, and string literals. |
michael@0 | 76 | * </li> |
michael@0 | 77 | * <li> |
michael@0 | 78 | * hides the order of fields. |
michael@0 | 79 | * </li> |
michael@0 | 80 | * <li> |
michael@0 | 81 | * might hide a field's pattern letter length. |
michael@0 | 82 | * </li> |
michael@0 | 83 | * </ol> |
michael@0 | 84 | * |
michael@0 | 85 | * For those non-digit calendar fields, the pattern letter length is |
michael@0 | 86 | * important, such as MMM, MMMM, and MMMMM; EEE and EEEE, |
michael@0 | 87 | * and the field's pattern letter length is honored. |
michael@0 | 88 | * |
michael@0 | 89 | * For the digit calendar fields, such as M or MM, d or dd, yy or yyyy, |
michael@0 | 90 | * the field pattern length is ignored and the best match, which is defined |
michael@0 | 91 | * in date time patterns, will be returned without honor the field pattern |
michael@0 | 92 | * letter length in skeleton. |
michael@0 | 93 | * |
michael@0 | 94 | * <P> |
michael@0 | 95 | * The calendar fields we support for interval formatting are: |
michael@0 | 96 | * year, month, date, day-of-week, am-pm, hour, hour-of-day, and minute. |
michael@0 | 97 | * Those calendar fields can be defined in the following order: |
michael@0 | 98 | * year > month > date > hour (in day) > minute |
michael@0 | 99 | * |
michael@0 | 100 | * The largest different calendar fields between 2 calendars is the |
michael@0 | 101 | * first different calendar field in above order. |
michael@0 | 102 | * |
michael@0 | 103 | * For example: the largest different calendar fields between "Jan 10, 2007" |
michael@0 | 104 | * and "Feb 20, 2008" is year. |
michael@0 | 105 | * |
michael@0 | 106 | * <P> |
michael@0 | 107 | * For other calendar fields, the compact interval formatting is not |
michael@0 | 108 | * supported. And the interval format will be fall back to fall-back |
michael@0 | 109 | * patterns, which is mostly "{date0} - {date1}". |
michael@0 | 110 | * |
michael@0 | 111 | * <P> |
michael@0 | 112 | * There is a set of pre-defined static skeleton strings. |
michael@0 | 113 | * There are pre-defined interval patterns for those pre-defined skeletons |
michael@0 | 114 | * in locales' resource files. |
michael@0 | 115 | * For example, for a skeleton UDAT_YEAR_ABBR_MONTH_DAY, which is "yMMMd", |
michael@0 | 116 | * in en_US, if the largest different calendar field between date1 and date2 |
michael@0 | 117 | * is "year", the date interval pattern is "MMM d, yyyy - MMM d, yyyy", |
michael@0 | 118 | * such as "Jan 10, 2007 - Jan 10, 2008". |
michael@0 | 119 | * If the largest different calendar field between date1 and date2 is "month", |
michael@0 | 120 | * the date interval pattern is "MMM d - MMM d, yyyy", |
michael@0 | 121 | * such as "Jan 10 - Feb 10, 2007". |
michael@0 | 122 | * If the largest different calendar field between date1 and date2 is "day", |
michael@0 | 123 | * the date interval pattern is "MMM d-d, yyyy", such as "Jan 10-20, 2007". |
michael@0 | 124 | * |
michael@0 | 125 | * For date skeleton, the interval patterns when year, or month, or date is |
michael@0 | 126 | * different are defined in resource files. |
michael@0 | 127 | * For time skeleton, the interval patterns when am/pm, or hour, or minute is |
michael@0 | 128 | * different are defined in resource files. |
michael@0 | 129 | * |
michael@0 | 130 | * <P> |
michael@0 | 131 | * If a skeleton is not found in a locale's DateIntervalInfo, which means |
michael@0 | 132 | * the interval patterns for the skeleton is not defined in resource file, |
michael@0 | 133 | * the interval pattern will falls back to the interval "fallback" pattern |
michael@0 | 134 | * defined in resource file. |
michael@0 | 135 | * If the interval "fallback" pattern is not defined, the default fall-back |
michael@0 | 136 | * is "{date0} - {data1}". |
michael@0 | 137 | * |
michael@0 | 138 | * <P> |
michael@0 | 139 | * For the combination of date and time, |
michael@0 | 140 | * The rule to generate interval patterns are: |
michael@0 | 141 | * <ol> |
michael@0 | 142 | * <li> |
michael@0 | 143 | * when the year, month, or day differs, falls back to fall-back |
michael@0 | 144 | * interval pattern, which mostly is the concatenate the two original |
michael@0 | 145 | * expressions with a separator between, |
michael@0 | 146 | * For example, interval pattern from "Jan 10, 2007 10:10 am" |
michael@0 | 147 | * to "Jan 11, 2007 10:10am" is |
michael@0 | 148 | * "Jan 10, 2007 10:10 am - Jan 11, 2007 10:10am" |
michael@0 | 149 | * </li> |
michael@0 | 150 | * <li> |
michael@0 | 151 | * otherwise, present the date followed by the range expression |
michael@0 | 152 | * for the time. |
michael@0 | 153 | * For example, interval pattern from "Jan 10, 2007 10:10 am" |
michael@0 | 154 | * to "Jan 10, 2007 11:10am" is "Jan 10, 2007 10:10 am - 11:10am" |
michael@0 | 155 | * </li> |
michael@0 | 156 | * </ol> |
michael@0 | 157 | * |
michael@0 | 158 | * |
michael@0 | 159 | * <P> |
michael@0 | 160 | * If two dates are the same, the interval pattern is the single date pattern. |
michael@0 | 161 | * For example, interval pattern from "Jan 10, 2007" to "Jan 10, 2007" is |
michael@0 | 162 | * "Jan 10, 2007". |
michael@0 | 163 | * |
michael@0 | 164 | * Or if the presenting fields between 2 dates have the exact same values, |
michael@0 | 165 | * the interval pattern is the single date pattern. |
michael@0 | 166 | * For example, if user only requests year and month, |
michael@0 | 167 | * the interval pattern from "Jan 10, 2007" to "Jan 20, 2007" is "Jan 2007". |
michael@0 | 168 | * |
michael@0 | 169 | * <P> |
michael@0 | 170 | * DateIntervalFormat needs the following information for correct |
michael@0 | 171 | * formatting: time zone, calendar type, pattern, date format symbols, |
michael@0 | 172 | * and date interval patterns. |
michael@0 | 173 | * It can be instantiated in 2 ways: |
michael@0 | 174 | * <ol> |
michael@0 | 175 | * <li> |
michael@0 | 176 | * create an instance using default or given locale plus given skeleton. |
michael@0 | 177 | * Users are encouraged to created date interval formatter this way and |
michael@0 | 178 | * to use the pre-defined skeleton macros, such as |
michael@0 | 179 | * UDAT_YEAR_NUM_MONTH, which consists the calendar fields and |
michael@0 | 180 | * the format style. |
michael@0 | 181 | * </li> |
michael@0 | 182 | * <li> |
michael@0 | 183 | * create an instance using default or given locale plus given skeleton |
michael@0 | 184 | * plus a given DateIntervalInfo. |
michael@0 | 185 | * This factory method is for powerful users who want to provide their own |
michael@0 | 186 | * interval patterns. |
michael@0 | 187 | * Locale provides the timezone, calendar, and format symbols information. |
michael@0 | 188 | * Local plus skeleton provides full pattern information. |
michael@0 | 189 | * DateIntervalInfo provides the date interval patterns. |
michael@0 | 190 | * </li> |
michael@0 | 191 | * </ol> |
michael@0 | 192 | * |
michael@0 | 193 | * <P> |
michael@0 | 194 | * For the calendar field pattern letter, such as G, y, M, d, a, h, H, m, s etc. |
michael@0 | 195 | * DateIntervalFormat uses the same syntax as that of |
michael@0 | 196 | * DateTime format. |
michael@0 | 197 | * |
michael@0 | 198 | * <P> |
michael@0 | 199 | * Code Sample: general usage |
michael@0 | 200 | * <pre> |
michael@0 | 201 | * \code |
michael@0 | 202 | * // the date interval object which the DateIntervalFormat formats on |
michael@0 | 203 | * // and parses into |
michael@0 | 204 | * DateInterval* dtInterval = new DateInterval(1000*3600*24, 1000*3600*24*2); |
michael@0 | 205 | * UErrorCode status = U_ZERO_ERROR; |
michael@0 | 206 | * DateIntervalFormat* dtIntervalFmt = DateIntervalFormat::createInstance( |
michael@0 | 207 | * UDAT_YEAR_MONTH_DAY, |
michael@0 | 208 | * Locale("en", "GB", ""), status); |
michael@0 | 209 | * UnicodeUnicodeString dateIntervalString; |
michael@0 | 210 | * FieldPosition pos = 0; |
michael@0 | 211 | * // formatting |
michael@0 | 212 | * dtIntervalFmt->format(dtInterval, dateIntervalUnicodeString, pos, status); |
michael@0 | 213 | * delete dtIntervalFmt; |
michael@0 | 214 | * \endcode |
michael@0 | 215 | * </pre> |
michael@0 | 216 | */ |
michael@0 | 217 | |
michael@0 | 218 | class U_I18N_API DateIntervalFormat : public Format { |
michael@0 | 219 | public: |
michael@0 | 220 | |
michael@0 | 221 | /** |
michael@0 | 222 | * Construct a DateIntervalFormat from skeleton and the default locale. |
michael@0 | 223 | * |
michael@0 | 224 | * This is a convenient override of |
michael@0 | 225 | * createInstance(const UnicodeString& skeleton, const Locale& locale, |
michael@0 | 226 | * UErrorCode&) |
michael@0 | 227 | * with the value of locale as default locale. |
michael@0 | 228 | * |
michael@0 | 229 | * @param skeleton the skeleton on which interval format based. |
michael@0 | 230 | * @param status output param set to success/failure code on exit |
michael@0 | 231 | * @return a date time interval formatter which the caller owns. |
michael@0 | 232 | * @stable ICU 4.0 |
michael@0 | 233 | */ |
michael@0 | 234 | static DateIntervalFormat* U_EXPORT2 createInstance( |
michael@0 | 235 | const UnicodeString& skeleton, |
michael@0 | 236 | UErrorCode& status); |
michael@0 | 237 | |
michael@0 | 238 | /** |
michael@0 | 239 | * Construct a DateIntervalFormat from skeleton and a given locale. |
michael@0 | 240 | * <P> |
michael@0 | 241 | * In this factory method, |
michael@0 | 242 | * the date interval pattern information is load from resource files. |
michael@0 | 243 | * Users are encouraged to created date interval formatter this way and |
michael@0 | 244 | * to use the pre-defined skeleton macros. |
michael@0 | 245 | * |
michael@0 | 246 | * <P> |
michael@0 | 247 | * There are pre-defined skeletons (defined in udate.h) having predefined |
michael@0 | 248 | * interval patterns in resource files. |
michael@0 | 249 | * Users are encouraged to use those macros. |
michael@0 | 250 | * For example: |
michael@0 | 251 | * DateIntervalFormat::createInstance(UDAT_MONTH_DAY, status) |
michael@0 | 252 | * |
michael@0 | 253 | * The given Locale provides the interval patterns. |
michael@0 | 254 | * For example, for en_GB, if skeleton is UDAT_YEAR_ABBR_MONTH_WEEKDAY_DAY, |
michael@0 | 255 | * which is "yMMMEEEd", |
michael@0 | 256 | * the interval patterns defined in resource file to above skeleton are: |
michael@0 | 257 | * "EEE, d MMM, yyyy - EEE, d MMM, yyyy" for year differs, |
michael@0 | 258 | * "EEE, d MMM - EEE, d MMM, yyyy" for month differs, |
michael@0 | 259 | * "EEE, d - EEE, d MMM, yyyy" for day differs, |
michael@0 | 260 | * @param skeleton the skeleton on which the interval format is based. |
michael@0 | 261 | * @param locale the given locale |
michael@0 | 262 | * @param status output param set to success/failure code on exit |
michael@0 | 263 | * @return a date time interval formatter which the caller owns. |
michael@0 | 264 | * @stable ICU 4.0 |
michael@0 | 265 | * <p> |
michael@0 | 266 | * <h4>Sample code</h4> |
michael@0 | 267 | * \snippet samples/dtitvfmtsample/dtitvfmtsample.cpp dtitvfmtPreDefined1 |
michael@0 | 268 | * \snippet samples/dtitvfmtsample/dtitvfmtsample.cpp dtitvfmtPreDefined |
michael@0 | 269 | * <p> |
michael@0 | 270 | */ |
michael@0 | 271 | |
michael@0 | 272 | static DateIntervalFormat* U_EXPORT2 createInstance( |
michael@0 | 273 | const UnicodeString& skeleton, |
michael@0 | 274 | const Locale& locale, |
michael@0 | 275 | UErrorCode& status); |
michael@0 | 276 | |
michael@0 | 277 | /** |
michael@0 | 278 | * Construct a DateIntervalFormat from skeleton |
michael@0 | 279 | * DateIntervalInfo, and default locale. |
michael@0 | 280 | * |
michael@0 | 281 | * This is a convenient override of |
michael@0 | 282 | * createInstance(const UnicodeString& skeleton, const Locale& locale, |
michael@0 | 283 | * const DateIntervalInfo& dtitvinf, UErrorCode&) |
michael@0 | 284 | * with the locale value as default locale. |
michael@0 | 285 | * |
michael@0 | 286 | * @param skeleton the skeleton on which interval format based. |
michael@0 | 287 | * @param dtitvinf the DateIntervalInfo object. |
michael@0 | 288 | * @param status output param set to success/failure code on exit |
michael@0 | 289 | * @return a date time interval formatter which the caller owns. |
michael@0 | 290 | * @stable ICU 4.0 |
michael@0 | 291 | */ |
michael@0 | 292 | static DateIntervalFormat* U_EXPORT2 createInstance( |
michael@0 | 293 | const UnicodeString& skeleton, |
michael@0 | 294 | const DateIntervalInfo& dtitvinf, |
michael@0 | 295 | UErrorCode& status); |
michael@0 | 296 | |
michael@0 | 297 | /** |
michael@0 | 298 | * Construct a DateIntervalFormat from skeleton |
michael@0 | 299 | * a DateIntervalInfo, and the given locale. |
michael@0 | 300 | * |
michael@0 | 301 | * <P> |
michael@0 | 302 | * In this factory method, user provides its own date interval pattern |
michael@0 | 303 | * information, instead of using those pre-defined data in resource file. |
michael@0 | 304 | * This factory method is for powerful users who want to provide their own |
michael@0 | 305 | * interval patterns. |
michael@0 | 306 | * <P> |
michael@0 | 307 | * There are pre-defined skeletons (defined in udate.h) having predefined |
michael@0 | 308 | * interval patterns in resource files. |
michael@0 | 309 | * Users are encouraged to use those macros. |
michael@0 | 310 | * For example: |
michael@0 | 311 | * DateIntervalFormat::createInstance(UDAT_MONTH_DAY, status) |
michael@0 | 312 | * |
michael@0 | 313 | * The DateIntervalInfo provides the interval patterns. |
michael@0 | 314 | * and the DateIntervalInfo ownership remains to the caller. |
michael@0 | 315 | * |
michael@0 | 316 | * User are encouraged to set default interval pattern in DateIntervalInfo |
michael@0 | 317 | * as well, if they want to set other interval patterns ( instead of |
michael@0 | 318 | * reading the interval patterns from resource files). |
michael@0 | 319 | * When the corresponding interval pattern for a largest calendar different |
michael@0 | 320 | * field is not found ( if user not set it ), interval format fallback to |
michael@0 | 321 | * the default interval pattern. |
michael@0 | 322 | * If user does not provide default interval pattern, it fallback to |
michael@0 | 323 | * "{date0} - {date1}" |
michael@0 | 324 | * |
michael@0 | 325 | * @param skeleton the skeleton on which interval format based. |
michael@0 | 326 | * @param locale the given locale |
michael@0 | 327 | * @param dtitvinf the DateIntervalInfo object. |
michael@0 | 328 | * @param status output param set to success/failure code on exit |
michael@0 | 329 | * @return a date time interval formatter which the caller owns. |
michael@0 | 330 | * @stable ICU 4.0 |
michael@0 | 331 | * <p> |
michael@0 | 332 | * <h4>Sample code</h4> |
michael@0 | 333 | * \snippet samples/dtitvfmtsample/dtitvfmtsample.cpp dtitvfmtPreDefined1 |
michael@0 | 334 | * \snippet samples/dtitvfmtsample/dtitvfmtsample.cpp dtitvfmtCustomized |
michael@0 | 335 | * <p> |
michael@0 | 336 | */ |
michael@0 | 337 | static DateIntervalFormat* U_EXPORT2 createInstance( |
michael@0 | 338 | const UnicodeString& skeleton, |
michael@0 | 339 | const Locale& locale, |
michael@0 | 340 | const DateIntervalInfo& dtitvinf, |
michael@0 | 341 | UErrorCode& status); |
michael@0 | 342 | |
michael@0 | 343 | /** |
michael@0 | 344 | * Destructor. |
michael@0 | 345 | * @stable ICU 4.0 |
michael@0 | 346 | */ |
michael@0 | 347 | virtual ~DateIntervalFormat(); |
michael@0 | 348 | |
michael@0 | 349 | /** |
michael@0 | 350 | * Clone this Format object polymorphically. The caller owns the result and |
michael@0 | 351 | * should delete it when done. |
michael@0 | 352 | * @return A copy of the object. |
michael@0 | 353 | * @stable ICU 4.0 |
michael@0 | 354 | */ |
michael@0 | 355 | virtual Format* clone(void) const; |
michael@0 | 356 | |
michael@0 | 357 | /** |
michael@0 | 358 | * Return true if the given Format objects are semantically equal. Objects |
michael@0 | 359 | * of different subclasses are considered unequal. |
michael@0 | 360 | * @param other the object to be compared with. |
michael@0 | 361 | * @return true if the given Format objects are semantically equal. |
michael@0 | 362 | * @stable ICU 4.0 |
michael@0 | 363 | */ |
michael@0 | 364 | virtual UBool operator==(const Format& other) const; |
michael@0 | 365 | |
michael@0 | 366 | /** |
michael@0 | 367 | * Return true if the given Format objects are not semantically equal. |
michael@0 | 368 | * Objects of different subclasses are considered unequal. |
michael@0 | 369 | * @param other the object to be compared with. |
michael@0 | 370 | * @return true if the given Format objects are not semantically equal. |
michael@0 | 371 | * @stable ICU 4.0 |
michael@0 | 372 | */ |
michael@0 | 373 | UBool operator!=(const Format& other) const; |
michael@0 | 374 | |
michael@0 | 375 | |
michael@0 | 376 | using Format::format; |
michael@0 | 377 | |
michael@0 | 378 | /** |
michael@0 | 379 | * Format an object to produce a string. This method handles Formattable |
michael@0 | 380 | * objects with a DateInterval type. |
michael@0 | 381 | * If a the Formattable object type is not a DateInterval, |
michael@0 | 382 | * then it returns a failing UErrorCode. |
michael@0 | 383 | * |
michael@0 | 384 | * @param obj The object to format. |
michael@0 | 385 | * Must be a DateInterval. |
michael@0 | 386 | * @param appendTo Output parameter to receive result. |
michael@0 | 387 | * Result is appended to existing contents. |
michael@0 | 388 | * @param fieldPosition On input: an alignment field, if desired. |
michael@0 | 389 | * On output: the offsets of the alignment field. |
michael@0 | 390 | * @param status Output param filled with success/failure status. |
michael@0 | 391 | * @return Reference to 'appendTo' parameter. |
michael@0 | 392 | * @stable ICU 4.0 |
michael@0 | 393 | */ |
michael@0 | 394 | virtual UnicodeString& format(const Formattable& obj, |
michael@0 | 395 | UnicodeString& appendTo, |
michael@0 | 396 | FieldPosition& fieldPosition, |
michael@0 | 397 | UErrorCode& status) const ; |
michael@0 | 398 | |
michael@0 | 399 | |
michael@0 | 400 | |
michael@0 | 401 | /** |
michael@0 | 402 | * Format a DateInterval to produce a string. |
michael@0 | 403 | * |
michael@0 | 404 | * @param dtInterval DateInterval to be formatted. |
michael@0 | 405 | * @param appendTo Output parameter to receive result. |
michael@0 | 406 | * Result is appended to existing contents. |
michael@0 | 407 | * @param fieldPosition On input: an alignment field, if desired. |
michael@0 | 408 | * On output: the offsets of the alignment field. |
michael@0 | 409 | * @param status Output param filled with success/failure status. |
michael@0 | 410 | * @return Reference to 'appendTo' parameter. |
michael@0 | 411 | * @stable ICU 4.0 |
michael@0 | 412 | */ |
michael@0 | 413 | UnicodeString& format(const DateInterval* dtInterval, |
michael@0 | 414 | UnicodeString& appendTo, |
michael@0 | 415 | FieldPosition& fieldPosition, |
michael@0 | 416 | UErrorCode& status) const ; |
michael@0 | 417 | |
michael@0 | 418 | |
michael@0 | 419 | /** |
michael@0 | 420 | * Format 2 Calendars to produce a string. |
michael@0 | 421 | * |
michael@0 | 422 | * Note: "fromCalendar" and "toCalendar" are not const, |
michael@0 | 423 | * since calendar is not const in SimpleDateFormat::format(Calendar&), |
michael@0 | 424 | * |
michael@0 | 425 | * @param fromCalendar calendar set to the from date in date interval |
michael@0 | 426 | * to be formatted into date interval string |
michael@0 | 427 | * @param toCalendar calendar set to the to date in date interval |
michael@0 | 428 | * to be formatted into date interval string |
michael@0 | 429 | * @param appendTo Output parameter to receive result. |
michael@0 | 430 | * Result is appended to existing contents. |
michael@0 | 431 | * @param fieldPosition On input: an alignment field, if desired. |
michael@0 | 432 | * On output: the offsets of the alignment field. |
michael@0 | 433 | * @param status Output param filled with success/failure status. |
michael@0 | 434 | * Caller needs to make sure it is SUCCESS |
michael@0 | 435 | * at the function entrance |
michael@0 | 436 | * @return Reference to 'appendTo' parameter. |
michael@0 | 437 | * @stable ICU 4.0 |
michael@0 | 438 | */ |
michael@0 | 439 | UnicodeString& format(Calendar& fromCalendar, |
michael@0 | 440 | Calendar& toCalendar, |
michael@0 | 441 | UnicodeString& appendTo, |
michael@0 | 442 | FieldPosition& fieldPosition, |
michael@0 | 443 | UErrorCode& status) const ; |
michael@0 | 444 | |
michael@0 | 445 | /** |
michael@0 | 446 | * Date interval parsing is not supported. Please do not use. |
michael@0 | 447 | * <P> |
michael@0 | 448 | * This method should handle parsing of |
michael@0 | 449 | * date time interval strings into Formattable objects with |
michael@0 | 450 | * DateInterval type, which is a pair of UDate. |
michael@0 | 451 | * <P> |
michael@0 | 452 | * Before calling, set parse_pos.index to the offset you want to start |
michael@0 | 453 | * parsing at in the source. After calling, parse_pos.index is the end of |
michael@0 | 454 | * the text you parsed. If error occurs, index is unchanged. |
michael@0 | 455 | * <P> |
michael@0 | 456 | * When parsing, leading whitespace is discarded (with a successful parse), |
michael@0 | 457 | * while trailing whitespace is left as is. |
michael@0 | 458 | * <P> |
michael@0 | 459 | * See Format::parseObject() for more. |
michael@0 | 460 | * |
michael@0 | 461 | * @param source The string to be parsed into an object. |
michael@0 | 462 | * @param result Formattable to be set to the parse result. |
michael@0 | 463 | * If parse fails, return contents are undefined. |
michael@0 | 464 | * @param parse_pos The position to start parsing at. Since no parsing |
michael@0 | 465 | * is supported, upon return this param is unchanged. |
michael@0 | 466 | * @return A newly created Formattable* object, or NULL |
michael@0 | 467 | * on failure. The caller owns this and should |
michael@0 | 468 | * delete it when done. |
michael@0 | 469 | * @internal ICU 4.0 |
michael@0 | 470 | */ |
michael@0 | 471 | virtual void parseObject(const UnicodeString& source, |
michael@0 | 472 | Formattable& result, |
michael@0 | 473 | ParsePosition& parse_pos) const; |
michael@0 | 474 | |
michael@0 | 475 | |
michael@0 | 476 | /** |
michael@0 | 477 | * Gets the date time interval patterns. |
michael@0 | 478 | * @return the date time interval patterns associated with |
michael@0 | 479 | * this date interval formatter. |
michael@0 | 480 | * @stable ICU 4.0 |
michael@0 | 481 | */ |
michael@0 | 482 | const DateIntervalInfo* getDateIntervalInfo(void) const; |
michael@0 | 483 | |
michael@0 | 484 | |
michael@0 | 485 | /** |
michael@0 | 486 | * Set the date time interval patterns. |
michael@0 | 487 | * @param newIntervalPatterns the given interval patterns to copy. |
michael@0 | 488 | * @param status output param set to success/failure code on exit |
michael@0 | 489 | * @stable ICU 4.0 |
michael@0 | 490 | */ |
michael@0 | 491 | void setDateIntervalInfo(const DateIntervalInfo& newIntervalPatterns, |
michael@0 | 492 | UErrorCode& status); |
michael@0 | 493 | |
michael@0 | 494 | |
michael@0 | 495 | /** |
michael@0 | 496 | * Gets the date formatter |
michael@0 | 497 | * @return the date formatter associated with this date interval formatter. |
michael@0 | 498 | * @stable ICU 4.0 |
michael@0 | 499 | */ |
michael@0 | 500 | const DateFormat* getDateFormat(void) const; |
michael@0 | 501 | |
michael@0 | 502 | /** |
michael@0 | 503 | * Returns a reference to the TimeZone used by this DateIntervalFormat's calendar. |
michael@0 | 504 | * @return the time zone associated with the calendar of DateIntervalFormat. |
michael@0 | 505 | * @stable ICU 4.8 |
michael@0 | 506 | */ |
michael@0 | 507 | virtual const TimeZone& getTimeZone(void) const; |
michael@0 | 508 | |
michael@0 | 509 | /** |
michael@0 | 510 | * Sets the time zone for the calendar used by this DateIntervalFormat object. The |
michael@0 | 511 | * caller no longer owns the TimeZone object and should not delete it after this call. |
michael@0 | 512 | * @param zoneToAdopt the TimeZone to be adopted. |
michael@0 | 513 | * @stable ICU 4.8 |
michael@0 | 514 | */ |
michael@0 | 515 | virtual void adoptTimeZone(TimeZone* zoneToAdopt); |
michael@0 | 516 | |
michael@0 | 517 | /** |
michael@0 | 518 | * Sets the time zone for the calendar used by this DateIntervalFormat object. |
michael@0 | 519 | * @param zone the new time zone. |
michael@0 | 520 | * @stable ICU 4.8 |
michael@0 | 521 | */ |
michael@0 | 522 | virtual void setTimeZone(const TimeZone& zone); |
michael@0 | 523 | |
michael@0 | 524 | /** |
michael@0 | 525 | * Return the class ID for this class. This is useful only for comparing to |
michael@0 | 526 | * a return value from getDynamicClassID(). For example: |
michael@0 | 527 | * <pre> |
michael@0 | 528 | * . Base* polymorphic_pointer = createPolymorphicObject(); |
michael@0 | 529 | * . if (polymorphic_pointer->getDynamicClassID() == |
michael@0 | 530 | * . erived::getStaticClassID()) ... |
michael@0 | 531 | * </pre> |
michael@0 | 532 | * @return The class ID for all objects of this class. |
michael@0 | 533 | * @stable ICU 4.0 |
michael@0 | 534 | */ |
michael@0 | 535 | static UClassID U_EXPORT2 getStaticClassID(void); |
michael@0 | 536 | |
michael@0 | 537 | /** |
michael@0 | 538 | * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This |
michael@0 | 539 | * method is to implement a simple version of RTTI, since not all C++ |
michael@0 | 540 | * compilers support genuine RTTI. Polymorphic operator==() and clone() |
michael@0 | 541 | * methods call this method. |
michael@0 | 542 | * |
michael@0 | 543 | * @return The class ID for this object. All objects of a |
michael@0 | 544 | * given class have the same class ID. Objects of |
michael@0 | 545 | * other classes have different class IDs. |
michael@0 | 546 | * @stable ICU 4.0 |
michael@0 | 547 | */ |
michael@0 | 548 | virtual UClassID getDynamicClassID(void) const; |
michael@0 | 549 | |
michael@0 | 550 | protected: |
michael@0 | 551 | |
michael@0 | 552 | /** |
michael@0 | 553 | * Copy constructor. |
michael@0 | 554 | * @stable ICU 4.0 |
michael@0 | 555 | */ |
michael@0 | 556 | DateIntervalFormat(const DateIntervalFormat&); |
michael@0 | 557 | |
michael@0 | 558 | /** |
michael@0 | 559 | * Assignment operator. |
michael@0 | 560 | * @stable ICU 4.0 |
michael@0 | 561 | */ |
michael@0 | 562 | DateIntervalFormat& operator=(const DateIntervalFormat&); |
michael@0 | 563 | |
michael@0 | 564 | private: |
michael@0 | 565 | |
michael@0 | 566 | /* |
michael@0 | 567 | * This is for ICU internal use only. Please do not use. |
michael@0 | 568 | * Save the interval pattern information. |
michael@0 | 569 | * Interval pattern consists of 2 single date patterns and the separator. |
michael@0 | 570 | * For example, interval pattern "MMM d - MMM d, yyyy" consists |
michael@0 | 571 | * a single date pattern "MMM d", another single date pattern "MMM d, yyyy", |
michael@0 | 572 | * and a separator "-". |
michael@0 | 573 | * The pattern is divided into 2 parts. For above example, |
michael@0 | 574 | * the first part is "MMM d - ", and the second part is "MMM d, yyyy". |
michael@0 | 575 | * Also, the first date appears in an interval pattern could be |
michael@0 | 576 | * the earlier date or the later date. |
michael@0 | 577 | * And such information is saved in the interval pattern as well. |
michael@0 | 578 | */ |
michael@0 | 579 | struct PatternInfo { |
michael@0 | 580 | UnicodeString firstPart; |
michael@0 | 581 | UnicodeString secondPart; |
michael@0 | 582 | /** |
michael@0 | 583 | * Whether the first date in interval pattern is later date or not. |
michael@0 | 584 | * Fallback format set the default ordering. |
michael@0 | 585 | * And for a particular interval pattern, the order can be |
michael@0 | 586 | * overriden by prefixing the interval pattern with "latestFirst:" or |
michael@0 | 587 | * "earliestFirst:" |
michael@0 | 588 | * For example, given 2 date, Jan 10, 2007 to Feb 10, 2007. |
michael@0 | 589 | * if the fallback format is "{0} - {1}", |
michael@0 | 590 | * and the pattern is "d MMM - d MMM yyyy", the interval format is |
michael@0 | 591 | * "10 Jan - 10 Feb, 2007". |
michael@0 | 592 | * If the pattern is "latestFirst:d MMM - d MMM yyyy", |
michael@0 | 593 | * the interval format is "10 Feb - 10 Jan, 2007" |
michael@0 | 594 | */ |
michael@0 | 595 | UBool laterDateFirst; |
michael@0 | 596 | }; |
michael@0 | 597 | |
michael@0 | 598 | |
michael@0 | 599 | /** |
michael@0 | 600 | * default constructor |
michael@0 | 601 | * @internal ICU 4.0 |
michael@0 | 602 | */ |
michael@0 | 603 | DateIntervalFormat(); |
michael@0 | 604 | |
michael@0 | 605 | /** |
michael@0 | 606 | * Construct a DateIntervalFormat from DateFormat, |
michael@0 | 607 | * a DateIntervalInfo, and skeleton. |
michael@0 | 608 | * DateFormat provides the timezone, calendar, |
michael@0 | 609 | * full pattern, and date format symbols information. |
michael@0 | 610 | * It should be a SimpleDateFormat object which |
michael@0 | 611 | * has a pattern in it. |
michael@0 | 612 | * the DateIntervalInfo provides the interval patterns. |
michael@0 | 613 | * |
michael@0 | 614 | * Note: the DateIntervalFormat takes ownership of both |
michael@0 | 615 | * DateFormat and DateIntervalInfo objects. |
michael@0 | 616 | * Caller should not delete them. |
michael@0 | 617 | * |
michael@0 | 618 | * @param locale the locale of this date interval formatter. |
michael@0 | 619 | * @param dtItvInfo the DateIntervalInfo object to be adopted. |
michael@0 | 620 | * @param skeleton the skeleton of the date formatter |
michael@0 | 621 | * @param status output param set to success/failure code on exit |
michael@0 | 622 | */ |
michael@0 | 623 | DateIntervalFormat(const Locale& locale, DateIntervalInfo* dtItvInfo, |
michael@0 | 624 | const UnicodeString* skeleton, UErrorCode& status); |
michael@0 | 625 | |
michael@0 | 626 | |
michael@0 | 627 | /** |
michael@0 | 628 | * Construct a DateIntervalFormat from DateFormat |
michael@0 | 629 | * and a DateIntervalInfo. |
michael@0 | 630 | * |
michael@0 | 631 | * It is a wrapper of the constructor. |
michael@0 | 632 | * |
michael@0 | 633 | * @param locale the locale of this date interval formatter. |
michael@0 | 634 | * @param dtitvinf the DateIntervalInfo object to be adopted. |
michael@0 | 635 | * @param skeleton the skeleton of this formatter. |
michael@0 | 636 | * @param status Output param set to success/failure code. |
michael@0 | 637 | * @return a date time interval formatter which the caller owns. |
michael@0 | 638 | */ |
michael@0 | 639 | static DateIntervalFormat* U_EXPORT2 create(const Locale& locale, |
michael@0 | 640 | DateIntervalInfo* dtitvinf, |
michael@0 | 641 | const UnicodeString* skeleton, |
michael@0 | 642 | UErrorCode& status); |
michael@0 | 643 | |
michael@0 | 644 | /** |
michael@0 | 645 | * Create a simple date/time formatter from skeleton, given locale, |
michael@0 | 646 | * and date time pattern generator. |
michael@0 | 647 | * |
michael@0 | 648 | * @param skeleton the skeleton on which date format based. |
michael@0 | 649 | * @param locale the given locale. |
michael@0 | 650 | * @param dtpng the date time pattern generator. |
michael@0 | 651 | * @param status Output param to be set to success/failure code. |
michael@0 | 652 | * If it is failure, the returned date formatter will |
michael@0 | 653 | * be NULL. |
michael@0 | 654 | * @return a simple date formatter which the caller owns. |
michael@0 | 655 | */ |
michael@0 | 656 | static SimpleDateFormat* U_EXPORT2 createSDFPatternInstance( |
michael@0 | 657 | const UnicodeString& skeleton, |
michael@0 | 658 | const Locale& locale, |
michael@0 | 659 | DateTimePatternGenerator* dtpng, |
michael@0 | 660 | UErrorCode& status); |
michael@0 | 661 | |
michael@0 | 662 | |
michael@0 | 663 | /** |
michael@0 | 664 | * Below are for generating interval patterns local to the formatter |
michael@0 | 665 | */ |
michael@0 | 666 | |
michael@0 | 667 | |
michael@0 | 668 | /** |
michael@0 | 669 | * Format 2 Calendars using fall-back interval pattern |
michael@0 | 670 | * |
michael@0 | 671 | * The full pattern used in this fall-back format is the |
michael@0 | 672 | * full pattern of the date formatter. |
michael@0 | 673 | * |
michael@0 | 674 | * @param fromCalendar calendar set to the from date in date interval |
michael@0 | 675 | * to be formatted into date interval string |
michael@0 | 676 | * @param toCalendar calendar set to the to date in date interval |
michael@0 | 677 | * to be formatted into date interval string |
michael@0 | 678 | * @param appendTo Output parameter to receive result. |
michael@0 | 679 | * Result is appended to existing contents. |
michael@0 | 680 | * @param pos On input: an alignment field, if desired. |
michael@0 | 681 | * On output: the offsets of the alignment field. |
michael@0 | 682 | * @param status output param set to success/failure code on exit |
michael@0 | 683 | * @return Reference to 'appendTo' parameter. |
michael@0 | 684 | */ |
michael@0 | 685 | UnicodeString& fallbackFormat(Calendar& fromCalendar, |
michael@0 | 686 | Calendar& toCalendar, |
michael@0 | 687 | UnicodeString& appendTo, |
michael@0 | 688 | FieldPosition& pos, |
michael@0 | 689 | UErrorCode& status) const; |
michael@0 | 690 | |
michael@0 | 691 | |
michael@0 | 692 | |
michael@0 | 693 | /** |
michael@0 | 694 | * Initialize interval patterns locale to this formatter |
michael@0 | 695 | * |
michael@0 | 696 | * This code is a bit complicated since |
michael@0 | 697 | * 1. the interval patterns saved in resource bundle files are interval |
michael@0 | 698 | * patterns based on date or time only. |
michael@0 | 699 | * It does not have interval patterns based on both date and time. |
michael@0 | 700 | * Interval patterns on both date and time are algorithm generated. |
michael@0 | 701 | * |
michael@0 | 702 | * For example, it has interval patterns on skeleton "dMy" and "hm", |
michael@0 | 703 | * but it does not have interval patterns on skeleton "dMyhm". |
michael@0 | 704 | * |
michael@0 | 705 | * The rule to generate interval patterns for both date and time skeleton are |
michael@0 | 706 | * 1) when the year, month, or day differs, concatenate the two original |
michael@0 | 707 | * expressions with a separator between, |
michael@0 | 708 | * For example, interval pattern from "Jan 10, 2007 10:10 am" |
michael@0 | 709 | * to "Jan 11, 2007 10:10am" is |
michael@0 | 710 | * "Jan 10, 2007 10:10 am - Jan 11, 2007 10:10am" |
michael@0 | 711 | * |
michael@0 | 712 | * 2) otherwise, present the date followed by the range expression |
michael@0 | 713 | * for the time. |
michael@0 | 714 | * For example, interval pattern from "Jan 10, 2007 10:10 am" |
michael@0 | 715 | * to "Jan 10, 2007 11:10am" is |
michael@0 | 716 | * "Jan 10, 2007 10:10 am - 11:10am" |
michael@0 | 717 | * |
michael@0 | 718 | * 2. even a pattern does not request a certain calendar field, |
michael@0 | 719 | * the interval pattern needs to include such field if such fields are |
michael@0 | 720 | * different between 2 dates. |
michael@0 | 721 | * For example, a pattern/skeleton is "hm", but the interval pattern |
michael@0 | 722 | * includes year, month, and date when year, month, and date differs. |
michael@0 | 723 | * |
michael@0 | 724 | * |
michael@0 | 725 | * @param status output param set to success/failure code on exit |
michael@0 | 726 | */ |
michael@0 | 727 | void initializePattern(UErrorCode& status); |
michael@0 | 728 | |
michael@0 | 729 | |
michael@0 | 730 | |
michael@0 | 731 | /** |
michael@0 | 732 | * Set fall back interval pattern given a calendar field, |
michael@0 | 733 | * a skeleton, and a date time pattern generator. |
michael@0 | 734 | * @param field the largest different calendar field |
michael@0 | 735 | * @param skeleton a skeleton |
michael@0 | 736 | * @param status output param set to success/failure code on exit |
michael@0 | 737 | */ |
michael@0 | 738 | void setFallbackPattern(UCalendarDateFields field, |
michael@0 | 739 | const UnicodeString& skeleton, |
michael@0 | 740 | UErrorCode& status); |
michael@0 | 741 | |
michael@0 | 742 | |
michael@0 | 743 | |
michael@0 | 744 | /** |
michael@0 | 745 | * get separated date and time skeleton from a combined skeleton. |
michael@0 | 746 | * |
michael@0 | 747 | * The difference between date skeleton and normalizedDateSkeleton are: |
michael@0 | 748 | * 1. both 'y' and 'd' are appeared only once in normalizeDateSkeleton |
michael@0 | 749 | * 2. 'E' and 'EE' are normalized into 'EEE' |
michael@0 | 750 | * 3. 'MM' is normalized into 'M' |
michael@0 | 751 | * |
michael@0 | 752 | ** the difference between time skeleton and normalizedTimeSkeleton are: |
michael@0 | 753 | * 1. both 'H' and 'h' are normalized as 'h' in normalized time skeleton, |
michael@0 | 754 | * 2. 'a' is omitted in normalized time skeleton. |
michael@0 | 755 | * 3. there is only one appearance for 'h', 'm','v', 'z' in normalized time |
michael@0 | 756 | * skeleton |
michael@0 | 757 | * |
michael@0 | 758 | * |
michael@0 | 759 | * @param skeleton given combined skeleton. |
michael@0 | 760 | * @param date Output parameter for date only skeleton. |
michael@0 | 761 | * @param normalizedDate Output parameter for normalized date only |
michael@0 | 762 | * |
michael@0 | 763 | * @param time Output parameter for time only skeleton. |
michael@0 | 764 | * @param normalizedTime Output parameter for normalized time only |
michael@0 | 765 | * skeleton. |
michael@0 | 766 | * |
michael@0 | 767 | */ |
michael@0 | 768 | static void U_EXPORT2 getDateTimeSkeleton(const UnicodeString& skeleton, |
michael@0 | 769 | UnicodeString& date, |
michael@0 | 770 | UnicodeString& normalizedDate, |
michael@0 | 771 | UnicodeString& time, |
michael@0 | 772 | UnicodeString& normalizedTime); |
michael@0 | 773 | |
michael@0 | 774 | |
michael@0 | 775 | |
michael@0 | 776 | /** |
michael@0 | 777 | * Generate date or time interval pattern from resource, |
michael@0 | 778 | * and set them into the interval pattern locale to this formatter. |
michael@0 | 779 | * |
michael@0 | 780 | * It needs to handle the following: |
michael@0 | 781 | * 1. need to adjust field width. |
michael@0 | 782 | * For example, the interval patterns saved in DateIntervalInfo |
michael@0 | 783 | * includes "dMMMy", but not "dMMMMy". |
michael@0 | 784 | * Need to get interval patterns for dMMMMy from dMMMy. |
michael@0 | 785 | * Another example, the interval patterns saved in DateIntervalInfo |
michael@0 | 786 | * includes "hmv", but not "hmz". |
michael@0 | 787 | * Need to get interval patterns for "hmz' from 'hmv' |
michael@0 | 788 | * |
michael@0 | 789 | * 2. there might be no pattern for 'y' differ for skeleton "Md", |
michael@0 | 790 | * in order to get interval patterns for 'y' differ, |
michael@0 | 791 | * need to look for it from skeleton 'yMd' |
michael@0 | 792 | * |
michael@0 | 793 | * @param dateSkeleton normalized date skeleton |
michael@0 | 794 | * @param timeSkeleton normalized time skeleton |
michael@0 | 795 | * @return whether the resource is found for the skeleton. |
michael@0 | 796 | * TRUE if interval pattern found for the skeleton, |
michael@0 | 797 | * FALSE otherwise. |
michael@0 | 798 | */ |
michael@0 | 799 | UBool setSeparateDateTimePtn(const UnicodeString& dateSkeleton, |
michael@0 | 800 | const UnicodeString& timeSkeleton); |
michael@0 | 801 | |
michael@0 | 802 | |
michael@0 | 803 | |
michael@0 | 804 | |
michael@0 | 805 | /** |
michael@0 | 806 | * Generate interval pattern from existing resource |
michael@0 | 807 | * |
michael@0 | 808 | * It not only save the interval patterns, |
michael@0 | 809 | * but also return the extended skeleton and its best match skeleton. |
michael@0 | 810 | * |
michael@0 | 811 | * @param field largest different calendar field |
michael@0 | 812 | * @param skeleton skeleton |
michael@0 | 813 | * @param bestSkeleton the best match skeleton which has interval pattern |
michael@0 | 814 | * defined in resource |
michael@0 | 815 | * @param differenceInfo the difference between skeleton and best skeleton |
michael@0 | 816 | * 0 means the best matched skeleton is the same as input skeleton |
michael@0 | 817 | * 1 means the fields are the same, but field width are different |
michael@0 | 818 | * 2 means the only difference between fields are v/z, |
michael@0 | 819 | * -1 means there are other fields difference |
michael@0 | 820 | * |
michael@0 | 821 | * @param extendedSkeleton extended skeleton |
michael@0 | 822 | * @param extendedBestSkeleton extended best match skeleton |
michael@0 | 823 | * @return whether the interval pattern is found |
michael@0 | 824 | * through extending skeleton or not. |
michael@0 | 825 | * TRUE if interval pattern is found by |
michael@0 | 826 | * extending skeleton, FALSE otherwise. |
michael@0 | 827 | */ |
michael@0 | 828 | UBool setIntervalPattern(UCalendarDateFields field, |
michael@0 | 829 | const UnicodeString* skeleton, |
michael@0 | 830 | const UnicodeString* bestSkeleton, |
michael@0 | 831 | int8_t differenceInfo, |
michael@0 | 832 | UnicodeString* extendedSkeleton = NULL, |
michael@0 | 833 | UnicodeString* extendedBestSkeleton = NULL); |
michael@0 | 834 | |
michael@0 | 835 | /** |
michael@0 | 836 | * Adjust field width in best match interval pattern to match |
michael@0 | 837 | * the field width in input skeleton. |
michael@0 | 838 | * |
michael@0 | 839 | * TODO (xji) make a general solution |
michael@0 | 840 | * The adjusting rule can be: |
michael@0 | 841 | * 1. always adjust |
michael@0 | 842 | * 2. never adjust |
michael@0 | 843 | * 3. default adjust, which means adjust according to the following rules |
michael@0 | 844 | * 3.1 always adjust string, such as MMM and MMMM |
michael@0 | 845 | * 3.2 never adjust between string and numeric, such as MM and MMM |
michael@0 | 846 | * 3.3 always adjust year |
michael@0 | 847 | * 3.4 do not adjust 'd', 'h', or 'm' if h presents |
michael@0 | 848 | * 3.5 do not adjust 'M' if it is numeric(?) |
michael@0 | 849 | * |
michael@0 | 850 | * Since date interval format is well-formed format, |
michael@0 | 851 | * date and time skeletons are normalized previously, |
michael@0 | 852 | * till this stage, the adjust here is only "adjust strings, such as MMM |
michael@0 | 853 | * and MMMM, EEE and EEEE. |
michael@0 | 854 | * |
michael@0 | 855 | * @param inputSkeleton the input skeleton |
michael@0 | 856 | * @param bestMatchSkeleton the best match skeleton |
michael@0 | 857 | * @param bestMatchIntervalPattern the best match interval pattern |
michael@0 | 858 | * @param differenceInfo the difference between 2 skeletons |
michael@0 | 859 | * 1 means only field width differs |
michael@0 | 860 | * 2 means v/z exchange |
michael@0 | 861 | * @param adjustedIntervalPattern adjusted interval pattern |
michael@0 | 862 | */ |
michael@0 | 863 | static void U_EXPORT2 adjustFieldWidth( |
michael@0 | 864 | const UnicodeString& inputSkeleton, |
michael@0 | 865 | const UnicodeString& bestMatchSkeleton, |
michael@0 | 866 | const UnicodeString& bestMatchIntervalPattern, |
michael@0 | 867 | int8_t differenceInfo, |
michael@0 | 868 | UnicodeString& adjustedIntervalPattern); |
michael@0 | 869 | |
michael@0 | 870 | /** |
michael@0 | 871 | * Concat a single date pattern with a time interval pattern, |
michael@0 | 872 | * set it into the intervalPatterns, while field is time field. |
michael@0 | 873 | * This is used to handle time interval patterns on skeleton with |
michael@0 | 874 | * both time and date. Present the date followed by |
michael@0 | 875 | * the range expression for the time. |
michael@0 | 876 | * @param format date and time format |
michael@0 | 877 | * @param formatLen format string length |
michael@0 | 878 | * @param datePattern date pattern |
michael@0 | 879 | * @param field time calendar field: AM_PM, HOUR, MINUTE |
michael@0 | 880 | * @param status output param set to success/failure code on exit |
michael@0 | 881 | */ |
michael@0 | 882 | void concatSingleDate2TimeInterval(const UChar* format, |
michael@0 | 883 | int32_t formatLen, |
michael@0 | 884 | const UnicodeString& datePattern, |
michael@0 | 885 | UCalendarDateFields field, |
michael@0 | 886 | UErrorCode& status); |
michael@0 | 887 | |
michael@0 | 888 | /** |
michael@0 | 889 | * check whether a calendar field present in a skeleton. |
michael@0 | 890 | * @param field calendar field need to check |
michael@0 | 891 | * @param skeleton given skeleton on which to check the calendar field |
michael@0 | 892 | * @return true if field present in a skeleton. |
michael@0 | 893 | */ |
michael@0 | 894 | static UBool U_EXPORT2 fieldExistsInSkeleton(UCalendarDateFields field, |
michael@0 | 895 | const UnicodeString& skeleton); |
michael@0 | 896 | |
michael@0 | 897 | |
michael@0 | 898 | /** |
michael@0 | 899 | * Split interval patterns into 2 part. |
michael@0 | 900 | * @param intervalPattern interval pattern |
michael@0 | 901 | * @return the index in interval pattern which split the pattern into 2 part |
michael@0 | 902 | */ |
michael@0 | 903 | static int32_t U_EXPORT2 splitPatternInto2Part(const UnicodeString& intervalPattern); |
michael@0 | 904 | |
michael@0 | 905 | |
michael@0 | 906 | /** |
michael@0 | 907 | * Break interval patterns as 2 part and save them into pattern info. |
michael@0 | 908 | * @param field calendar field |
michael@0 | 909 | * @param intervalPattern interval pattern |
michael@0 | 910 | */ |
michael@0 | 911 | void setIntervalPattern(UCalendarDateFields field, |
michael@0 | 912 | const UnicodeString& intervalPattern); |
michael@0 | 913 | |
michael@0 | 914 | |
michael@0 | 915 | /** |
michael@0 | 916 | * Break interval patterns as 2 part and save them into pattern info. |
michael@0 | 917 | * @param field calendar field |
michael@0 | 918 | * @param intervalPattern interval pattern |
michael@0 | 919 | * @param laterDateFirst whether later date appear first in interval pattern |
michael@0 | 920 | */ |
michael@0 | 921 | void setIntervalPattern(UCalendarDateFields field, |
michael@0 | 922 | const UnicodeString& intervalPattern, |
michael@0 | 923 | UBool laterDateFirst); |
michael@0 | 924 | |
michael@0 | 925 | |
michael@0 | 926 | /** |
michael@0 | 927 | * Set pattern information. |
michael@0 | 928 | * |
michael@0 | 929 | * @param field calendar field |
michael@0 | 930 | * @param firstPart the first part in interval pattern |
michael@0 | 931 | * @param secondPart the second part in interval pattern |
michael@0 | 932 | * @param laterDateFirst whether the first date in intervalPattern |
michael@0 | 933 | * is earlier date or later date |
michael@0 | 934 | */ |
michael@0 | 935 | void setPatternInfo(UCalendarDateFields field, |
michael@0 | 936 | const UnicodeString* firstPart, |
michael@0 | 937 | const UnicodeString* secondPart, |
michael@0 | 938 | UBool laterDateFirst); |
michael@0 | 939 | |
michael@0 | 940 | |
michael@0 | 941 | // from calendar field to pattern letter |
michael@0 | 942 | static const UChar fgCalendarFieldToPatternLetter[]; |
michael@0 | 943 | |
michael@0 | 944 | |
michael@0 | 945 | /** |
michael@0 | 946 | * The interval patterns for this locale. |
michael@0 | 947 | */ |
michael@0 | 948 | DateIntervalInfo* fInfo; |
michael@0 | 949 | |
michael@0 | 950 | /** |
michael@0 | 951 | * The DateFormat object used to format single pattern |
michael@0 | 952 | */ |
michael@0 | 953 | SimpleDateFormat* fDateFormat; |
michael@0 | 954 | |
michael@0 | 955 | /** |
michael@0 | 956 | * The 2 calendars with the from and to date. |
michael@0 | 957 | * could re-use the calendar in fDateFormat, |
michael@0 | 958 | * but keeping 2 calendars make it clear and clean. |
michael@0 | 959 | */ |
michael@0 | 960 | Calendar* fFromCalendar; |
michael@0 | 961 | Calendar* fToCalendar; |
michael@0 | 962 | |
michael@0 | 963 | /** |
michael@0 | 964 | * Date time pattern generator |
michael@0 | 965 | */ |
michael@0 | 966 | DateTimePatternGenerator* fDtpng; |
michael@0 | 967 | |
michael@0 | 968 | /** |
michael@0 | 969 | * Following are interval information relavent (locale) to this formatter. |
michael@0 | 970 | */ |
michael@0 | 971 | UnicodeString fSkeleton; |
michael@0 | 972 | PatternInfo fIntervalPatterns[DateIntervalInfo::kIPI_MAX_INDEX]; |
michael@0 | 973 | }; |
michael@0 | 974 | |
michael@0 | 975 | inline UBool |
michael@0 | 976 | DateIntervalFormat::operator!=(const Format& other) const { |
michael@0 | 977 | return !operator==(other); |
michael@0 | 978 | } |
michael@0 | 979 | |
michael@0 | 980 | U_NAMESPACE_END |
michael@0 | 981 | |
michael@0 | 982 | #endif /* #if !UCONFIG_NO_FORMATTING */ |
michael@0 | 983 | |
michael@0 | 984 | #endif // _DTITVFMT_H__ |
michael@0 | 985 | //eof |