Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* |
michael@0 | 2 | ***************************************************************************************** |
michael@0 | 3 | * Copyright (C) 2010-2012, International Business Machines |
michael@0 | 4 | * Corporation and others. All Rights Reserved. |
michael@0 | 5 | ***************************************************************************************** |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | #ifndef UDATEINTERVALFORMAT_H |
michael@0 | 9 | #define UDATEINTERVALFORMAT_H |
michael@0 | 10 | |
michael@0 | 11 | #include "unicode/utypes.h" |
michael@0 | 12 | |
michael@0 | 13 | #if !UCONFIG_NO_FORMATTING |
michael@0 | 14 | |
michael@0 | 15 | #include "unicode/umisc.h" |
michael@0 | 16 | #include "unicode/localpointer.h" |
michael@0 | 17 | |
michael@0 | 18 | /** |
michael@0 | 19 | * \file |
michael@0 | 20 | * \brief C API: Format a date interval. |
michael@0 | 21 | * |
michael@0 | 22 | * A UDateIntervalFormat is used to format the range between two UDate values |
michael@0 | 23 | * in a locale-sensitive way, using a skeleton that specifies the precision and |
michael@0 | 24 | * completeness of the information to show. If the range smaller than the resolution |
michael@0 | 25 | * specified by the skeleton, a single date format will be produced. If the range |
michael@0 | 26 | * is larger than the format specified by the skeleton, a locale-specific fallback |
michael@0 | 27 | * will be used to format the items missing from the skeleton. |
michael@0 | 28 | * |
michael@0 | 29 | * For example, if the range is 2010-03-04 07:56 - 2010-03-04 19:56 (12 hours) |
michael@0 | 30 | * - The skeleton jm will produce |
michael@0 | 31 | * for en_US, "7:56 AM - 7:56 PM" |
michael@0 | 32 | * for en_GB, "7:56 - 19:56" |
michael@0 | 33 | * - The skeleton MMMd will produce |
michael@0 | 34 | * for en_US, "Mar 4" |
michael@0 | 35 | * for en_GB, "4 Mar" |
michael@0 | 36 | * If the range is 2010-03-04 07:56 - 2010-03-08 16:11 (4 days, 8 hours, 15 minutes) |
michael@0 | 37 | * - The skeleton jm will produce |
michael@0 | 38 | * for en_US, "3/4/2010 7:56 AM - 3/8/2010 4:11 PM" |
michael@0 | 39 | * for en_GB, "4/3/2010 7:56 - 8/3/2010 16:11" |
michael@0 | 40 | * - The skeleton MMMd will produce |
michael@0 | 41 | * for en_US, "Mar 4-8" |
michael@0 | 42 | * for en_GB, "4-8 Mar" |
michael@0 | 43 | * |
michael@0 | 44 | * Note: the "-" characters in the above sample output will actually be |
michael@0 | 45 | * Unicode 2013, EN_DASH, in all but the last example. |
michael@0 | 46 | * |
michael@0 | 47 | * Note, in ICU 4.4 the standard skeletons for which date interval format data |
michael@0 | 48 | * is usually available are as follows; best results will be obtained by using |
michael@0 | 49 | * skeletons from this set, or those formed by combining these standard skeletons |
michael@0 | 50 | * (note that for these skeletons, the length of digit field such as d, y, or |
michael@0 | 51 | * M vs MM is irrelevant (but for non-digit fields such as MMM vs MMMM it is |
michael@0 | 52 | * relevant). Note that a skeleton involving h or H generally explicitly requests |
michael@0 | 53 | * that time style (12- or 24-hour time respectively). For a skeleton that |
michael@0 | 54 | * requests the locale's default time style (h or H), use 'j' instead of h or H. |
michael@0 | 55 | * h, H, hm, Hm, |
michael@0 | 56 | * hv, Hv, hmv, Hmv, |
michael@0 | 57 | * d, |
michael@0 | 58 | * M, MMM, MMMM, |
michael@0 | 59 | * Md, MMMd, |
michael@0 | 60 | * MEd, MMMEd, |
michael@0 | 61 | * y, |
michael@0 | 62 | * yM, yMMM, yMMMM, |
michael@0 | 63 | * yMd, yMMMd, |
michael@0 | 64 | * yMEd, yMMMEd |
michael@0 | 65 | * |
michael@0 | 66 | * Locales for which ICU 4.4 seems to have a reasonable amount of this data |
michael@0 | 67 | * include: |
michael@0 | 68 | * af, am, ar, be, bg, bn, ca, cs, da, de (_AT), el, en (_AU,_CA,_GB,_IE,_IN...), |
michael@0 | 69 | * eo, es (_AR,_CL,_CO,...,_US) et, fa, fi, fo, fr (_BE,_CH,_CA), fur, gsw, he, |
michael@0 | 70 | * hr, hu, hy, is, it (_CH), ja, kk, km, ko, lt, lv, mk, ml, mt, nb, nl )_BE), |
michael@0 | 71 | * nn, pl, pt (_PT), rm, ro, ru (_UA), sk, sl, so, sq, sr, sr_Latn, sv, th, to, |
michael@0 | 72 | * tr, uk, ur, vi, zh (_SG), zh_Hant (_HK,_MO) |
michael@0 | 73 | */ |
michael@0 | 74 | |
michael@0 | 75 | /** |
michael@0 | 76 | * Opaque UDateIntervalFormat object for use in C programs. |
michael@0 | 77 | * @stable ICU 4.8 |
michael@0 | 78 | */ |
michael@0 | 79 | struct UDateIntervalFormat; |
michael@0 | 80 | typedef struct UDateIntervalFormat UDateIntervalFormat; /**< C typedef for struct UDateIntervalFormat. @stable ICU 4.8 */ |
michael@0 | 81 | |
michael@0 | 82 | /** |
michael@0 | 83 | * Open a new UDateIntervalFormat object using the predefined rules for a |
michael@0 | 84 | * given locale plus a specified skeleton. |
michael@0 | 85 | * @param locale |
michael@0 | 86 | * The locale for whose rules should be used; may be NULL for |
michael@0 | 87 | * default locale. |
michael@0 | 88 | * @param skeleton |
michael@0 | 89 | * A pattern containing only the fields desired for the interval |
michael@0 | 90 | * format, for example "Hm", "yMMMd", or "yMMMEdHm". |
michael@0 | 91 | * @param skeletonLength |
michael@0 | 92 | * The length of skeleton; may be -1 if the skeleton is zero-terminated. |
michael@0 | 93 | * @param tzID |
michael@0 | 94 | * A timezone ID specifying the timezone to use. If 0, use the default |
michael@0 | 95 | * timezone. |
michael@0 | 96 | * @param tzIDLength |
michael@0 | 97 | * The length of tzID, or -1 if null-terminated. If 0, use the default |
michael@0 | 98 | * timezone. |
michael@0 | 99 | * @param status |
michael@0 | 100 | * A pointer to a UErrorCode to receive any errors. |
michael@0 | 101 | * @return |
michael@0 | 102 | * A pointer to a UDateIntervalFormat object for the specified locale, |
michael@0 | 103 | * or NULL if an error occurred. |
michael@0 | 104 | * @stable ICU 4.8 |
michael@0 | 105 | */ |
michael@0 | 106 | U_STABLE UDateIntervalFormat* U_EXPORT2 |
michael@0 | 107 | udtitvfmt_open(const char* locale, |
michael@0 | 108 | const UChar* skeleton, |
michael@0 | 109 | int32_t skeletonLength, |
michael@0 | 110 | const UChar* tzID, |
michael@0 | 111 | int32_t tzIDLength, |
michael@0 | 112 | UErrorCode* status); |
michael@0 | 113 | |
michael@0 | 114 | /** |
michael@0 | 115 | * Close a UDateIntervalFormat object. Once closed it may no longer be used. |
michael@0 | 116 | * @param formatter |
michael@0 | 117 | * The UDateIntervalFormat object to close. |
michael@0 | 118 | * @stable ICU 4.8 |
michael@0 | 119 | */ |
michael@0 | 120 | U_STABLE void U_EXPORT2 |
michael@0 | 121 | udtitvfmt_close(UDateIntervalFormat *formatter); |
michael@0 | 122 | |
michael@0 | 123 | |
michael@0 | 124 | #if U_SHOW_CPLUSPLUS_API |
michael@0 | 125 | |
michael@0 | 126 | U_NAMESPACE_BEGIN |
michael@0 | 127 | |
michael@0 | 128 | /** |
michael@0 | 129 | * \class LocalUDateIntervalFormatPointer |
michael@0 | 130 | * "Smart pointer" class, closes a UDateIntervalFormat via udtitvfmt_close(). |
michael@0 | 131 | * For most methods see the LocalPointerBase base class. |
michael@0 | 132 | * |
michael@0 | 133 | * @see LocalPointerBase |
michael@0 | 134 | * @see LocalPointer |
michael@0 | 135 | * @stable ICU 4.8 |
michael@0 | 136 | */ |
michael@0 | 137 | U_DEFINE_LOCAL_OPEN_POINTER(LocalUDateIntervalFormatPointer, UDateIntervalFormat, udtitvfmt_close); |
michael@0 | 138 | |
michael@0 | 139 | U_NAMESPACE_END |
michael@0 | 140 | |
michael@0 | 141 | #endif |
michael@0 | 142 | |
michael@0 | 143 | |
michael@0 | 144 | /** |
michael@0 | 145 | * Formats a date/time range using the conventions established for the |
michael@0 | 146 | * UDateIntervalFormat object. |
michael@0 | 147 | * @param formatter |
michael@0 | 148 | * The UDateIntervalFormat object specifying the format conventions. |
michael@0 | 149 | * @param fromDate |
michael@0 | 150 | * The starting point of the range. |
michael@0 | 151 | * @param toDate |
michael@0 | 152 | * The ending point of the range. |
michael@0 | 153 | * @param result |
michael@0 | 154 | * A pointer to a buffer to receive the formatted range. |
michael@0 | 155 | * @param resultCapacity |
michael@0 | 156 | * The maximum size of result. |
michael@0 | 157 | * @param position |
michael@0 | 158 | * A pointer to a UFieldPosition. On input, position->field is read. |
michael@0 | 159 | * On output, position->beginIndex and position->endIndex indicate |
michael@0 | 160 | * the beginning and ending indices of field number position->field, |
michael@0 | 161 | * if such a field exists. This parameter may be NULL, in which case |
michael@0 | 162 | * no field position data is returned. |
michael@0 | 163 | * @param status |
michael@0 | 164 | * A pointer to a UErrorCode to receive any errors. |
michael@0 | 165 | * @return |
michael@0 | 166 | * The total buffer size needed; if greater than resultLength, the |
michael@0 | 167 | * output was truncated. |
michael@0 | 168 | * @stable ICU 4.8 |
michael@0 | 169 | */ |
michael@0 | 170 | U_STABLE int32_t U_EXPORT2 |
michael@0 | 171 | udtitvfmt_format(const UDateIntervalFormat* formatter, |
michael@0 | 172 | UDate fromDate, |
michael@0 | 173 | UDate toDate, |
michael@0 | 174 | UChar* result, |
michael@0 | 175 | int32_t resultCapacity, |
michael@0 | 176 | UFieldPosition* position, |
michael@0 | 177 | UErrorCode* status); |
michael@0 | 178 | |
michael@0 | 179 | #endif /* #if !UCONFIG_NO_FORMATTING */ |
michael@0 | 180 | |
michael@0 | 181 | #endif |