{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import datetime as dt\n",
    "import panel as pn\n",
    "\n",
    "pn.extension()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The ``DatetimeRangeInput`` widget allows selecting a datetime range using two [`DatetimeInput`](./DatetimeInput.ipynb) widgets, which return a tuple range.\n",
    "\n",
    "Discover more on using widgets to add interactivity to your applications in the [how-to guides on interactivity](../../how_to/interactivity/index.md). Alternatively, learn [how to set up callbacks and (JS-)links between parameters](../../how_to/links/index.md) or [how to use them as part of declarative UIs with Param](../../how_to/param/index.md).\n",
    "\n",
    "#### Parameters:\n",
    "\n",
    "For details on other options for customizing the component see the [layout](../../how_to/layout/index.md) and [styling](../../how_to/styling/index.md) how-to guides.\n",
    "\n",
    "\n",
    "##### Core\n",
    "\n",
    "* **``format``** (str): Datetime formatting string that determines how the value is formatted and parsed (``default='%Y-%m-%d %H:%M:%S'``)\n",
    "* **``start``** (datetime): The range's lower bound\n",
    "* **``end``** (datetime): The range's upper bound\n",
    "* **``value``** (tuple): Tuple of upper and lower bounds of the selected range expressed as datetime types\n",
    "\n",
    "##### Display\n",
    "\n",
    "* **``disabled``** (boolean): Whether the widget is editable\n",
    "* **``label``** (str): The title of the widget\n",
    "* **``name``** (str): Deprecated alias for ``label``; use ``label`` instead.\n",
    "\n",
    "___\n",
    "\n",
    "The datetime parser uses the defined ``format`` to validate the input value, if the entered text is not a valid datetime a warning will be shown in the title as \"`(invalid)`\":"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "datetime_range_input = pn.widgets.DatetimeRangeInput(\n",
    "    label='Datetime Range Input',\n",
    "    start=dt.datetime(2017, 1, 1), end=dt.datetime(2019, 1, 1),\n",
    "    value=(dt.datetime(2017, 1, 1), dt.datetime(2018, 1, 10)),\n",
    "    width=300\n",
    ")\n",
    "\n",
    "datetime_range_input"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "``DatetimeRangeInput.value`` returns a tuple of datetime values that can be read out and set like other widgets:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "datetime_range_input.value"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Controls\n",
    "\n",
    "The `DatetimeRangeInput` widget is a composite widget, which requires Python for communication. Therefore the controls only work when connected in a live Python server/kernel:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "pn.Row(datetime_range_input.controls(jslink=False), datetime_range_input)"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
