date grammar

Collects a date spoken in any of several formats.

Return keys/values

Key

Value

MEANING

Contains a string with the spoken date expressed as YYYYMMDD.

SWI_literal

Contains the exact text that was recognized.

CENTURY

Set to the first 2 digits of the year, when spoken by the caller. For example, set to "20" when the caller says "2009."

TWO_DIGIT_YEAR

Set to the last 2 digits of the year when the caller omits the thousand and hundreds (for example, saying "98" instead of "1998."

YEAR

Set to the 4-digit year.

MONTH

Set to the month number.

DAY

Set to the day of the month.

WEEKDAY

Set when the recognized phrase includes a specified weekday. For "Wednesday the fourth of June," the WEEKDAY key is set to 4. If no weekday is recognized, WEEKDAY is set to ?.

WEEKDAY is numbered from 1 for Sunday through 7 for Saturday, unless otherwise noted in the Language Supplement.

Because the grammar does not know the current date, it returns question marks (?) wherever the caller omits information. For example, if YYYYMMDD is 20080523, the following keys are set:

  • CENTURY=20
  • TWO_DIGIT_YEAR=08
  • YEAR=2008
  • MONTH=05
  • DAY=23
  • WEEKDAY=?

Missing fields are filled with ??. For example, if the recognition result is "Monday the 4th," the return value is ?????04, and fields are:

  • CENTURY=??
  • TWO_DIGIT_YEAR=??
  • YEAR=????
  • MONTH=??
  • DAY=04
  • WEEKDAY=2

The grammar also accepts relative phrases such as "yesterday," "today," and "tomorrow" which return values of -1, 0, and +1 respectively into the MEANING key. See the Language Supplement for details; some languages recognize terms for "the day before yesterday," and "the day after tomorrow."

Note that to be understood, at least the day of the month must be present. Phrases like "next Wednesday" and "June 2009" are not understood.

There is no validity checking on the date, either for day-of-week or days-in-month validity. For example, "Monday, July 4, 2007" is not automatically rejected even though July 4, 2007 is a Wednesday. Similarly, "April 31" is not rejected even though April has only 30 days.

Properties

The more narrowly you set these properties, the higher the recognition accuracy. However, narrow settings also limit the range of possibilities that callers are allowed to speak. Your settings must balance the need for accuracy with the expectations of your callers.

Property

Description

minallowed

Earliest date recognized, expressed as YYYYMMDD (default=19000101)

maxallowed

Latest date recognized (default=21991231)

minexpected

Earliest likely date (default=19000101)

maxexpected

Latest likely date (default=21991231)

If the latest date is earlier than the earliest date the Recognizer returns an error. If they are equal, the Recognizer only accepts a single date.

Setting an allowed range tells the Recognizer to only allow amounts inside the range you specify. Amounts outside the range are not recognized as part of the vocabulary.

Setting an expected range is meant to include the most likely 90% of amounts callers may speak, and is used by the recognition engine to improve accuracy on those dates.

You can use both allowed and expected ranges at the same time. The expected range must fall within the allowed range or an error is returned.

Example

builtin:grammar/date?language=en-US;minallowed=20060101;
   maxallowed=20091231;minexpected=20080301;maxexpected=20080430

DTMF interpretation

The grammar returns the same keys and MEANING when callers press touchtones instead of speaking. The format must be YYYYMMDD.

Extensions to VoiceXML specification

The VoiceXML specification does not specify how to handle ambiguous two-digit years or ambiguous months (for example, "97" instead of "1997" and "Monday the 4th"). The implementation allows the ambiguity by returning questions marks (?) for ambiguous information in both speech and DTMF grammars. In addition, for two-digit years, the Recognizer returns the TWO_DIGIT_YEAR key.