RelativeDateFormatter

Since: BlackBerry 10.2.0

#include <bb/utility/i18n/RelativeDateFormatter>

To link against this class, add the following line to your .pro file: LIBS += -lbbutilityi18n

Formats QDateTime objects relative to current date/time.

A bb::utility::i18n::RelativeDateFormatter uses several ranges of QDateTime offsets to provide an informative yet simple representation. The supported types of bb::utility::i18n::RelativeDateFormatter objects are enumerated by and summarized in bb::utility::i18n::RelativeDateFormat.


Overview

Public Functions Index

RelativeDateFormatter (bb::utility::i18n::RelativeDateFormat::Type type=bb::utility::i18n::RelativeDateFormat::TimeCritical, QObject *parent=0)
virtual ~RelativeDateFormatter ()
Q_SLOT voidapplyCurrentTimeAsAnchor ()
Q_SLOT voidapplyUserRegionLocale ()
Q_INVOKABLE QStringformat (const QDateTime &dateTime) const
Q_SLOT voidsetAnchorTime (const QDateTime &anchorTime)
Q_SLOT voidsetClockFormat (bb::utility::i18n::ClockFormat::Type format)
voidsetLocale (const QLocale &locale)

Signals Index

voidchanged ()

Properties

bb::utility::i18n::RelativeDateFormat::Type type

The type of this relative date/time formatter.

Since:

BlackBerry 10.2.0

Public Functions

RelativeDateFormatter (

Creates a relative date/time formatter of the supplied type.

Note:

By default, all bb::utility::i18n::RelativeDateFormatter objects start with the user's currently selected locale and clock format override. The application is expected to call applyUserRegionLocale() and/or setClockFormat(bb::utility::i18n::ClockFormat::Type) with bb::utility::i18n::ClockFormat::ApplyUserFormat whenever the user changes these values.

Parameters
type

The bb::utility::i18n::RelativeDateFormat::Type to apply to this formatter.

parent

If not 0, the supplied parent will be responsible for deleting this instance.

Since:

BlackBerry 10.2.0

virtual~RelativeDateFormatter ()

Destructor.

Since:

BlackBerry 10.2.0

Q_SLOT void applyCurrentTimeAsAnchor ()

Updates this formatter with the current system date/time.

Note:

The user of bb::utility::i18n::RelativeDateFormatter is expected to call this function prior to calling format(const QDateTime &)const to ensure an accuracy. The current system time is automatically cached at creation of the formatter.

Applications filling out tables should call this function only once before each update, and then call format(const QDateTime &)const on all the rows to optimize performance.
Since:

BlackBerry 10.2.0

Q_SLOT void applyUserRegionLocale ()

Updates this formatter with the currently selected region locale.

The user of bb::utility::i18n::RelativeDateFormatter is expected to listen and maintain their own bb::system::LocaleType::Region type of bb::system::LocaleHandler, and call this function whenever the locale changes.

Note:

Cascades QML users may listen to bb::cascades::LocaleHandler or the QML Retranslate plugin.

Since:

BlackBerry 10.2.0

Q_INVOKABLE QString format (

Prints out a localized date/time to a string relative to the cached current time.

Parameters
dateTime

A QDateTime object that should be printed.

Return:

A QString with a formatted date and/or time.

Since:

BlackBerry 10.2.0

Q_SLOT void setAnchorTime (

Sets this formatter's reference time.

Parameters
anchorTime

A custom QDateTime to relate future format(const QDateTime &)const calls to.

Since:

BlackBerry 10.2.0

Q_SLOT void setClockFormat (

Changes the clock format used for formatting.

The bb::utility::i18n::ClockFormat::Type enum offers the choice to use the currently selected user setting, the default format in the current locale, or custom value.

Note:

If the clock format was previously set to bb::utility::i18n::ClockFormat::ApplyLocaleFormat, changing the locale will not affect the actual clock format used to format time.

Parameters
format

A bb::utility::i18n::ClockFormat to use as the new locale.

Since:

BlackBerry 10.2.0

void setLocale (

Changes the locale used for formatting.

Parameters
locale

A QLocale to use as the new locale.

Since:

BlackBerry 10.2.0

Signals

void changed ()

Emitted whenever this formatter changes.

The application can register a slot to this signal that calls format(const QDateTime &)const on all it's date/time values.

Since:

BlackBerry 10.2.0

Last modified: 2014-09-30



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus