| OLD | NEW |
| 1 /*******************************************************************************
* | 1 /*******************************************************************************
* |
| 2 * Copyright (C) 2008-2013, International Business Machines Corporation and | 2 * Copyright (C) 2008-2013,2015, International Business Machines Corporation and |
| 3 * others. All Rights Reserved. | 3 * others. All Rights Reserved. |
| 4 ******************************************************************************* | 4 ******************************************************************************* |
| 5 * | 5 * |
| 6 * File DTITVFMT.H | 6 * File DTITVFMT.H |
| 7 * | 7 * |
| 8 ******************************************************************************* | 8 ******************************************************************************* |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef __DTITVFMT_H__ | 11 #ifndef __DTITVFMT_H__ |
| 12 #define __DTITVFMT_H__ | 12 #define __DTITVFMT_H__ |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 * important, such as MMM, MMMM, and MMMMM; EEE and EEEE, | 86 * important, such as MMM, MMMM, and MMMMM; EEE and EEEE, |
| 87 * and the field's pattern letter length is honored. | 87 * and the field's pattern letter length is honored. |
| 88 * | 88 * |
| 89 * For the digit calendar fields, such as M or MM, d or dd, yy or yyyy, | 89 * For the digit calendar fields, such as M or MM, d or dd, yy or yyyy, |
| 90 * the field pattern length is ignored and the best match, which is defined | 90 * the field pattern length is ignored and the best match, which is defined |
| 91 * in date time patterns, will be returned without honor the field pattern | 91 * in date time patterns, will be returned without honor the field pattern |
| 92 * letter length in skeleton. | 92 * letter length in skeleton. |
| 93 * | 93 * |
| 94 * <P> | 94 * <P> |
| 95 * The calendar fields we support for interval formatting are: | 95 * The calendar fields we support for interval formatting are: |
| 96 * year, month, date, day-of-week, am-pm, hour, hour-of-day, and minute. | 96 * year, month, date, day-of-week, am-pm, hour, hour-of-day, minute, and second |
| 97 * (though we do not currently have specific intervalFormat date for skeletons |
| 98 * with seconds). |
| 97 * Those calendar fields can be defined in the following order: | 99 * Those calendar fields can be defined in the following order: |
| 98 * year > month > date > hour (in day) > minute | 100 * year > month > date > hour (in day) > minute > second |
| 99 * | 101 * |
| 100 * The largest different calendar fields between 2 calendars is the | 102 * The largest different calendar fields between 2 calendars is the |
| 101 * first different calendar field in above order. | 103 * first different calendar field in above order. |
| 102 * | 104 * |
| 103 * For example: the largest different calendar fields between "Jan 10, 2007" | 105 * For example: the largest different calendar fields between "Jan 10, 2007" |
| 104 * and "Feb 20, 2008" is year. | 106 * and "Feb 20, 2008" is year. |
| 105 * | 107 * |
| 106 * <P> | 108 * <P> |
| 107 * For other calendar fields, the compact interval formatting is not | 109 * For other calendar fields, the compact interval formatting is not |
| 108 * supported. And the interval format will be fall back to fall-back | 110 * supported. And the interval format will be fall back to fall-back |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 * objects with a DateInterval type. | 382 * objects with a DateInterval type. |
| 381 * If a the Formattable object type is not a DateInterval, | 383 * If a the Formattable object type is not a DateInterval, |
| 382 * then it returns a failing UErrorCode. | 384 * then it returns a failing UErrorCode. |
| 383 * | 385 * |
| 384 * @param obj The object to format. | 386 * @param obj The object to format. |
| 385 * Must be a DateInterval. | 387 * Must be a DateInterval. |
| 386 * @param appendTo Output parameter to receive result. | 388 * @param appendTo Output parameter to receive result. |
| 387 * Result is appended to existing contents. | 389 * Result is appended to existing contents. |
| 388 * @param fieldPosition On input: an alignment field, if desired. | 390 * @param fieldPosition On input: an alignment field, if desired. |
| 389 * On output: the offsets of the alignment field. | 391 * On output: the offsets of the alignment field. |
| 392 * There may be multiple instances of a given field
type |
| 393 * in an interval format; in this case the fieldPos
ition |
| 394 * offsets refer to the first instance. |
| 390 * @param status Output param filled with success/failure status. | 395 * @param status Output param filled with success/failure status. |
| 391 * @return Reference to 'appendTo' parameter. | 396 * @return Reference to 'appendTo' parameter. |
| 392 * @stable ICU 4.0 | 397 * @stable ICU 4.0 |
| 393 */ | 398 */ |
| 394 virtual UnicodeString& format(const Formattable& obj, | 399 virtual UnicodeString& format(const Formattable& obj, |
| 395 UnicodeString& appendTo, | 400 UnicodeString& appendTo, |
| 396 FieldPosition& fieldPosition, | 401 FieldPosition& fieldPosition, |
| 397 UErrorCode& status) const ; | 402 UErrorCode& status) const ; |
| 398 | 403 |
| 399 | 404 |
| 400 | 405 |
| 401 /** | 406 /** |
| 402 * Format a DateInterval to produce a string. | 407 * Format a DateInterval to produce a string. |
| 403 * | 408 * |
| 404 * @param dtInterval DateInterval to be formatted. | 409 * @param dtInterval DateInterval to be formatted. |
| 405 * @param appendTo Output parameter to receive result. | 410 * @param appendTo Output parameter to receive result. |
| 406 * Result is appended to existing contents. | 411 * Result is appended to existing contents. |
| 407 * @param fieldPosition On input: an alignment field, if desired. | 412 * @param fieldPosition On input: an alignment field, if desired. |
| 408 * On output: the offsets of the alignment field. | 413 * On output: the offsets of the alignment field. |
| 414 * There may be multiple instances of a given field
type |
| 415 * in an interval format; in this case the fieldPos
ition |
| 416 * offsets refer to the first instance. |
| 409 * @param status Output param filled with success/failure status. | 417 * @param status Output param filled with success/failure status. |
| 410 * @return Reference to 'appendTo' parameter. | 418 * @return Reference to 'appendTo' parameter. |
| 411 * @stable ICU 4.0 | 419 * @stable ICU 4.0 |
| 412 */ | 420 */ |
| 413 UnicodeString& format(const DateInterval* dtInterval, | 421 UnicodeString& format(const DateInterval* dtInterval, |
| 414 UnicodeString& appendTo, | 422 UnicodeString& appendTo, |
| 415 FieldPosition& fieldPosition, | 423 FieldPosition& fieldPosition, |
| 416 UErrorCode& status) const ; | 424 UErrorCode& status) const ; |
| 417 | 425 |
| 418 | 426 |
| 419 /** | 427 /** |
| 420 * Format 2 Calendars to produce a string. | 428 * Format 2 Calendars to produce a string. |
| 421 * | 429 * |
| 422 * Note: "fromCalendar" and "toCalendar" are not const, | 430 * Note: "fromCalendar" and "toCalendar" are not const, |
| 423 * since calendar is not const in SimpleDateFormat::format(Calendar&), | 431 * since calendar is not const in SimpleDateFormat::format(Calendar&), |
| 424 * | 432 * |
| 425 * @param fromCalendar calendar set to the from date in date interval | 433 * @param fromCalendar calendar set to the from date in date interval |
| 426 * to be formatted into date interval string | 434 * to be formatted into date interval string |
| 427 * @param toCalendar calendar set to the to date in date interval | 435 * @param toCalendar calendar set to the to date in date interval |
| 428 * to be formatted into date interval string | 436 * to be formatted into date interval string |
| 429 * @param appendTo Output parameter to receive result. | 437 * @param appendTo Output parameter to receive result. |
| 430 * Result is appended to existing contents. | 438 * Result is appended to existing contents. |
| 431 * @param fieldPosition On input: an alignment field, if desired. | 439 * @param fieldPosition On input: an alignment field, if desired. |
| 432 * On output: the offsets of the alignment field. | 440 * On output: the offsets of the alignment field. |
| 441 * There may be multiple instances of a given field
type |
| 442 * in an interval format; in this case the fieldPos
ition |
| 443 * offsets refer to the first instance. |
| 433 * @param status Output param filled with success/failure status. | 444 * @param status Output param filled with success/failure status. |
| 434 * Caller needs to make sure it is SUCCESS | 445 * Caller needs to make sure it is SUCCESS |
| 435 * at the function entrance | 446 * at the function entrance |
| 436 * @return Reference to 'appendTo' parameter. | 447 * @return Reference to 'appendTo' parameter. |
| 437 * @stable ICU 4.0 | 448 * @stable ICU 4.0 |
| 438 */ | 449 */ |
| 439 UnicodeString& format(Calendar& fromCalendar, | 450 UnicodeString& format(Calendar& fromCalendar, |
| 440 Calendar& toCalendar, | 451 Calendar& toCalendar, |
| 441 UnicodeString& appendTo, | 452 UnicodeString& appendTo, |
| 442 FieldPosition& fieldPosition, | 453 FieldPosition& fieldPosition, |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 * @param skeleton the skeleton of this formatter. | 646 * @param skeleton the skeleton of this formatter. |
| 636 * @param status Output param set to success/failure code. | 647 * @param status Output param set to success/failure code. |
| 637 * @return a date time interval formatter which the caller owns. | 648 * @return a date time interval formatter which the caller owns. |
| 638 */ | 649 */ |
| 639 static DateIntervalFormat* U_EXPORT2 create(const Locale& locale, | 650 static DateIntervalFormat* U_EXPORT2 create(const Locale& locale, |
| 640 DateIntervalInfo* dtitvinf, | 651 DateIntervalInfo* dtitvinf, |
| 641 const UnicodeString* skeleton, | 652 const UnicodeString* skeleton, |
| 642 UErrorCode& status); | 653 UErrorCode& status); |
| 643 | 654 |
| 644 /** | 655 /** |
| 645 * Create a simple date/time formatter from skeleton, given locale, | |
| 646 * and date time pattern generator. | |
| 647 * | |
| 648 * @param skeleton the skeleton on which date format based. | |
| 649 * @param locale the given locale. | |
| 650 * @param dtpng the date time pattern generator. | |
| 651 * @param status Output param to be set to success/failure code. | |
| 652 * If it is failure, the returned date formatter will | |
| 653 * be NULL. | |
| 654 * @return a simple date formatter which the caller owns. | |
| 655 */ | |
| 656 static SimpleDateFormat* U_EXPORT2 createSDFPatternInstance( | |
| 657 const UnicodeString& skeleton, | |
| 658 const Locale& locale, | |
| 659 DateTimePatternGenerator* dtpng, | |
| 660 UErrorCode& status); | |
| 661 | |
| 662 | |
| 663 /** | |
| 664 * Below are for generating interval patterns local to the formatter | 656 * Below are for generating interval patterns local to the formatter |
| 665 */ | 657 */ |
| 666 | 658 |
| 659 /** |
| 660 * Provide an updated FieldPosition posResult based on two formats, |
| 661 * the FieldPosition values for each of them, and the pattern used |
| 662 * to combine them. The idea is for posResult to indicate the first |
| 663 * instance (if any) of the specified field in the combined result, |
| 664 * with correct offsets. |
| 665 * |
| 666 * @param combiningPattern Pattern used to combine pat0 and pat1 |
| 667 * @param pat0 Formatted date/time value to replace {0} |
| 668 * @param pos0 FieldPosition within pat0 |
| 669 * @param pat1 Formatted date/time value to replace {1} |
| 670 * @param pos1 FieldPosition within pat1 |
| 671 * @param posResult FieldPosition to be set to the correct |
| 672 * position of the first field instance when |
| 673 * pat0 and pat1 are combined using combiningPatter
n |
| 674 */ |
| 675 static void |
| 676 adjustPosition(UnicodeString& combiningPattern, // has {0} and {1} in it |
| 677 UnicodeString& pat0, FieldPosition& pos0, // pattern and pos
corresponding to {0} |
| 678 UnicodeString& pat1, FieldPosition& pos1, // pattern and pos
corresponding to {1} |
| 679 FieldPosition& posResult); |
| 680 |
| 667 | 681 |
| 668 /** | 682 /** |
| 669 * Format 2 Calendars using fall-back interval pattern | 683 * Format 2 Calendars using fall-back interval pattern |
| 670 * | 684 * |
| 671 * The full pattern used in this fall-back format is the | 685 * The full pattern used in this fall-back format is the |
| 672 * full pattern of the date formatter. | 686 * full pattern of the date formatter. |
| 673 * | 687 * |
| 674 * @param fromCalendar calendar set to the from date in date interval | 688 * @param fromCalendar calendar set to the from date in date interval |
| 675 * to be formatted into date interval string | 689 * to be formatted into date interval string |
| 676 * @param toCalendar calendar set to the to date in date interval | 690 * @param toCalendar calendar set to the to date in date interval |
| 677 * to be formatted into date interval string | 691 * to be formatted into date interval string |
| 692 * @param fromToOnSameDay TRUE iff from and to dates are on the same day |
| 693 * (any difference is in ampm/hours or below) |
| 678 * @param appendTo Output parameter to receive result. | 694 * @param appendTo Output parameter to receive result. |
| 679 * Result is appended to existing contents. | 695 * Result is appended to existing contents. |
| 680 * @param pos On input: an alignment field, if desired. | 696 * @param pos On input: an alignment field, if desired. |
| 681 * On output: the offsets of the alignment field. | 697 * On output: the offsets of the alignment field. |
| 682 * @param status output param set to success/failure code on exit | 698 * @param status output param set to success/failure code on exit |
| 683 * @return Reference to 'appendTo' parameter. | 699 * @return Reference to 'appendTo' parameter. |
| 684 */ | 700 */ |
| 685 UnicodeString& fallbackFormat(Calendar& fromCalendar, | 701 UnicodeString& fallbackFormat(Calendar& fromCalendar, |
| 686 Calendar& toCalendar, | 702 Calendar& toCalendar, |
| 703 UBool fromToOnSameDay, |
| 687 UnicodeString& appendTo, | 704 UnicodeString& appendTo, |
| 688 FieldPosition& pos, | 705 FieldPosition& pos, |
| 689 UErrorCode& status) const; | 706 UErrorCode& status) const; |
| 690 | 707 |
| 691 | 708 |
| 692 | 709 |
| 693 /** | 710 /** |
| 694 * Initialize interval patterns locale to this formatter | 711 * Initialize interval patterns locale to this formatter |
| 695 * | 712 * |
| 696 * This code is a bit complicated since | 713 * This code is a bit complicated since |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 int8_t differenceInfo, | 884 int8_t differenceInfo, |
| 868 UnicodeString& adjustedIntervalPattern); | 885 UnicodeString& adjustedIntervalPattern); |
| 869 | 886 |
| 870 /** | 887 /** |
| 871 * Concat a single date pattern with a time interval pattern, | 888 * Concat a single date pattern with a time interval pattern, |
| 872 * set it into the intervalPatterns, while field is time field. | 889 * set it into the intervalPatterns, while field is time field. |
| 873 * This is used to handle time interval patterns on skeleton with | 890 * This is used to handle time interval patterns on skeleton with |
| 874 * both time and date. Present the date followed by | 891 * both time and date. Present the date followed by |
| 875 * the range expression for the time. | 892 * the range expression for the time. |
| 876 * @param format date and time format | 893 * @param format date and time format |
| 877 * @param formatLen format string length | |
| 878 * @param datePattern date pattern | 894 * @param datePattern date pattern |
| 879 * @param field time calendar field: AM_PM, HOUR, MINUTE | 895 * @param field time calendar field: AM_PM, HOUR, MINUTE |
| 880 * @param status output param set to success/failure code on exit | 896 * @param status output param set to success/failure code on exit |
| 881 */ | 897 */ |
| 882 void concatSingleDate2TimeInterval(const UChar* format, | 898 void concatSingleDate2TimeInterval(UnicodeString& format, |
| 883 int32_t formatLen, | |
| 884 const UnicodeString& datePattern, | 899 const UnicodeString& datePattern, |
| 885 UCalendarDateFields field, | 900 UCalendarDateFields field, |
| 886 UErrorCode& status); | 901 UErrorCode& status); |
| 887 | 902 |
| 888 /** | 903 /** |
| 889 * check whether a calendar field present in a skeleton. | 904 * check whether a calendar field present in a skeleton. |
| 890 * @param field calendar field need to check | 905 * @param field calendar field need to check |
| 891 * @param skeleton given skeleton on which to check the calendar field | 906 * @param skeleton given skeleton on which to check the calendar field |
| 892 * @return true if field present in a skeleton. | 907 * @return true if field present in a skeleton. |
| 893 */ | 908 */ |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 953 SimpleDateFormat* fDateFormat; | 968 SimpleDateFormat* fDateFormat; |
| 954 | 969 |
| 955 /** | 970 /** |
| 956 * The 2 calendars with the from and to date. | 971 * The 2 calendars with the from and to date. |
| 957 * could re-use the calendar in fDateFormat, | 972 * could re-use the calendar in fDateFormat, |
| 958 * but keeping 2 calendars make it clear and clean. | 973 * but keeping 2 calendars make it clear and clean. |
| 959 */ | 974 */ |
| 960 Calendar* fFromCalendar; | 975 Calendar* fFromCalendar; |
| 961 Calendar* fToCalendar; | 976 Calendar* fToCalendar; |
| 962 | 977 |
| 963 /** | 978 Locale fLocale; |
| 964 * Date time pattern generator | |
| 965 */ | |
| 966 DateTimePatternGenerator* fDtpng; | |
| 967 | 979 |
| 968 /** | 980 /** |
| 969 * Following are interval information relavent (locale) to this formatter. | 981 * Following are interval information relevant (locale) to this formatter. |
| 970 */ | 982 */ |
| 971 UnicodeString fSkeleton; | 983 UnicodeString fSkeleton; |
| 972 PatternInfo fIntervalPatterns[DateIntervalInfo::kIPI_MAX_INDEX]; | 984 PatternInfo fIntervalPatterns[DateIntervalInfo::kIPI_MAX_INDEX]; |
| 985 |
| 986 /** |
| 987 * Patterns for fallback formatting. |
| 988 */ |
| 989 UnicodeString* fDatePattern; |
| 990 UnicodeString* fTimePattern; |
| 991 UnicodeString* fDateTimeFormat; |
| 973 }; | 992 }; |
| 974 | 993 |
| 975 inline UBool | 994 inline UBool |
| 976 DateIntervalFormat::operator!=(const Format& other) const { | 995 DateIntervalFormat::operator!=(const Format& other) const { |
| 977 return !operator==(other); | 996 return !operator==(other); |
| 978 } | 997 } |
| 979 | 998 |
| 980 U_NAMESPACE_END | 999 U_NAMESPACE_END |
| 981 | 1000 |
| 982 #endif /* #if !UCONFIG_NO_FORMATTING */ | 1001 #endif /* #if !UCONFIG_NO_FORMATTING */ |
| 983 | 1002 |
| 984 #endif // _DTITVFMT_H__ | 1003 #endif // _DTITVFMT_H__ |
| 985 //eof | 1004 //eof |
| OLD | NEW |