<secure-datetime>

A date and time picker with automatic input sanitization, configurable min/max range enforcement, and timezone normalization to UTC before submission. Supports all five date and time input subtypes with consistent security behavior across each.

<script type="module"
  src="/components/secure-datetime/secure-datetime.js">
</script>
View API Reference →
Live Demo

Configurations

type="date"
Calendar date input. Value is validated as a well-formed ISO 8601 date string before submission. Out-of-range values are rejected and cleared.
<secure-datetime
  type="date"
  label="Date"
  name="date"
  security-tier="public">
</secure-datetime>
type="time"
Clock time input. Validates HH:MM or HH:MM:SS format. Values outside a configured min/max window are rejected.
<secure-datetime
  type="time"
  label="Time"
  name="time"
  security-tier="public">
</secure-datetime>
type="datetime-local"
Combined date and time picker. The submitted value is normalized to UTC — the browser's local timezone offset is stripped before the value reaches your server.
<secure-datetime
  type="datetime-local"
  label="Date and Time"
  name="datetime"
  security-tier="public">
</secure-datetime>
type="month"
Year and month picker. Value format is YYYY-MM. Useful for expiry dates, billing periods, and subscription billing cycles.
<secure-datetime
  type="month"
  label="Month"
  name="month"
  security-tier="public">
</secure-datetime>
type="week"
ISO week picker. Value format is YYYY-WNN. Useful for sprint planning, scheduling, and reporting periods.
<secure-datetime
  type="week"
  label="Week"
  name="week"
  security-tier="public">
</secure-datetime>
security-tier="authenticated"
Audit log enabled. All changes are recorded with field name and value. Use for dates associated with user accounts, preferences, or history.
<secure-datetime
  security-tier="authenticated"
  label="Authenticated date"
  type="date"
  name="date">
</secure-datetime>
security-tier="sensitive"
Autocomplete disabled to prevent browsers from caching the value. Full audit log. Use for dates of birth, medical appointments, and legal deadlines.
<secure-datetime
  security-tier="sensitive"
  label="Sensitive date"
  type="date"
  name="date">
</secure-datetime>
required
Shows an inline error on blur when no date is selected. The required attribute is forwarded to the internal input so constraint validation also applies.
<secure-datetime
  label="Required date"
  name="date"
  type="date"
  required
  security-tier="public">
</secure-datetime>
disabled
Non-interactive. Excluded from form submission. Use to display a confirmed date from a previous step that the user cannot change.
<secure-datetime
  label="Disabled date"
  name="date"
  type="date"
  disabled
  security-tier="public">
</secure-datetime>
min / max
Server-defined range boundaries. Values outside the range are rejected on the component before submission — they never reach your handler. The constraint is also enforced on the internal input so the browser picker won't offer out-of-range dates.
<secure-datetime
  label="Date range"
  name="date"
  type="date"
  min="2025-01-01"
  max="2025-12-31"
  security-tier="public">
</secure-datetime>
step
Constrains valid values to increments of step. For type="time", the unit is seconds — 1800 restricts selection to half-hour slots. Out-of-step values are rejected on submission.
<!-- step in seconds (1800 = 30 min) -->
<secure-datetime
  label="Time (30 min steps)"
  name="time"
  type="time"
  step="1800"
  security-tier="public">
</secure-datetime>

Security Features

Security is enforced server-side. These features are client-side complements that reduce attack surface.

Range enforcement + timezone normalization All tiers

At mount, the component records the min, max, and step values from server-rendered attributes. On every change and blur event the submitted value is checked against those bounds. Out-of-range values are cleared and a secure-audit event is dispatched — the value never reaches your submit handler. For datetime-local the value is converted to UTC before dispatch, so your server always receives a timezone-agnostic timestamp regardless of the user's locale.

