Tempus Dominus Documentation

repository·master·Indexed 27 days ago

https://github.com/eonasdan/tempus-dominus

A robust, modern JavaScript date and time picker library. Version 6 is a TypeScript-based rewrite that eliminates dependencies on jQuery, Moment.js, and Bootstrap, requiring only Popper2 for positioning. It features a DateTime class for date manipulation and localization, a Display class for picker visibility control, and support for various icon sets including Font Awesome 5 and Bootstrap Icons v1.

Tokens
2.4K
Snippets
8
Records
27
Agent score
88%

What's inside Tempus Dominus

  1. Overview of Tempus Dominus v6

    master

    Tempus Dominus is a robust JavaScript date/time picker. Version 6 is a major rewrite written in TypeScript, optimized for modern browsers.

    Key characteristics:

    • No dependencies required: Bootstrap, Moment.js, and jQuery are no longer required.
    • Required dependency: Popper2 is required for correct picker positioning.
    • jQuery Support: If your project requires jQuery, a jQuery provider is available that wraps the native JavaScript functions.
  2. Use the Font Awesome 5 icon plugin

    master

    The Font Awesome 5 plugin provides a predefined set of icon classes for Tempus Dominus components. This plugin requires Font Awesome libraries to be loaded in your environment to display the icons correctly.

    To use this plugin, call the load function and pass the Tempus Dominus factory instance. This will update the DefaultOptions.display.icons configuration with the Font Awesome 5 icon set.

  3. Use EventEmitters for component lifecycle and updates

    master

    The EventEmitters class provides several event streams that allow developers to react to internal component changes. You can subscribe to these emitters to listen for specific actions or view updates.

    Available emitters:

    • triggerEvent: Emits BaseEvent objects.
    • viewUpdate: Emits generic updates to the view.
    • updateDisplay: Emits ViewUpdateValues (e.g., 'calendar', 'clock', 'all').
    • action: Emits an object containing the original event e and an optional action of type ActionTypes.
    • updateViewDate: Emits a DateTime object when the view date changes.
  4. Use the Moment.js parsing plugin

    master

    The Moment.js plugin allows Tempus Dominus to parse and format dates using Moment.js logic. To use this plugin, you must have moment loaded in your environment. The plugin overrides setFromInput to enable parsing based on a provided format string and overrides formatInput to format the date for the input field using that same format string.

    When initializing the plugin, you provide a format string (the option parameter) which Moment.js will use for both parsing and formatting.

  5. Access the picker widget and containers

    master

    The Display class provides getters to access the underlying DOM elements of the picker:

    • widget: Returns the main HTMLElement of the picker body.
    • dateContainer: Returns the HTMLElement containing the calendar/date components.
    • timeContainer: Returns the HTMLElement containing the clock/time components.
    • isVisible: Returns a boolean indicating if the picker is currently shown.