40 * Date Format helps you to format and parse dates for any locale. Your code can 41 * be completely independent of the locale conventions for months, days of the 42 * week, or even the calendar format: lunar vs. solar. 43 *
44 * To format a date for the current Locale with default time and date style, 45 * use one of the static factory methods: 46 *
47 * \code 48 * UErrorCode status = U_ZERO_ERROR; 49 * UChar *myString; 50 * int32_t myStrlen = 0; 51 * UDateFormat* dfmt = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, NULL, -1, NULL, -1, &status); 52 * myStrlen = udat_format(dfmt, myDate, NULL, myStrlen, NULL, &status); 53 * if (status==U_BUFFER_OVERFLOW_ERROR){ 54 * status=U_ZERO_ERROR; 55 * myString=(UChar*)malloc(sizeof(UChar) * (myStrlen+1) ); 56 * udat_format(dfmt, myDate, myString, myStrlen+1, NULL, &status); 57 * } 58 * \endcode 59 *
64 * \code 65 * UErrorCode status = U_ZERO_ERROR; 66 * int32_t i, myStrlen = 0; 67 * UChar* myString; 68 * char buffer[1024]; 69 * UDate myDateArr[] = { 0.0, 100000000.0, 2000000000.0 }; // test values 70 * UDateFormat* df = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, NULL, -1, NULL, 0, &status); 71 * for (i = 0; i < 3; i++) { 72 * myStrlen = udat_format(df, myDateArr[i], NULL, myStrlen, NULL, &status); 73 * if(status == U_BUFFER_OVERFLOW_ERROR){ 74 * status = U_ZERO_ERROR; 75 * myString = (UChar*)malloc(sizeof(UChar) * (myStrlen+1) ); 76 * udat_format(df, myDateArr[i], myString, myStrlen+1, NULL, &status); 77 * printf("%s\n", u_austrcpy(buffer, myString) ); 78 * free(myString); 79 * } 80 * } 81 * \endcode 82 *
86 * \code 87 * UErrorCode status = U_ZERO_ERROR; 88 * UFieldPosition pos; 89 * UChar *myString; 90 * int32_t myStrlen = 0; 91 * char buffer[1024]; 92 * 93 * pos.field = 1; // Same as the DateFormat::EField enum 94 * UDateFormat* dfmt = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, -1, NULL, 0, &status); 95 * myStrlen = udat_format(dfmt, myDate, NULL, myStrlen, &pos, &status); 96 * if (status==U_BUFFER_OVERFLOW_ERROR){ 97 * status=U_ZERO_ERROR; 98 * myString=(UChar*)malloc(sizeof(UChar) * (myStrlen+1) ); 99 * udat_format(dfmt, myDate, myString, myStrlen+1, &pos, &status); 100 * } 101 * printf("date format: %s\n", u_austrcpy(buffer, myString)); 102 * buffer[pos.endIndex] = 0; // NULL terminate the string. 103 * printf("UFieldPosition position equals %s\n", &buffer[pos.beginIndex]); 104 * \endcode 105 *
109 * \code 110 * UDateFormat* df = udat_open(UDAT_SHORT, UDAT_SHORT, "fr_FR", NULL, -1, NULL, 0, &status); 111 * \endcode 112 *
115 * \code 116 * UErrorCode status = U_ZERO_ERROR; 117 * int32_t parsepos=0; 118 * UDate myDate = udat_parse(df, myString, u_strlen(myString), &parsepos, &status); 119 * \endcode 120 *
134 * You can also use forms of the parse and format methods with Parse Position and 135 * UFieldPosition to allow you to 136 *
Date and Time Patterns:
Date and time formats are specified by date and time pattern strings. 144 * Within date and time pattern strings, all unquoted ASCII letters [A-Za-z] are reserved 145 * as pattern letters representing calendar fields. UDateFormat supports 146 * the date and time formatting algorithm and pattern letters defined by 147 * UTS#35 148 * Unicode Locale Data Markup Language (LDML) and further documented for ICU in the 149 * ICU 150 * User Guide.
UDateFormat
1174 * Note that the normal date formats associated with some calendars - such 1175 * as the Chinese lunar calendar - do not specify enough fields to enable 1176 * dates to be parsed unambiguously. In the case of the Chinese lunar 1177 * calendar, while the year within the current 60-year cycle is specified, 1178 * the number of such cycles since the start date of the calendar (in the 1179 * UCAL_ERA field of the UCalendar object) is not normally part of the format, 1180 * and parsing may assume the wrong era. For cases such as this it is 1181 * recommended that clients parse using udat_parseCalendar with the UCalendar 1182 * passed in set to the current date, or to a date within the era/cycle that 1183 * should be assumed if absent in the format. 1184 * 1185 * @param format The formatter to use. 1186 * @param text The text to parse. 1187 * @param textLength The length of text, or -1 if null-terminated. 1188 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which 1189 * to begin parsing. If not 0, on output the offset at which parsing ended. 1190 * @param status A pointer to an UErrorCode to receive any errors 1191 * @return The value of the parsed date/time 1192 * @see udat_format 1193 * @stable ICU 2.0 1194 */ 1195 U_CAPI UDate U_EXPORT2 1196 udat_parse(const UDateFormat* format, 1197 const UChar* text, 1198 int32_t textLength, 1199 int32_t *parsePos, 1200 UErrorCode *status); 1201 1202 /** 1203 * Parse a string into an date/time using a UDateFormat. 1204 * The date will be parsed using the conventions specified in {@link #udat_open }. 1205 * @param format The formatter to use. 1206 * @param calendar A calendar set on input to the date and time to be used for 1207 * missing values in the date/time string being parsed, and set 1208 * on output to the parsed date/time. When the calendar type is 1209 * different from the internal calendar held by the UDateFormat 1210 * instance, the internal calendar will be cloned to a work 1211 * calendar set to the same milliseconds and time zone as this 1212 * calendar parameter, field values will be parsed based on the 1213 * work calendar, then the result (milliseconds and time zone) 1214 * will be set in this calendar. 1215 * @param text The text to parse. 1216 * @param textLength The length of text, or -1 if null-terminated. 1217 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which 1218 * to begin parsing. If not 0, on output the offset at which parsing ended. 1219 * @param status A pointer to an UErrorCode to receive any errors 1220 * @see udat_format 1221 * @stable ICU 2.0 1222 */ 1223 U_CAPI void U_EXPORT2 1224 udat_parseCalendar(const UDateFormat* format, 1225 UCalendar* calendar, 1226 const UChar* text, 1227 int32_t textLength, 1228 int32_t *parsePos, 1229 UErrorCode *status); 1230 1231 /** 1232 * Determine if an UDateFormat will perform lenient parsing. 1233 * With lenient parsing, the parser may use heuristics to interpret inputs that do not 1234 * precisely match the pattern. With strict parsing, inputs must match the pattern. 1235 * @param fmt The formatter to query 1236 * @return true if fmt is set to perform lenient parsing, false otherwise. 1237 * @see udat_setLenient 1238 * @stable ICU 2.0 1239 */ 1240 U_CAPI UBool U_EXPORT2 1241 udat_isLenient(const UDateFormat* fmt); 1242 1243 /** 1244 * Specify whether an UDateFormat will perform lenient parsing. 1245 * With lenient parsing, the parser may use heuristics to interpret inputs that do not 1246 * precisely match the pattern. With strict parsing, inputs must match the pattern. 1247 * @param fmt The formatter to set 1248 * @param isLenient true if fmt should perform lenient parsing, false otherwise. 1249 * @see dat_isLenient 1250 * @stable ICU 2.0 1251 */ 1252 U_CAPI void U_EXPORT2 1253 udat_setLenient( UDateFormat* fmt, 1254 UBool isLenient); 1255 1256 /** 1257 * Get the UCalendar associated with an UDateFormat. 1258 * A UDateFormat uses a UCalendar to convert a raw value to, for example, 1259 * the day of the week. 1260 * @param fmt The formatter to query. 1261 * @return A pointer to the UCalendar used by fmt. 1262 * @see udat_setCalendar 1263 * @stable ICU 2.0 1264 */ 1265 U_CAPI const UCalendar* U_EXPORT2 1266 udat_getCalendar(const UDateFormat* fmt); 1267 1268 /** 1269 * Set the UCalendar associated with an UDateFormat. 1270 * A UDateFormat uses a UCalendar to convert a raw value to, for example, 1271 * the day of the week. 1272 * @param fmt The formatter to set. 1273 * @param calendarToSet A pointer to an UCalendar to be used by fmt. 1274 * @see udat_setCalendar 1275 * @stable ICU 2.0 1276 */ 1277 U_CAPI void U_EXPORT2 1278 udat_setCalendar( UDateFormat* fmt, 1279 const UCalendar* calendarToSet); 1280 1281 /** 1282 * Get the UNumberFormat associated with an UDateFormat. 1283 * A UDateFormat uses a UNumberFormat to format numbers within a date, 1284 * for example the day number. 1285 * @param fmt The formatter to query. 1286 * @return A pointer to the UNumberFormat used by fmt to format numbers. 1287 * @see udat_setNumberFormat 1288 * @stable ICU 2.0 1289 */ 1290 U_CAPI const UNumberFormat* U_EXPORT2 1291 udat_getNumberFormat(const UDateFormat* fmt); 1292 1293 /** 1294 * Get the UNumberFormat for specific field associated with an UDateFormat. 1295 * For example: 'y' for year and 'M' for month 1296 * @param fmt The formatter to query. 1297 * @param field the field to query 1298 * @return A pointer to the UNumberFormat used by fmt to format field numbers. 1299 * @see udat_setNumberFormatForField 1300 * @stable ICU 54 1301 */ 1302 U_CAPI const UNumberFormat* U_EXPORT2 1303 udat_getNumberFormatForField(const UDateFormat* fmt, UChar field); 1304 1305 /** 1306 * Set the UNumberFormat for specific field associated with an UDateFormat. 1307 * It can be a single field like: "y"(year) or "M"(month) 1308 * It can be several field combined together: "yM"(year and month) 1309 * Note: 1310 * 1 symbol field is enough for multiple symbol field (so "y" will override "yy", "yyy") 1311 * If the field is not numeric, then override has no effect (like "MMM" will use abbreviation, not numerical field) 1312 * 1313 * @param fields the fields to set 1314 * @param fmt The formatter to set. 1315 * @param numberFormatToSet A pointer to the UNumberFormat to be used by fmt to format numbers. 1316 * @param status error code passed around (memory allocation or invalid fields) 1317 * @see udat_getNumberFormatForField 1318 * @stable ICU 54 1319 */ 1320 U_CAPI void U_EXPORT2 1321 udat_adoptNumberFormatForFields( UDateFormat* fmt, 1322 const UChar* fields, 1323 UNumberFormat* numberFormatToSet, 1324 UErrorCode* status); 1325 /** 1326 * Set the UNumberFormat associated with an UDateFormat. 1327 * A UDateFormat uses a UNumberFormat to format numbers within a date, 1328 * for example the day number. 1329 * This method also clears per field NumberFormat instances previously 1330 * set by {@see udat_setNumberFormatForField} 1331 * @param fmt The formatter to set. 1332 * @param numberFormatToSet A pointer to the UNumberFormat to be used by fmt to format numbers. 1333 * @see udat_getNumberFormat 1334 * @see udat_setNumberFormatForField 1335 * @stable ICU 2.0 1336 */ 1337 U_CAPI void U_EXPORT2 1338 udat_setNumberFormat( UDateFormat* fmt, 1339 const UNumberFormat* numberFormatToSet); 1340 /** 1341 * Adopt the UNumberFormat associated with an UDateFormat. 1342 * A UDateFormat uses a UNumberFormat to format numbers within a date, 1343 * for example the day number. 1344 * @param fmt The formatter to set. 1345 * @param numberFormatToAdopt A pointer to the UNumberFormat to be used by fmt to format numbers. 1346 * @see udat_getNumberFormat 1347 * @stable ICU 54 1348 */ 1349 U_CAPI void U_EXPORT2 1350 udat_adoptNumberFormat( UDateFormat* fmt, 1351 UNumberFormat* numberFormatToAdopt); 1352 /** 1353 * Get a locale for which date/time formatting patterns are available. 1354 * A UDateFormat in a locale returned by this function will perform the correct 1355 * formatting and parsing for the locale. 1356 * @param localeIndex The index of the desired locale. 1357 * @return A locale for which date/time formatting patterns are available, or 0 if none. 1358 * @see udat_countAvailable 1359 * @stable ICU 2.0 1360 */ 1361 U_CAPI const char* U_EXPORT2 1362 udat_getAvailable(int32_t localeIndex); 1363 1364 /** 1365 * Determine how many locales have date/time formatting patterns available. 1366 * This function is most useful as determining the loop ending condition for 1367 * calls to {@link #udat_getAvailable }. 1368 * @return The number of locales for which date/time formatting patterns are available. 1369 * @see udat_getAvailable 1370 * @stable ICU 2.0 1371 */ 1372 U_CAPI int32_t U_EXPORT2 1373 udat_countAvailable(void); 1374 1375 /** 1376 * Get the year relative to which all 2-digit years are interpreted. 1377 * For example, if the 2-digit start year is 2100, the year 99 will be 1378 * interpreted as 2199. 1379 * @param fmt The formatter to query. 1380 * @param status A pointer to an UErrorCode to receive any errors 1381 * @return The year relative to which all 2-digit years are interpreted. 1382 * @see udat_Set2DigitYearStart 1383 * @stable ICU 2.0 1384 */ 1385 U_CAPI UDate U_EXPORT2 1386 udat_get2DigitYearStart( const UDateFormat *fmt, 1387 UErrorCode *status); 1388 1389 /** 1390 * Set the year relative to which all 2-digit years will be interpreted. 1391 * For example, if the 2-digit start year is 2100, the year 99 will be 1392 * interpreted as 2199. 1393 * @param fmt The formatter to set. 1394 * @param d The year relative to which all 2-digit years will be interpreted. 1395 * @param status A pointer to an UErrorCode to receive any errors 1396 * @see udat_Set2DigitYearStart 1397 * @stable ICU 2.0 1398 */ 1399 U_CAPI void U_EXPORT2 1400 udat_set2DigitYearStart( UDateFormat *fmt, 1401 UDate d, 1402 UErrorCode *status); 1403 1404 /** 1405 * Extract the pattern from a UDateFormat. 1406 * The pattern will follow the pattern syntax rules. 1407 * @param fmt The formatter to query. 1408 * @param localized true if the pattern should be localized, false otherwise. 1409 * @param result A pointer to a buffer to receive the pattern. 1410 * @param resultLength The maximum size of result. 1411 * @param status A pointer to an UErrorCode to receive any errors 1412 * @return The total buffer size needed; if greater than resultLength, the output was truncated. 1413 * @see udat_applyPattern 1414 * @stable ICU 2.0 1415 */ 1416 U_CAPI int32_t U_EXPORT2 1417 udat_toPattern( const UDateFormat *fmt, 1418 UBool localized, 1419 UChar *result, 1420 int32_t resultLength, 1421 UErrorCode *status); 1422 1423 /** 1424 * Set the pattern used by an UDateFormat. 1425 * The pattern should follow the pattern syntax rules. 1426 * @param format The formatter to set. 1427 * @param localized true if the pattern is localized, false otherwise. 1428 * @param pattern The new pattern 1429 * @param patternLength The length of pattern, or -1 if null-terminated. 1430 * @see udat_toPattern 1431 * @stable ICU 2.0 1432 */ 1433 U_CAPI void U_EXPORT2 1434 udat_applyPattern( UDateFormat *format, 1435 UBool localized, 1436 const UChar *pattern, 1437 int32_t patternLength); 1438 1439 /** 1440 * The possible types of date format symbols 1441 * @stable ICU 2.6 1442 */ 1443 typedef enum UDateFormatSymbolType { 1444 /** The era names, for example AD */ 1445 UDAT_ERAS, 1446 /** The month names, for example February */ 1447 UDAT_MONTHS, 1448 /** The short month names, for example Feb. */ 1449 UDAT_SHORT_MONTHS, 1450 /** The CLDR-style format "wide" weekday names, for example Monday */ 1451 UDAT_WEEKDAYS, 1452 /** 1453 * The CLDR-style format "abbreviated" (not "short") weekday names, for example "Mon." 1454 * For the CLDR-style format "short" weekday names, use UDAT_SHORTER_WEEKDAYS. 1455 */ 1456 UDAT_SHORT_WEEKDAYS, 1457 /** The AM/PM names, for example AM */ 1458 UDAT_AM_PMS, 1459 /** The localized characters */ 1460 UDAT_LOCALIZED_CHARS, 1461 /** The long era names, for example Anno Domini */ 1462 UDAT_ERA_NAMES, 1463 /** The narrow month names, for example F */ 1464 UDAT_NARROW_MONTHS, 1465 /** The CLDR-style format "narrow" weekday names, for example "M" */ 1466 UDAT_NARROW_WEEKDAYS, 1467 /** Standalone context versions of months */ 1468 UDAT_STANDALONE_MONTHS, 1469 UDAT_STANDALONE_SHORT_MONTHS, 1470 UDAT_STANDALONE_NARROW_MONTHS, 1471 /** The CLDR-style stand-alone "wide" weekday names */ 1472 UDAT_STANDALONE_WEEKDAYS, 1473 /** 1474 * The CLDR-style stand-alone "abbreviated" (not "short") weekday names. 1475 * For the CLDR-style stand-alone "short" weekday names, use UDAT_STANDALONE_SHORTER_WEEKDAYS. 1476 */ 1477 UDAT_STANDALONE_SHORT_WEEKDAYS, 1478 /** The CLDR-style stand-alone "narrow" weekday names */ 1479 UDAT_STANDALONE_NARROW_WEEKDAYS, 1480 /** The quarters, for example 1st Quarter */ 1481 UDAT_QUARTERS, 1482 /** The short quarter names, for example Q1 */ 1483 UDAT_SHORT_QUARTERS, 1484 /** Standalone context versions of quarters */ 1485 UDAT_STANDALONE_QUARTERS, 1486 UDAT_STANDALONE_SHORT_QUARTERS, 1487 /** 1488 * The CLDR-style short weekday names, e.g. "Su", Mo", etc. 1489 * These are named "SHORTER" to contrast with the constants using _SHORT_ 1490 * above, which actually get the CLDR-style *abbreviated* versions of the 1491 * corresponding names. 1492 * @stable ICU 51 1493 */ 1494 UDAT_SHORTER_WEEKDAYS, 1495 /** 1496 * Standalone version of UDAT_SHORTER_WEEKDAYS. 1497 * @stable ICU 51 1498 */ 1499 UDAT_STANDALONE_SHORTER_WEEKDAYS, 1500 /** 1501 * Cyclic year names (only supported for some calendars, and only for FORMAT usage; 1502 * udat_setSymbols not supported for UDAT_CYCLIC_YEARS_WIDE) 1503 * @stable ICU 54 1504 */ 1505 UDAT_CYCLIC_YEARS_WIDE, 1506 /** 1507 * Cyclic year names (only supported for some calendars, and only for FORMAT usage) 1508 * @stable ICU 54 1509 */ 1510 UDAT_CYCLIC_YEARS_ABBREVIATED, 1511 /** 1512 * Cyclic year names (only supported for some calendars, and only for FORMAT usage; 1513 * udat_setSymbols not supported for UDAT_CYCLIC_YEARS_NARROW) 1514 * @stable ICU 54 1515 */ 1516 UDAT_CYCLIC_YEARS_NARROW, 1517 /** 1518 * Calendar zodiac names (only supported for some calendars, and only for FORMAT usage; 1519 * udat_setSymbols not supported for UDAT_ZODIAC_NAMES_WIDE) 1520 * @stable ICU 54 1521 */ 1522 UDAT_ZODIAC_NAMES_WIDE, 1523 /** 1524 * Calendar zodiac names (only supported for some calendars, and only for FORMAT usage) 1525 * @stable ICU 54 1526 */ 1527 UDAT_ZODIAC_NAMES_ABBREVIATED, 1528 /** 1529 * Calendar zodiac names (only supported for some calendars, and only for FORMAT usage; 1530 * udat_setSymbols not supported for UDAT_ZODIAC_NAMES_NARROW) 1531 * @stable ICU 54 1532 */ 1533 UDAT_ZODIAC_NAMES_NARROW, 1534 1535 /** 1536 * The narrow quarter names, for example 1 1537 * @stable ICU 70 1538 */ 1539 UDAT_NARROW_QUARTERS, 1540 1541 /** 1542 * The narrow standalone quarter names, for example 1 1543 * @stable ICU 70 1544 */ 1545 UDAT_STANDALONE_NARROW_QUARTERS 1546 } UDateFormatSymbolType; 1547 1548 struct UDateFormatSymbols; 1549 /** Date format symbols. 1550 * For usage in C programs. 1551 * @stable ICU 2.6 1552 */ 1553 typedef struct UDateFormatSymbols UDateFormatSymbols; 1554 1555 /** 1556 * Get the symbols associated with an UDateFormat. 1557 * The symbols are what a UDateFormat uses to represent locale-specific data, 1558 * for example month or day names. 1559 * @param fmt The formatter to query. 1560 * @param type The type of symbols to get. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS, 1561 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS 1562 * @param symbolIndex The desired symbol of type type. 1563 * @param result A pointer to a buffer to receive the pattern. 1564 * @param resultLength The maximum size of result. 1565 * @param status A pointer to an UErrorCode to receive any errors 1566 * @return The total buffer size needed; if greater than resultLength, the output was truncated. 1567 * @see udat_countSymbols 1568 * @see udat_setSymbols 1569 * @stable ICU 2.0 1570 */ 1571 U_CAPI int32_t U_EXPORT2 1572 udat_getSymbols(const UDateFormat *fmt, 1573 UDateFormatSymbolType type, 1574 int32_t symbolIndex, 1575 UChar *result, 1576 int32_t resultLength, 1577 UErrorCode *status); 1578 1579 /** 1580 * Count the number of particular symbols for an UDateFormat. 1581 * This function is most useful as for determining the loop termination condition 1582 * for calls to {@link #udat_getSymbols }. 1583 * @param fmt The formatter to query. 1584 * @param type The type of symbols to count. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS, 1585 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS 1586 * @return The number of symbols of type type. 1587 * @see udat_getSymbols 1588 * @see udat_setSymbols 1589 * @stable ICU 2.0 1590 */ 1591 U_CAPI int32_t U_EXPORT2 1592 udat_countSymbols( const UDateFormat *fmt, 1593 UDateFormatSymbolType type); 1594 1595 /** 1596 * Set the symbols associated with an UDateFormat. 1597 * The symbols are what a UDateFormat uses to represent locale-specific data, 1598 * for example month or day names. 1599 * @param format The formatter to set 1600 * @param type The type of symbols to set. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS, 1601 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS 1602 * @param symbolIndex The index of the symbol to set of type type. 1603 * @param value The new value 1604 * @param valueLength The length of value, or -1 if null-terminated 1605 * @param status A pointer to an UErrorCode to receive any errors 1606 * @see udat_getSymbols 1607 * @see udat_countSymbols 1608 * @stable ICU 2.0 1609 */ 1610 U_CAPI void U_EXPORT2 1611 udat_setSymbols( UDateFormat *format, 1612 UDateFormatSymbolType type, 1613 int32_t symbolIndex, 1614 UChar *value, 1615 int32_t valueLength, 1616 UErrorCode *status); 1617 1618 /** 1619 * Get the locale for this date format object. 1620 * You can choose between valid and actual locale. 1621 * @param fmt The formatter to get the locale from 1622 * @param type type of the locale we're looking for (valid or actual) 1623 * @param status error code for the operation 1624 * @return the locale name 1625 * @stable ICU 2.8 1626 */ 1627 U_CAPI const char* U_EXPORT2 1628 udat_getLocaleByType(const UDateFormat *fmt, 1629 ULocDataLocaleType type, 1630 UErrorCode* status); 1631 1632 /** 1633 * Set a particular UDisplayContext value in the formatter, such as 1634 * UDISPCTX_CAPITALIZATION_FOR_STANDALONE. 1635 * @param fmt The formatter for which to set a UDisplayContext value. 1636 * @param value The UDisplayContext value to set. 1637 * @param status A pointer to an UErrorCode to receive any errors 1638 * @stable ICU 51 1639 */ 1640 U_CAPI void U_EXPORT2 1641 udat_setContext(UDateFormat* fmt, UDisplayContext value, UErrorCode* status); 1642 1643 /** 1644 * Get the formatter's UDisplayContext value for the specified UDisplayContextType, 1645 * such as UDISPCTX_TYPE_CAPITALIZATION. 1646 * @param fmt The formatter to query. 1647 * @param type The UDisplayContextType whose value to return 1648 * @param status A pointer to an UErrorCode to receive any errors 1649 * @return The UDisplayContextValue for the specified type. 1650 * @stable ICU 53 1651 */ 1652 U_CAPI UDisplayContext U_EXPORT2 1653 udat_getContext(const UDateFormat* fmt, UDisplayContextType type, UErrorCode* status); 1654 1655 #ifndef U_HIDE_INTERNAL_API 1656 /** 1657 * Extract the date pattern from a UDateFormat set for relative date formatting. 1658 * The pattern will follow the pattern syntax rules. 1659 * @param fmt The formatter to query. 1660 * @param result A pointer to a buffer to receive the pattern. 1661 * @param resultLength The maximum size of result. 1662 * @param status A pointer to a UErrorCode to receive any errors 1663 * @return The total buffer size needed; if greater than resultLength, the output was truncated. 1664 * @see udat_applyPatternRelative 1665 * @internal ICU 4.2 technology preview 1666 */ 1667 U_CAPI int32_t U_EXPORT2 1668 udat_toPatternRelativeDate(const UDateFormat *fmt, 1669 UChar *result, 1670 int32_t resultLength, 1671 UErrorCode *status); 1672 1673 /** 1674 * Extract the time pattern from a UDateFormat set for relative date formatting. 1675 * The pattern will follow the pattern syntax rules. 1676 * @param fmt The formatter to query. 1677 * @param result A pointer to a buffer to receive the pattern. 1678 * @param resultLength The maximum size of result. 1679 * @param status A pointer to a UErrorCode to receive any errors 1680 * @return The total buffer size needed; if greater than resultLength, the output was truncated. 1681 * @see udat_applyPatternRelative 1682 * @internal ICU 4.2 technology preview 1683 */ 1684 U_CAPI int32_t U_EXPORT2 1685 udat_toPatternRelativeTime(const UDateFormat *fmt, 1686 UChar *result, 1687 int32_t resultLength, 1688 UErrorCode *status); 1689 1690 /** 1691 * Set the date & time patterns used by a UDateFormat set for relative date formatting. 1692 * The patterns should follow the pattern syntax rules. 1693 * @param format The formatter to set. 1694 * @param datePattern The new date pattern 1695 * @param datePatternLength The length of datePattern, or -1 if null-terminated. 1696 * @param timePattern The new time pattern 1697 * @param timePatternLength The length of timePattern, or -1 if null-terminated. 1698 * @param status A pointer to a UErrorCode to receive any errors 1699 * @see udat_toPatternRelativeDate, udat_toPatternRelativeTime 1700 * @internal ICU 4.2 technology preview 1701 */ 1702 U_CAPI void U_EXPORT2 1703 udat_applyPatternRelative(UDateFormat *format, 1704 const UChar *datePattern, 1705 int32_t datePatternLength, 1706 const UChar *timePattern, 1707 int32_t timePatternLength, 1708 UErrorCode *status); 1709 1710 /** 1711 * @internal 1712 * @see udat_open 1713 */ 1714 typedef UDateFormat* (U_EXPORT2 *UDateFormatOpener) (UDateFormatStyle timeStyle, 1715 UDateFormatStyle dateStyle, 1716 const char *locale, 1717 const UChar *tzID, 1718 int32_t tzIDLength, 1719 const UChar *pattern, 1720 int32_t patternLength, 1721 UErrorCode *status); 1722 1723 /** 1724 * Register a provider factory 1725 * @internal ICU 49 1726 */ 1727 U_CAPI void U_EXPORT2 1728 udat_registerOpener(UDateFormatOpener opener, UErrorCode *status); 1729 1730 /** 1731 * Un-Register a provider factory 1732 * @internal ICU 49 1733 */ 1734 U_CAPI UDateFormatOpener U_EXPORT2 1735 udat_unregisterOpener(UDateFormatOpener opener, UErrorCode *status); 1736 #endif /* U_HIDE_INTERNAL_API */ 1737 1738 1739 #endif /* #if !UCONFIG_NO_FORMATTING */ 1740 1741 #endif