Class: TDateTimeFormatter

Declaration: DateTime.h

Taxonomy Categories:

Member Functions:


Interface Category:

API.

Inherits From:

TFormatter

Inherited By:

TPatternBasedDateTimeFormatter

Purpose:

An abstract base class for formatting and scanning date/time information. It defines the protocol to map a TTime or set of fields to textual representation and vice versa. The mappings can have variations, such as abbreviated month names, or 2/4 digit years. For example, text field values can include text such as Sept., September, Oct., October, Friday, and so on. Any field can have text representations--some calendars have names for the days of the month. TDateTimeFormatter descends from TFormatter and can be used in a TParameterFormatter. This class uses a TCalendar internally to map TTime to TDateTimeFields. Note that a date/time formatter only works correctly with a single TCalendar. For each TCalendar derived class, there should be at least one corresponding TDateTimeFormatter derived class. For example, TGregorianCalendar and TGregorianDateTimeFormatter, TLunarCalendar and TLunarDateTimeFormatter, and so on.

Instantiation:

Allocate on the heap or the stack.

Deriving Classes:

TDateTimeFormatter is an abstract base class. Deriving classes must override the pure virtual functions TimeToText, TextToTime, and GetCalendar. The concrete class TGregorianDateTimeFormatter is provided.

Concurrency:

Not multithread safe.

Resource Use:

No special requirements.

Other Considerations:

None.

Member Function: TDateTimeFormatter::~TDateTimeFormatter

virtual ~ TDateTimeFormatter ()

Interface Category:

API.

Purpose:

Destructor.

Calling Context:

Called to destroy an object.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TDateTimeFormatter::Format

  1. virtual void Format (const TFormattable & value, TText & text) const
  2. virtual void Format (const TFormattable & value, TText & text, TFormatResult & conversionResult) const

Interface Category:

API.

Purpose:

  1. Given a TFormattableTime value, returns the formatted text.
  2. Given a TFormattableTime value, returns the formatted text. Also returns information about the accuracy of the formatting.

Calling Context:

  1. Call this function directly.
  2. Call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws an exception if the TFormattable argument is not a TFormattableTime object.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TDateTimeFormatter::Scan

virtual void Scan (const TText & text, const TTextRange & inputRange, TFormattable & value, TScanResult & conversionResult) const

Interface Category:

API.

Purpose:

Given a text object, scans and parses it to return a time value.

Calling Context:

Call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TDateTimeFormatter::CreateFormattable

virtual TFormattable * CreateFormattable () const

Interface Category:

API.

Purpose:

Creates the formattable, TFormattableTime, used for this formatter.

Calling Context:

Called by the Scan function.

Parameters:

Return Value:

Returns a TFormattableTime object.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TDateTimeFormatter::CreateScanResult

virtual TScanResult * CreateScanResult () const

Interface Category:

API.

Purpose:

Creates the scanning accuracy result object, TScanResult, used by this formatter.

Calling Context:

Called by the Scan function.

Parameters:

Return Value:

Returns a TScanResult object. The caller owns the storage.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TDateTimeFormatter::CreateFormatResult

virtual TFormatResult * CreateFormatResult () const

Interface Category:

API.

Purpose:

Creates the formatting accuracy result object, TFormatResult, used by this formatter.

Calling Context:

Called by the Format function.

Parameters:

Return Value:

Returns a TFormatResult object. The caller owns the storage.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TDateTimeFormatter::SetMilitaryTime

virtual void SetMilitaryTime (bool flag)

Interface Category:

API.

Purpose:

Specifies whether military time (24-hour clock) should be used. For example, 15:00 instead of 3:00 p.m.

Calling Context:

Call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TDateTimeFormatter::IsMilitaryTime

virtual bool IsMilitaryTime () const

Interface Category:

API.

Purpose:

Queries whether military time (24 hour clock) should be used. For example, 15:00 instead of 3:00 p.m..

Calling Context:

Called during conversion operations to query this field.

Parameters:

Return Value:

Returns true if military time should be used.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TDateTimeFormatter::SetAbbreviateYear

virtual void SetAbbreviateYear (bool flag)

Interface Category:

API.

Purpose:

Specifies whether the year should be abbreviated to two digits. For example, '93 instead of 1993.

Calling Context:

Call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TDateTimeFormatter::IsAbbreviateYear

virtual bool IsAbbreviateYear () const

Interface Category:

API.

Purpose:

Queries whether the year should be abbreviated to two digits. For example, '93 instead 1993.

Calling Context:

Called during conversion operations to query this field.

Parameters:

