michael@0: /* michael@0: ***************************************************************************************** michael@0: * Copyright (C) 2010-2012, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ***************************************************************************************** michael@0: */ michael@0: michael@0: #ifndef UDATEINTERVALFORMAT_H michael@0: #define UDATEINTERVALFORMAT_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: #include "unicode/umisc.h" michael@0: #include "unicode/localpointer.h" michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C API: Format a date interval. michael@0: * michael@0: * A UDateIntervalFormat is used to format the range between two UDate values michael@0: * in a locale-sensitive way, using a skeleton that specifies the precision and michael@0: * completeness of the information to show. If the range smaller than the resolution michael@0: * specified by the skeleton, a single date format will be produced. If the range michael@0: * is larger than the format specified by the skeleton, a locale-specific fallback michael@0: * will be used to format the items missing from the skeleton. michael@0: * michael@0: * For example, if the range is 2010-03-04 07:56 - 2010-03-04 19:56 (12 hours) michael@0: * - The skeleton jm will produce michael@0: * for en_US, "7:56 AM - 7:56 PM" michael@0: * for en_GB, "7:56 - 19:56" michael@0: * - The skeleton MMMd will produce michael@0: * for en_US, "Mar 4" michael@0: * for en_GB, "4 Mar" michael@0: * If the range is 2010-03-04 07:56 - 2010-03-08 16:11 (4 days, 8 hours, 15 minutes) michael@0: * - The skeleton jm will produce michael@0: * for en_US, "3/4/2010 7:56 AM - 3/8/2010 4:11 PM" michael@0: * for en_GB, "4/3/2010 7:56 - 8/3/2010 16:11" michael@0: * - The skeleton MMMd will produce michael@0: * for en_US, "Mar 4-8" michael@0: * for en_GB, "4-8 Mar" michael@0: * michael@0: * Note: the "-" characters in the above sample output will actually be michael@0: * Unicode 2013, EN_DASH, in all but the last example. michael@0: * michael@0: * Note, in ICU 4.4 the standard skeletons for which date interval format data michael@0: * is usually available are as follows; best results will be obtained by using michael@0: * skeletons from this set, or those formed by combining these standard skeletons michael@0: * (note that for these skeletons, the length of digit field such as d, y, or michael@0: * M vs MM is irrelevant (but for non-digit fields such as MMM vs MMMM it is michael@0: * relevant). Note that a skeleton involving h or H generally explicitly requests michael@0: * that time style (12- or 24-hour time respectively). For a skeleton that michael@0: * requests the locale's default time style (h or H), use 'j' instead of h or H. michael@0: * h, H, hm, Hm, michael@0: * hv, Hv, hmv, Hmv, michael@0: * d, michael@0: * M, MMM, MMMM, michael@0: * Md, MMMd, michael@0: * MEd, MMMEd, michael@0: * y, michael@0: * yM, yMMM, yMMMM, michael@0: * yMd, yMMMd, michael@0: * yMEd, yMMMEd michael@0: * michael@0: * Locales for which ICU 4.4 seems to have a reasonable amount of this data michael@0: * include: michael@0: * af, am, ar, be, bg, bn, ca, cs, da, de (_AT), el, en (_AU,_CA,_GB,_IE,_IN...), michael@0: * eo, es (_AR,_CL,_CO,...,_US) et, fa, fi, fo, fr (_BE,_CH,_CA), fur, gsw, he, michael@0: * hr, hu, hy, is, it (_CH), ja, kk, km, ko, lt, lv, mk, ml, mt, nb, nl )_BE), michael@0: * nn, pl, pt (_PT), rm, ro, ru (_UA), sk, sl, so, sq, sr, sr_Latn, sv, th, to, michael@0: * tr, uk, ur, vi, zh (_SG), zh_Hant (_HK,_MO) michael@0: */ michael@0: michael@0: /** michael@0: * Opaque UDateIntervalFormat object for use in C programs. michael@0: * @stable ICU 4.8 michael@0: */ michael@0: struct UDateIntervalFormat; michael@0: typedef struct UDateIntervalFormat UDateIntervalFormat; /**< C typedef for struct UDateIntervalFormat. @stable ICU 4.8 */ michael@0: michael@0: /** michael@0: * Open a new UDateIntervalFormat object using the predefined rules for a michael@0: * given locale plus a specified skeleton. michael@0: * @param locale michael@0: * The locale for whose rules should be used; may be NULL for michael@0: * default locale. michael@0: * @param skeleton michael@0: * A pattern containing only the fields desired for the interval michael@0: * format, for example "Hm", "yMMMd", or "yMMMEdHm". michael@0: * @param skeletonLength michael@0: * The length of skeleton; may be -1 if the skeleton is zero-terminated. michael@0: * @param tzID michael@0: * A timezone ID specifying the timezone to use. If 0, use the default michael@0: * timezone. michael@0: * @param tzIDLength michael@0: * The length of tzID, or -1 if null-terminated. If 0, use the default michael@0: * timezone. michael@0: * @param status michael@0: * A pointer to a UErrorCode to receive any errors. michael@0: * @return michael@0: * A pointer to a UDateIntervalFormat object for the specified locale, michael@0: * or NULL if an error occurred. michael@0: * @stable ICU 4.8 michael@0: */ michael@0: U_STABLE UDateIntervalFormat* U_EXPORT2 michael@0: udtitvfmt_open(const char* locale, michael@0: const UChar* skeleton, michael@0: int32_t skeletonLength, michael@0: const UChar* tzID, michael@0: int32_t tzIDLength, michael@0: UErrorCode* status); michael@0: michael@0: /** michael@0: * Close a UDateIntervalFormat object. Once closed it may no longer be used. michael@0: * @param formatter michael@0: * The UDateIntervalFormat object to close. michael@0: * @stable ICU 4.8 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: udtitvfmt_close(UDateIntervalFormat *formatter); michael@0: michael@0: michael@0: #if U_SHOW_CPLUSPLUS_API michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: /** michael@0: * \class LocalUDateIntervalFormatPointer michael@0: * "Smart pointer" class, closes a UDateIntervalFormat via udtitvfmt_close(). michael@0: * For most methods see the LocalPointerBase base class. michael@0: * michael@0: * @see LocalPointerBase michael@0: * @see LocalPointer michael@0: * @stable ICU 4.8 michael@0: */ michael@0: U_DEFINE_LOCAL_OPEN_POINTER(LocalUDateIntervalFormatPointer, UDateIntervalFormat, udtitvfmt_close); michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif michael@0: michael@0: michael@0: /** michael@0: * Formats a date/time range using the conventions established for the michael@0: * UDateIntervalFormat object. michael@0: * @param formatter michael@0: * The UDateIntervalFormat object specifying the format conventions. michael@0: * @param fromDate michael@0: * The starting point of the range. michael@0: * @param toDate michael@0: * The ending point of the range. michael@0: * @param result michael@0: * A pointer to a buffer to receive the formatted range. michael@0: * @param resultCapacity michael@0: * The maximum size of result. michael@0: * @param position michael@0: * A pointer to a UFieldPosition. On input, position->field is read. michael@0: * On output, position->beginIndex and position->endIndex indicate michael@0: * the beginning and ending indices of field number position->field, michael@0: * if such a field exists. This parameter may be NULL, in which case michael@0: * no field position data is returned. michael@0: * @param status michael@0: * A pointer to a UErrorCode to receive any errors. michael@0: * @return michael@0: * The total buffer size needed; if greater than resultLength, the michael@0: * output was truncated. michael@0: * @stable ICU 4.8 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: udtitvfmt_format(const UDateIntervalFormat* formatter, michael@0: UDate fromDate, michael@0: UDate toDate, michael@0: UChar* result, michael@0: int32_t resultCapacity, michael@0: UFieldPosition* position, michael@0: UErrorCode* status); michael@0: michael@0: #endif /* #if !UCONFIG_NO_FORMATTING */ michael@0: michael@0: #endif