Home     About PeterBlum.com     Policies     Download a Licensed Product     Newsletter
Peter's Date and Time
TimeOfDayTextBox and DurationTextBox Control

There are two types of time: time of day and duration. The time of day reflects a 24 hour period and users use two formats to enter it: 12 or 24 hour. The duration reflects a length of time. Users also use two formats to enter it: HH:MM:SS or decimal (3:30 or 3.5).

Peter's Date and Time offers separate TextBox controls for each of these types of time: TimeOfDayTextBox and DurationTextBox. Both have extensive features to make data entry easy and familiar.

Product Features

Here are the defaults for both textboxes to use while reviewing these features.

TimeOfDayTextBox: DurationTextBox:

Data Entry in the TextBox

  • All Peter's Date and Time controls use the System.Globalization.CultureInfo object to determine the extact format. So they are fully localizable.
  • Keystrokes are filtered to allow only the characters supported by the time format. This is not a "masked textbox", where the user is highly constrained to type a very specific character at a specific position because of the next feature...
  • Has a powerful fuzzy logic parser to interpret what the user types when they do not follow the time format precisely. Fuzzy logic allows users to enter data more quickly as they can use shortcuts.
    • Within the TimeOfDayTextBox, the user can enter time in either 12- or 24-hour format. The user can give a single character or the full text of the AM Descriptor and PM Descriptor. The user can put a space between the time and the AM/PM element. The following are all valid representations of the time: 12:34AM, 0:34, 12:34A, 12:34 A, 12:34 AM.
    • If the user omits the time separator and exits the TextBox, separators will be added for them. The field must have at least 3 digits and no time separators for this to work. For example, they can enter ‘1223’ for ’12:23’.
    • The user can omit parts the time. For example, type 12 to get 12:00 AM or 12:00 (military time).
  • You can determine if seconds are allowed. They can be stripped automatically if entered. They can optionally be hidden if they are set to 0. (12:23:45 will show as is. 12:23:00 will show as 12:23.)
  • The user can optionally enter a time as a decimal number where the whole part is the hours and the decimal is minutes and seconds. For example, 13.5 is 1:30PM on a TimeOfDayTextBox and 13:30 on a DurationTextBox.
  • You can enforce a rounding rule where whatever the user enters is converted up to the next X number of minutes. For example, if you round to every 5 minutes and the user enters 12:34, validation will change it to 12:35. This is helpful when entering times into a schedule.
  • Within the DurationTextBox, the user can enter time values up to 99999:59:59.
  • You can limit the times to be between a minimum and maximum time. For example, use it to limit a time of day to business hours or a duration to the 40 business hours in a week.
  • There are numerous commands available to assist the user (especially valuable when the user is likely to use the control frequently for data entry.) Commands are offered as single keystrokes, from optional arrow buttons, from an optional right click Context Menu or optional Help button. They are optionally shown in a tool tip associated with the TextBox.
    • Within the TimeOfDayTextBox, assign the current time of the user’s computer with the Now command. The default keystroke is ‘Control+N’.
    • Increment the minutes with the Next Minute command. Decrement the minutes with the Previous Minute command. Both support a value to add to minutes. It defaults to 1 but imagine changing it to 5, 10, etc for a scheduling application. Next Minute defaults to these keystrokes: up arrow and plus. Previous Minute defaults to down arrow and minus.
    • Increment the hours with the Next Hour command. The default keystroke is pageup. Decrement the hours with the Previous Hour command. The default keystroke is pagedown.

    Here is a TimeOfDayTextBox with optional Spinners and help button. Try out the buttons, keystroke commands, and right click for the context menu.

Popup TimePicker

You can add a PopupTimePicker to assist the user in selecting a time from a fixed list.

You can even make the textbox ReadOnly so the user must use the TimePicker or arrow buttons to assign the time value.

Add the UnselectableTimesValidator to report errors when the user does not pick a time found in the TimePicker or from a time interval rule (such as on 30 minute increments).

Other Features

  • Supports databinding on its value.
  • The time value can be represented by a DateTime structure or TimeSpan structure, both which are defined in the .Net framework. The TimeSpan structure has methods to convert to and from numerous other values such as number of seconds and number of hours.
  • TimeOfDayTextBox can be used as a companion to a DateTextBox. Start by linking the TimeOfDayTextBox to a DateTextBox. Then you can set and get a DateTime structure, with both date and time into the TimeOfDayTextBox’s xDateTime property and it will update both fields. In addition, its commands to increment minutes or hours will wrap around at midnight, incrementing the DateTextBox too. Finally, the validators can evaluate the two controls as a single Date+Time value.

    In this example, we've connected a TimeOfDayTextBox to a DateTextBox. When configured this way, you can assign and retrieve one DateTime structure representing both controls. Unfortunately, you can't see that in a demo. But you can see how using the arrows will change the date as it hits the minimum and maximum. Also use the Now command in the TimeOfDayTextBox (from the Help button or Ctrl+N) to see both fields filled in.

  • You can build a time range entry tool by adding two TimeOfDayTextBoxes or DurationTextBoxes to your form. Use the TimeTextBoxCompareValidator to validate the users entry so that the first time will be less than or equal to the second. If you have a date and time, add DateTextBoxes and the validator will include the dates in this validation.