Return Value:

Returns true if the year should be abbreviated to two digits.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TDateTimeFormatter::SetNumberFormat

virtual void SetNumberFormat (const TNumberFormatter & format)

Interface Category:

API.

Purpose:

Specifies the number formatter to be used by this formatter.

Calling Context:

Called to specify a number formatter for use when formatting numeric fields.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TDateTimeFormatter::SetFlexibleScanning

virtual void SetFlexibleScanning (bool flag)

Interface Category:

API.

Purpose:

Specifies whether flexible scanning should be used; that is, whether or not the scanning operation should allow alternate text matches. The scanning operation is faster when it does not perform flexible scanning, but this limits the range of input. By default, flexible scanning is performed.

Calling Context:

Call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TDateTimeFormatter::GetFlexibleScanning

bool GetFlexibleScanning () const

Interface Category:

API.

Purpose:

Queries whether flexible scanning should be used.

Calling Context:

Called during the scanning operation to query this field.

Parameters:

Return Value:

Returns true if flexible scanning should be used.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TDateTimeFormatter::Hash

virtual long Hash () const

Interface Category:

API.

Purpose:

Generates a hash value.

Calling Context:

Called to generate a hash value.

Parameters:

Return Value:

The numeric value of the hash.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TDateTimeFormatter::operator=

TDateTimeFormatter & operator =(const TDateTimeFormatter & format)

Interface Category:

API.

Purpose:

Assignment operator.

Calling Context:

Called when an object is assigned to another compatible object.

Parameters:

Return Value:

A non-const reference to the left-hand side object.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TDateTimeFormatter::operator<<=

virtual TStream & operator <<= (TStream & fromWhere)

Interface Category:

API.

Purpose:

Stream-in operator.

Calling Context:

Called to stream in data.

Parameters:

Return Value:

Returns a reference to the stream the object streams itself in from.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TDateTimeFormatter::operator>>=

virtual TStream & operator >>=(TStream & toWhere) const

Interface Category:

API.

Purpose:

Stream-out operator.

Calling Context:

Called to stream out data.

Parameters:

Return Value:

Returns a reference to the stream the object streams itself out to.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TDateTimeFormatter::TDateTimeFormatter

  1. TDateTimeFormatter ()
  2. TDateTimeFormatter (const TDateTimeFormatter & format)

Interface Category:

API.

Purpose:

  1. Default constructor.
  2. Copy constructor.

Calling Context:

  1. Called by the stream-in operators.
  2. Called to copy an object.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TDateTimeFormatter::TimeToText

virtual void TimeToText (TCalendar & calendar, TText & text, TFormatResult & result) const

Interface Category:

API.

Purpose:

Converts the time as represented in the calendar to a textual form. Also returns the format accuracy result.

Calling Context:

Called during the formatting operation.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TDateTimeFormatter::TextToTime

virtual void TextToTime (const TText & text, const TTextRange & inputRange, TCalendar & calendar, TScanResult & result) const

Interface Category:

API.

Purpose:

Scans a text object and attempts to parse it into date/time information, setting the fields of a calendar accordingly. It also returns the scan accuracy result.

Calling Context:

Called during the scanning operation.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TDateTimeFormatter::GetCalendar

virtual TCalendar * GetCalendar () const

Interface Category:

API.

Purpose:

A given formatter only works in conjunction with a particular calendar. Hence, this pure virtual function is overridden by the derived class to provide an appropriate calendar.

Calling Context:

Called by Format and Scan.

Parameters:

Return Value:

Returns the appropriate TCalendar derived class.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TDateTimeFormatter::GetNumberFormatter

TNumberFormatter * GetNumberFormatter () const

Interface Category:

API.

Purpose:

Returns the number formatter used by this formatter.

Calling Context:

Call by format and scan.

Parameters:

Return Value:

Returns the number formatter.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TDateTimeFormatter::SetCalendar

virtual void SetCalendar (const TCalendar & calendar)

Interface Category:

API.

Purpose:

Set the calendar for the formatter.

Calling Context:

Called to set the calendar for the formatter.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:


Member Function: TDateTimeFormatter::SetName

virtual void SetName (const TLocalizableName & name)

Interface Category:

API.

Purpose:

Set the localizable name of the formatter.

Calling Context:

Called to set the localizable name of the formatter.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:


Member Function: TDateTimeFormatter::GetName

virtual void GetName (TLocalizableName & name) const

Interface Category:

API.

Purpose:

Get the localizable name of this formatter.

Calling Context:

Called to get the localizable name of the formatter.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:


Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.