# TimeInput — SvelteKit UI

Package: sveltekit-ui 1.1.94

Page: https://www.sveltekit-ui.com/components/time_input

Category: Input controls

Builds a time/date/datetime/period selection input with flexible granularity, calendar picker, optional time zone support, and more.

Public component import: `TimeInput`

Public manager import: `create_time_input_manager`

## Usage

```svelte
<script>
  // Import the shared stylesheet once in your application's root layout.
  import "sveltekit-ui/style.css"
  import { TimeInput, create_time_input_manager } from "sveltekit-ui"

  const manager = create_time_input_manager({
    label: "Due date",
    format: "calendar_date",
    val: "2026-09-15",
    is_popover: true,
  })
</script>

<TimeInput {manager} />
<p>Selected date: {manager.val}</p>
```

## Configuration

### `label`

- type: string or null
- default: null
- description: A text label displayed for the time input.

### `is_popover`

- type: boolean
- default: true
- description: If true, the time picker is shown in a popover when clicking a toggle button. If false, it’s displayed inline.

### `format`

- type: string
- default: time_full
- allowed_values:
  - time_full
  - epoch
  - calendar_date
  - datetime
  - datetime_utc
  - datetime_zoned
  - year_week
  - year
  - year_month
  - hour_minute
  - hour_minute_second
  - period_full
  - period_iso_8601
  - period_total_seconds
- description: Determines the interpretation of the time object. For example, 'datetime_zoned' or 'calendar_date'. Controls which UI sections appear (calendar, hours, etc.).

### `granularity_options`

- type: array of strings
- default:
  - year
  - month
  - week
  - day
  - hour
  - minute
  - second
- description: Which granularities are allowed, e.g. ['day','hour','minute']. The user can select from them if `is_show_granularity_dropdown` is true.

### `granularity`

- type: string
- default: day
- description: Specifies the current granularity (e.g. 'day','hour','minute','second').

### `val`

- type: object or null
- description: The starting value to set. `create_time_input_manager` will parse it as a time object. If null, means 'no value'.

### `is_show_granularity_dropdown`

- type: boolean
- default: false
- description: If true, displays a dropdown to change the time granularity.

### `picker_year`

- type: number or null
- default: current year
- description: The calendar’s initial highlighted year.

### `picker_month`

- type: number or null
- default: current month (1–12)
- description: The calendar’s initial highlighted month.

### `is_disabled`

- type: boolean
- default: false
- description: If true, the time input is not interactive.

### `on_finish`

- type: function or null
- description: Callback called when the user finalizes (clicking 'Finish'). Receives the time value. Typically returns an object like `{ is_success: boolean, ... }`.

## Methods

### `init()`

- description: Initializes internal state and managers, called once with the config.

### `set_val()`

- description: Set the time/datetime/period value from outside. Provide an object matching the relevant format or null.

### `set_to_now()`

- description: Convenient method to set the value to the current system time.

### `set_year()`

- description: Sets the year. Also updates the calendar year pickers.

### `set_month()`

- description: Sets the month (1–12). Also updates the calendar.

### `set_day_of_month()`

- description: Sets a new day of the month. (1–31) Also moves the selected date in the calendar.

### `set_hour()`

- description: Sets hour in [0..23].

### `set_minute()`

- description: Sets minute in [0..59].

### `set_second()`

- description: Sets second in [0..59].

### `set_timezone()`

- description: Sets the time zone (e.g. 'America/Los_Angeles').

### `set_picker_data()`

- description: Update `picker_year` and `picker_month` used by the internal calendar UI.

### `handle_left_month()`

- description: Calendar arrow method for shifting the visible month left.

### `handle_right_month()`

- description: Calendar arrow method for shifting the visible month right.

### `finish()`

- description: Closes the popover and calls the `on_finish` callback if provided.

## Returned state

### `val`

- type: object or null
- description: The current time/datetime/period value. It's structured according to the specified format & granularity, e.g. `{ year, month, day_of_month, hour, minute, timezone, ... }` or null.

### `popover_manager`

- type: object
- description: Controls the popover if `is_popover=true`. You can open or close the popover with `manager.popover_manager.open()` or `manager.popover_manager.close()`.

### `main_toggle_button_manager`

- type: object
- description: If `is_popover=true`, this is the toggle button’s manager used to open the time picker.

### `set_null_button_manager`

- type: object
- description: Clicking it clears the value to null.

### `finish_button_manager`

- type: object
- description: The button manager for finalizing the time selection (running `on_finish`).