Manipulation attempt
// Attacker removes the max attribute
const el = document.querySelector('secure-datetime');
el.removeAttribute('max');
el.value = '2099-12-31';
What fires on your listener
element.addEventListener('secure-audit', e => {
  // e.detail.event === 'out_of_range_date'
  // e.detail.attemptedValue === '2099-12-31'
  // field cleared — value never submitted
});
FeaturePublicAuthenticatedSensitiveCritical
Input format validationYesYesYesYes
Range enforcement (min/max/step)YesYesYesYes
Timezone normalization to UTCYesYesYesYes
Audit logging-YesYesYes
Autocomplete disabled--YesYes

Theming

Secure-UI uses CSS custom properties. Override at :root, per-component, or per-instance. The secure-datetime component inherits all --secure-ui-input-* variables.

VariableDefaultDescription
--secure-ui-input-height2.5remInput height (shared with secure-input)
--secure-ui-input-padding-x0.75remHorizontal padding (shared)
--secure-ui-input-border-radius6pxCorner radius (shared)
--secure-ui-input-border-colorvar(--secure-ui-color-border)Border color (shared)
--secure-ui-input-border-color-focusvar(--secure-ui-color-primary)Focus border color (shared)
--secure-ui-input-bgvar(--secure-ui-color-bg-primary)Background color (shared)
--secure-ui-input-text-colorvar(--secure-ui-color-text-primary)Text color (shared)
Themed Example
secure-datetime {
  --secure-ui-input-border-radius: 0;
  --secure-ui-input-border-color: #7c3aed;
  --secure-ui-input-border-color-focus: #a78bfa;
  --secure-ui-input-height: 3rem;
}

Framework Examples

Web Components work natively in all frameworks. No wrappers, no adapters.

Plain HTML html
<script type="module"
  src="/components/secure-datetime/secure-datetime.js">
</script>

<secure-datetime
  label="Appointment"
  name="appointment"
  type="datetime-local"
  min="2025-01-01T00:00"
  max="2025-12-31T23:59"
  security-tier="authenticated"
  required>
</secure-datetime>
React (JSX) tsx
import { useEffect } from 'react';

export function AppointmentPicker() {
  useEffect(() => {
    import('/components/secure-datetime/secure-datetime.js');
  }, []);

  return (
    <secure-datetime
      label="Appointment"
      name="appointment"
      type="datetime-local"
      min="2025-01-01T00:00"
      security-tier="authenticated"
      required
    />
  );
}
Vue 3 vue
<template>
  <secure-datetime
    label="Appointment"
    name="appointment"
    type="datetime-local"
    :min="minDate"
    security-tier="authenticated"
    required>
  </secure-datetime>
</template>

<script setup>
import { onMounted } from 'vue';
const minDate = '2025-01-01T00:00';
onMounted(() => import('/components/secure-datetime/secure-datetime.js'));
</script>
Angular typescript
import { Component, CUSTOM_ELEMENTS_SCHEMA, OnInit } from '@angular/core';

@Component({
  selector: 'app-appointment-picker',
  template: `
    <secure-datetime
      label="Appointment"
      name="appointment"
      type="datetime-local"
      min="2025-01-01T00:00"
      security-tier="authenticated"
      required>
    </secure-datetime>
  `,
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
export class AppointmentPickerComponent implements OnInit {
  ngOnInit() {
    import('/components/secure-datetime/secure-datetime.js');
  }
}
Svelte svelte
<script>
  import { onMount } from 'svelte';
  onMount(() => import('/components/secure-datetime/secure-datetime.js'));
</script>

<secure-datetime
  label="Appointment"
  name="appointment"
  type="datetime-local"
  min="2025-01-01T00:00"
  security-tier="authenticated"
  required>
</secure-datetime>
Go / Templ templ
templ AppointmentPicker(min, max string) {
  <secure-datetime
    label="Appointment"
    name="appointment"
    type="datetime-local"
    min={ min }
    max={ max }
    security-tier="authenticated"
    required>
  </secure-datetime>
}