2013-11-22 18:26:22 +00:00
|
|
|
/*
|
2014-01-11 00:30:39 +00:00
|
|
|
*****************************************************************************
|
2015-03-10 07:20:48 +00:00
|
|
|
* Copyright (C) 2014-2015, International Business Machines Corporation and
|
2013-11-22 18:26:22 +00:00
|
|
|
* others.
|
|
|
|
* All Rights Reserved.
|
2014-01-11 00:30:39 +00:00
|
|
|
*****************************************************************************
|
2013-11-22 18:26:22 +00:00
|
|
|
*
|
|
|
|
* File RELDATEFMT.H
|
2014-01-11 00:30:39 +00:00
|
|
|
*****************************************************************************
|
2013-11-22 18:26:22 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __RELDATEFMT_H
|
|
|
|
#define __RELDATEFMT_H
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
2014-04-03 22:44:00 +00:00
|
|
|
#include "unicode/uobject.h"
|
2014-05-22 22:46:53 +00:00
|
|
|
#include "unicode/udisplaycontext.h"
|
|
|
|
#include "unicode/locid.h"
|
2013-12-03 04:48:00 +00:00
|
|
|
|
2014-01-11 00:30:39 +00:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* \brief C++ API: Formats relative dates such as "1 day ago" or "tomorrow"
|
|
|
|
*/
|
|
|
|
|
2014-07-02 05:09:05 +00:00
|
|
|
#if !UCONFIG_NO_FORMATTING && !UCONFIG_NO_BREAK_ITERATION
|
2013-12-03 04:48:00 +00:00
|
|
|
|
2014-06-11 18:31:47 +00:00
|
|
|
/**
|
|
|
|
* The formatting style
|
|
|
|
* @draft ICU 54
|
|
|
|
*/
|
|
|
|
typedef enum UDateRelativeDateTimeFormatterStyle {
|
2015-06-10 17:21:08 +00:00
|
|
|
#ifndef U_HIDE_DRAFT_API
|
2014-06-11 18:31:47 +00:00
|
|
|
/**
|
|
|
|
* Everything spelled out.
|
|
|
|
* @draft ICU 54
|
|
|
|
*/
|
|
|
|
UDAT_STYLE_LONG,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abbreviations used when possible.
|
|
|
|
* @draft ICU 54
|
|
|
|
*/
|
|
|
|
UDAT_STYLE_SHORT,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use the shortest possible form.
|
|
|
|
* @draft ICU 54
|
|
|
|
*/
|
|
|
|
UDAT_STYLE_NARROW,
|
2014-06-11 19:45:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The number of styles.
|
|
|
|
* @draft ICU 54
|
|
|
|
*/
|
2014-06-12 19:55:36 +00:00
|
|
|
UDAT_STYLE_COUNT
|
2015-06-10 17:21:08 +00:00
|
|
|
#else
|
|
|
|
/** @internal */
|
|
|
|
UDAT_RELATIVE_DATE_TIME_FORMATTER_STYLE_HIDDEN
|
2015-03-10 07:20:48 +00:00
|
|
|
#endif /* U_HIDE_DRAFT_API */
|
2015-06-10 17:21:08 +00:00
|
|
|
} UDateRelativeDateTimeFormatterStyle;
|
2015-03-10 07:20:48 +00:00
|
|
|
|
2013-11-22 18:26:22 +00:00
|
|
|
/**
|
|
|
|
* Represents the unit for formatting a relative date. e.g "in 5 days"
|
|
|
|
* or "in 3 months"
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2013-11-22 18:26:22 +00:00
|
|
|
*/
|
|
|
|
typedef enum UDateRelativeUnit {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Seconds
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2014-01-21 18:26:44 +00:00
|
|
|
*/
|
2013-11-22 18:26:22 +00:00
|
|
|
UDAT_RELATIVE_SECONDS,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Minutes
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2014-01-21 18:26:44 +00:00
|
|
|
*/
|
2013-11-22 18:26:22 +00:00
|
|
|
UDAT_RELATIVE_MINUTES,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hours
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2014-01-21 18:26:44 +00:00
|
|
|
*/
|
2013-11-22 18:26:22 +00:00
|
|
|
UDAT_RELATIVE_HOURS,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Days
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2014-01-21 18:26:44 +00:00
|
|
|
*/
|
2013-11-22 18:26:22 +00:00
|
|
|
UDAT_RELATIVE_DAYS,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Weeks
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2014-01-21 18:26:44 +00:00
|
|
|
*/
|
2013-11-22 18:26:22 +00:00
|
|
|
UDAT_RELATIVE_WEEKS,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Months
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2014-01-21 18:26:44 +00:00
|
|
|
*/
|
|
|
|
UDAT_RELATIVE_MONTHS,
|
2013-11-22 18:26:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Years
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2014-01-21 18:26:44 +00:00
|
|
|
*/
|
2013-11-22 18:26:22 +00:00
|
|
|
UDAT_RELATIVE_YEARS,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Count of items in this enum.
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2013-11-22 18:26:22 +00:00
|
|
|
*/
|
|
|
|
UDAT_RELATIVE_UNIT_COUNT
|
|
|
|
} UDateRelativeUnit;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents an absolute unit.
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2013-11-22 18:26:22 +00:00
|
|
|
*/
|
|
|
|
typedef enum UDateAbsoluteUnit {
|
|
|
|
|
|
|
|
// Days of week have to remain together and in order from Sunday to
|
|
|
|
// Saturday.
|
|
|
|
/**
|
|
|
|
* Sunday
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2014-01-21 18:26:44 +00:00
|
|
|
*/
|
2013-11-22 18:26:22 +00:00
|
|
|
UDAT_ABSOLUTE_SUNDAY,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Monday
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2014-01-21 18:26:44 +00:00
|
|
|
*/
|
2013-11-22 18:26:22 +00:00
|
|
|
UDAT_ABSOLUTE_MONDAY,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tuesday
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2014-01-21 18:26:44 +00:00
|
|
|
*/
|
2013-11-22 18:26:22 +00:00
|
|
|
UDAT_ABSOLUTE_TUESDAY,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wednesday
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2014-01-21 18:26:44 +00:00
|
|
|
*/
|
2013-11-22 18:26:22 +00:00
|
|
|
UDAT_ABSOLUTE_WEDNESDAY,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Thursday
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2014-01-21 18:26:44 +00:00
|
|
|
*/
|
2013-11-22 18:26:22 +00:00
|
|
|
UDAT_ABSOLUTE_THURSDAY,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Friday
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2014-01-21 18:26:44 +00:00
|
|
|
*/
|
2013-11-22 18:26:22 +00:00
|
|
|
UDAT_ABSOLUTE_FRIDAY,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Saturday
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2014-01-21 18:26:44 +00:00
|
|
|
*/
|
2013-11-22 18:26:22 +00:00
|
|
|
UDAT_ABSOLUTE_SATURDAY,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Day
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2014-01-21 18:26:44 +00:00
|
|
|
*/
|
2013-11-22 18:26:22 +00:00
|
|
|
UDAT_ABSOLUTE_DAY,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Week
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2014-01-21 18:26:44 +00:00
|
|
|
*/
|
2013-11-22 18:26:22 +00:00
|
|
|
UDAT_ABSOLUTE_WEEK,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Month
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2014-01-21 18:26:44 +00:00
|
|
|
*/
|
2013-11-22 18:26:22 +00:00
|
|
|
UDAT_ABSOLUTE_MONTH,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Year
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2014-01-21 18:26:44 +00:00
|
|
|
*/
|
2013-11-22 18:26:22 +00:00
|
|
|
UDAT_ABSOLUTE_YEAR,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Now
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2013-11-22 18:26:22 +00:00
|
|
|
*/
|
|
|
|
UDAT_ABSOLUTE_NOW,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Count of items in this enum.
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2013-11-22 18:26:22 +00:00
|
|
|
*/
|
|
|
|
UDAT_ABSOLUTE_UNIT_COUNT
|
|
|
|
} UDateAbsoluteUnit;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents a direction for an absolute unit e.g "Next Tuesday"
|
|
|
|
* or "Last Tuesday"
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2013-11-22 18:26:22 +00:00
|
|
|
*/
|
|
|
|
typedef enum UDateDirection {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Two before. Not fully supported in every locale.
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2014-01-21 18:26:44 +00:00
|
|
|
*/
|
2013-11-22 18:26:22 +00:00
|
|
|
UDAT_DIRECTION_LAST_2,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Last
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2014-01-21 18:26:44 +00:00
|
|
|
*/
|
2013-11-22 18:26:22 +00:00
|
|
|
UDAT_DIRECTION_LAST,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2014-01-21 18:26:44 +00:00
|
|
|
*/
|
2013-11-22 18:26:22 +00:00
|
|
|
UDAT_DIRECTION_THIS,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Next
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2014-01-21 18:26:44 +00:00
|
|
|
*/
|
2013-11-22 18:26:22 +00:00
|
|
|
UDAT_DIRECTION_NEXT,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Two after. Not fully supported in every locale.
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2014-01-21 18:26:44 +00:00
|
|
|
*/
|
2013-11-22 18:26:22 +00:00
|
|
|
UDAT_DIRECTION_NEXT_2,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Plain, which means the absence of a qualifier.
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2014-01-21 18:26:44 +00:00
|
|
|
*/
|
2013-11-22 18:26:22 +00:00
|
|
|
UDAT_DIRECTION_PLAIN,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Count of items in this enum.
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2013-11-22 18:26:22 +00:00
|
|
|
*/
|
2013-12-04 20:46:08 +00:00
|
|
|
UDAT_DIRECTION_COUNT
|
2013-11-22 18:26:22 +00:00
|
|
|
} UDateDirection;
|
|
|
|
|
|
|
|
|
2014-01-21 18:26:44 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
2013-11-22 18:26:22 +00:00
|
|
|
|
2014-02-10 19:13:50 +00:00
|
|
|
class RelativeDateTimeCacheData;
|
|
|
|
class SharedNumberFormat;
|
|
|
|
class SharedPluralRules;
|
2014-05-22 22:46:53 +00:00
|
|
|
class SharedBreakIterator;
|
2013-11-22 18:26:22 +00:00
|
|
|
class NumberFormat;
|
2014-04-03 22:44:00 +00:00
|
|
|
class UnicodeString;
|
2013-11-22 18:26:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Formats simple relative dates. There are two types of relative dates that
|
|
|
|
* it handles:
|
|
|
|
* <ul>
|
|
|
|
* <li>relative dates with a quantity e.g "in 5 days"</li>
|
|
|
|
* <li>relative dates without a quantity e.g "next Tuesday"</li>
|
|
|
|
* </ul>
|
|
|
|
* <p>
|
|
|
|
* This API is very basic and is intended to be a building block for more
|
|
|
|
* fancy APIs. The caller tells it exactly what to display in a locale
|
|
|
|
* independent way. While this class automatically provides the correct plural
|
|
|
|
* forms, the grammatical form is otherwise as neutral as possible. It is the
|
|
|
|
* caller's responsibility to handle cut-off logic such as deciding between
|
|
|
|
* displaying "in 7 days" or "in 1 week." This API supports relative dates
|
|
|
|
* involving one single unit. This API does not support relative dates
|
2014-01-11 00:30:39 +00:00
|
|
|
* involving compound units,
|
2013-11-22 18:26:22 +00:00
|
|
|
* e.g "in 5 days and 4 hours" nor does it support parsing.
|
2013-12-04 22:50:25 +00:00
|
|
|
* <p>
|
|
|
|
* This class is mostly thread safe and immutable with the following caveats:
|
|
|
|
* 1. The assignment operator violates Immutability. It must not be used
|
|
|
|
* concurrently with other operations.
|
|
|
|
* 2. Caller must not hold onto adopted pointers.
|
|
|
|
* <p>
|
|
|
|
* This class is not intended for public subclassing.
|
2013-11-22 18:26:22 +00:00
|
|
|
* <p>
|
|
|
|
* Here are some examples of use:
|
|
|
|
* <blockquote>
|
|
|
|
* <pre>
|
|
|
|
* UErrorCode status = U_ZERO_ERROR;
|
|
|
|
* UnicodeString appendTo;
|
|
|
|
* RelativeDateTimeFormatter fmt(status);
|
|
|
|
* // Appends "in 1 day"
|
|
|
|
* fmt.format(
|
|
|
|
* 1, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_DAYS, appendTo, status);
|
|
|
|
* // Appends "in 3 days"
|
|
|
|
* fmt.format(
|
|
|
|
* 3, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_DAYS, appendTo, status);
|
|
|
|
* // Appends "3.2 years ago"
|
|
|
|
* fmt.format(
|
|
|
|
* 3.2, UDAT_DIRECTION_LAST, UDAT_RELATIVE_YEARS, appendTo, status);
|
|
|
|
* // Appends "last Sunday"
|
|
|
|
* fmt.format(UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_SUNDAY, appendTo, status);
|
|
|
|
* // Appends "this Sunday"
|
|
|
|
* fmt.format(UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_SUNDAY, appendTo, status);
|
|
|
|
* // Appends "next Sunday"
|
|
|
|
* fmt.format(UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_SUNDAY, appendTo, status);
|
|
|
|
* // Appends "Sunday"
|
|
|
|
* fmt.format(UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_SUNDAY, appendTo, status);
|
2014-01-21 18:26:44 +00:00
|
|
|
*
|
2013-11-22 18:26:22 +00:00
|
|
|
* // Appends "yesterday"
|
|
|
|
* fmt.format(UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_DAY, appendTo, status);
|
|
|
|
* // Appends "today"
|
|
|
|
* fmt.format(UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_DAY, appendTo, status);
|
|
|
|
* // Appends "tomorrow"
|
|
|
|
* fmt.format(UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_DAY, appendTo, status);
|
|
|
|
* // Appends "now"
|
|
|
|
* fmt.format(UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_NOW, appendTo, status);
|
|
|
|
*
|
|
|
|
* </pre>
|
|
|
|
* </blockquote>
|
|
|
|
* <p>
|
|
|
|
* In the future, we may add more forms, such as abbreviated/short forms
|
|
|
|
* (3 secs ago), and relative day periods ("yesterday afternoon"), etc.
|
|
|
|
*
|
|
|
|
* The RelativeDateTimeFormatter class is not intended for public subclassing.
|
2014-01-21 18:26:44 +00:00
|
|
|
*
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2013-11-22 18:26:22 +00:00
|
|
|
*/
|
|
|
|
class U_I18N_API RelativeDateTimeFormatter : public UObject {
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create RelativeDateTimeFormatter with default locale.
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2013-11-22 18:26:22 +00:00
|
|
|
*/
|
|
|
|
RelativeDateTimeFormatter(UErrorCode& status);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create RelativeDateTimeFormatter with given locale.
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2013-11-22 18:26:22 +00:00
|
|
|
*/
|
|
|
|
RelativeDateTimeFormatter(const Locale& locale, UErrorCode& status);
|
|
|
|
|
2013-12-04 22:50:25 +00:00
|
|
|
/**
|
|
|
|
* Create RelativeDateTimeFormatter with given locale and NumberFormat.
|
2014-01-21 18:26:44 +00:00
|
|
|
*
|
2013-12-04 22:50:25 +00:00
|
|
|
* @param locale the locale
|
|
|
|
* @param nfToAdopt Constructed object takes ownership of this pointer.
|
|
|
|
* It is an error for caller to delete this pointer or change its
|
|
|
|
* contents after calling this constructor.
|
|
|
|
* @status Any error is returned here.
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2013-12-04 22:50:25 +00:00
|
|
|
*/
|
|
|
|
RelativeDateTimeFormatter(
|
|
|
|
const Locale& locale, NumberFormat *nfToAdopt, UErrorCode& status);
|
|
|
|
|
2015-03-10 07:20:48 +00:00
|
|
|
#ifndef U_HIDE_DRAFT_API
|
2014-05-22 22:46:53 +00:00
|
|
|
/**
|
|
|
|
* Create RelativeDateTimeFormatter with given locale, NumberFormat,
|
|
|
|
* and capitalization context.
|
|
|
|
*
|
|
|
|
* @param locale the locale
|
|
|
|
* @param nfToAdopt Constructed object takes ownership of this pointer.
|
|
|
|
* It is an error for caller to delete this pointer or change its
|
|
|
|
* contents after calling this constructor. Caller may pass NULL for
|
|
|
|
* this argument if they want default number format behavior.
|
|
|
|
* @param style the format style. The UDAT_RELATIVE bit field has no effect.
|
2014-06-11 19:45:30 +00:00
|
|
|
* @param capitalizationContext A value from UDisplayContext that pertains to
|
|
|
|
* capitalization.
|
2014-05-22 22:46:53 +00:00
|
|
|
* @status Any error is returned here.
|
2014-07-01 16:41:37 +00:00
|
|
|
* @draft ICU 54
|
2014-05-22 22:46:53 +00:00
|
|
|
*/
|
|
|
|
RelativeDateTimeFormatter(
|
|
|
|
const Locale& locale,
|
|
|
|
NumberFormat *nfToAdopt,
|
2014-06-11 18:31:47 +00:00
|
|
|
UDateRelativeDateTimeFormatterStyle style,
|
2014-05-22 22:46:53 +00:00
|
|
|
UDisplayContext capitalizationContext,
|
|
|
|
UErrorCode& status);
|
2015-03-10 07:20:48 +00:00
|
|
|
#endif /* U_HIDE_DRAFT_API */
|
2014-05-22 22:46:53 +00:00
|
|
|
|
2013-11-22 18:26:22 +00:00
|
|
|
/**
|
|
|
|
* Copy constructor.
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2013-11-22 18:26:22 +00:00
|
|
|
*/
|
|
|
|
RelativeDateTimeFormatter(const RelativeDateTimeFormatter& other);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assignment operator.
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2013-11-22 18:26:22 +00:00
|
|
|
*/
|
2014-01-11 00:30:39 +00:00
|
|
|
RelativeDateTimeFormatter& operator=(
|
|
|
|
const RelativeDateTimeFormatter& other);
|
2013-11-22 18:26:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor.
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2013-11-22 18:26:22 +00:00
|
|
|
*/
|
|
|
|
virtual ~RelativeDateTimeFormatter();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Formats a relative date with a quantity such as "in 5 days" or
|
|
|
|
* "3 months ago"
|
|
|
|
* @param quantity The numerical amount e.g 5. This value is formatted
|
|
|
|
* according to this object's NumberFormat object.
|
|
|
|
* @param direction NEXT means a future relative date; LAST means a past
|
|
|
|
* relative date. If direction is anything else, this method sets
|
|
|
|
* status to U_ILLEGAL_ARGUMENT_ERROR.
|
|
|
|
* @param unit the unit e.g day? month? year?
|
|
|
|
* @param appendTo The string to which the formatted result will be
|
|
|
|
* appended
|
|
|
|
* @param status ICU error code returned here.
|
|
|
|
* @return appendTo
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2013-11-22 18:26:22 +00:00
|
|
|
*/
|
2014-01-11 00:30:39 +00:00
|
|
|
UnicodeString& format(
|
|
|
|
double quantity,
|
|
|
|
UDateDirection direction,
|
|
|
|
UDateRelativeUnit unit,
|
|
|
|
UnicodeString& appendTo,
|
|
|
|
UErrorCode& status) const;
|
2013-11-22 18:26:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Formats a relative date without a quantity.
|
|
|
|
* @param direction NEXT, LAST, THIS, etc.
|
|
|
|
* @param unit e.g SATURDAY, DAY, MONTH
|
|
|
|
* @param appendTo The string to which the formatted result will be
|
|
|
|
* appended. If the value of direction is documented as not being fully
|
|
|
|
* supported in all locales then this method leaves appendTo unchanged if
|
|
|
|
* no format string is available.
|
|
|
|
* @param status ICU error code returned here.
|
|
|
|
* @return appendTo
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2013-11-22 18:26:22 +00:00
|
|
|
*/
|
2014-01-11 00:30:39 +00:00
|
|
|
UnicodeString& format(
|
|
|
|
UDateDirection direction,
|
|
|
|
UDateAbsoluteUnit unit,
|
|
|
|
UnicodeString& appendTo,
|
|
|
|
UErrorCode& status) const;
|
2013-11-22 18:26:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Combines a relative date string and a time string in this object's
|
|
|
|
* locale. This is done with the same date-time separator used for the
|
|
|
|
* default calendar in this locale.
|
|
|
|
*
|
|
|
|
* @param relativeDateString the relative date, e.g 'yesterday'
|
|
|
|
* @param timeString the time e.g '3:45'
|
|
|
|
* @param appendTo concatenated date and time appended here
|
|
|
|
* @param status ICU error code returned here.
|
|
|
|
* @return appendTo
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2013-11-22 18:26:22 +00:00
|
|
|
*/
|
|
|
|
UnicodeString& combineDateAndTime(
|
2014-01-11 00:30:39 +00:00
|
|
|
const UnicodeString& relativeDateString,
|
|
|
|
const UnicodeString& timeString,
|
|
|
|
UnicodeString& appendTo,
|
|
|
|
UErrorCode& status) const;
|
2013-11-22 18:26:22 +00:00
|
|
|
|
|
|
|
/**
|
2013-12-04 22:50:25 +00:00
|
|
|
* Returns the NumberFormat this object is using.
|
|
|
|
*
|
2015-03-10 07:20:48 +00:00
|
|
|
* @stable ICU 53
|
2013-11-22 18:26:22 +00:00
|
|
|
*/
|
2013-12-04 22:50:25 +00:00
|
|
|
const NumberFormat& getNumberFormat() const;
|
|
|
|
|
2015-03-10 07:20:48 +00:00
|
|
|
#ifndef U_HIDE_DRAFT_API
|
2014-05-22 22:46:53 +00:00
|
|
|
/**
|
|
|
|
* Returns the capitalization context.
|
|
|
|
*
|
|
|
|
* @draft ICU 54
|
|
|
|
*/
|
|
|
|
UDisplayContext getCapitalizationContext() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the format style.
|
|
|
|
*
|
|
|
|
* @draft ICU 54
|
|
|
|
*/
|
2014-06-11 18:31:47 +00:00
|
|
|
UDateRelativeDateTimeFormatterStyle getFormatStyle() const;
|
2015-03-10 07:20:48 +00:00
|
|
|
#endif /* U_HIDE_DRAFT_API */
|
|
|
|
|
2013-11-22 18:26:22 +00:00
|
|
|
private:
|
2014-05-22 22:46:53 +00:00
|
|
|
const RelativeDateTimeCacheData* fCache;
|
|
|
|
const SharedNumberFormat *fNumberFormat;
|
|
|
|
const SharedPluralRules *fPluralRules;
|
2014-06-11 18:31:47 +00:00
|
|
|
UDateRelativeDateTimeFormatterStyle fStyle;
|
2014-05-22 22:46:53 +00:00
|
|
|
UDisplayContext fContext;
|
|
|
|
const SharedBreakIterator *fOptBreakIterator;
|
|
|
|
Locale fLocale;
|
|
|
|
void init(
|
|
|
|
NumberFormat *nfToAdopt,
|
|
|
|
BreakIterator *brkIter,
|
|
|
|
UErrorCode &status);
|
|
|
|
void adjustForContext(UnicodeString &) const;
|
2013-11-22 18:26:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2014-07-02 05:09:05 +00:00
|
|
|
#endif /* !UCONFIG_NO_FORMATTING && !UCONFIG_NO_BREAK_ITERATION*/
|
2013-11-22 18:26:22 +00:00
|
|
|
#endif
|