# Numbers, Booleans, Dates & URLs

> Exact validation rules, precision guards, timezone requirements, and JSON constraint keys for number, boolean, date, datetime, time, and url fields.

This page documents the six typed scalar fields beyond plain text: `number`, `boolean`, `date`, `datetime`, `time`, and `url`.

---

## `number`

Use `number` for prices, inventory counts, sort weights, coordinates, and ratings. OvertCMS decodes JSON numbers with `UseNumber()` and evaluates `integer`, `min`, `max`, `step`, and `precision` using **exact arbitrary-precision rational arithmetic (`big.Rat`)**, eliminating classic IEEE-754 floating-point drift (for example, `0.1 + 0.2` or `$19.99` on a `0.01` step).

### Safety & Precision Guards (`parseExactNumber`)

Before constraints run, every numeric token is checked for wire safety:

- **Strict JSON number only:** Quoted strings like `"42"` fail with `invalid_type`.
- **Finite only:** `NaN` and `Infinity` fail with `invalid_number`.
- **No negative zero:** `-0` fails with `negative_zero_not_allowed`.
- **JavaScript safe integer bound:** Magnitude must not exceed `±9007199254740991` (`2^53 - 1`), ensuring lossless round-tripping in JavaScript clients and Admin UIs. Values outside this bound fail with `unsafe_number`.
- **Token & exponent bounds (DoS guard):** Raw JSON number literals must be at most **128 bytes**, must not contain `/`, must have exponent within **`[-350, 350]`**, and must satisfy `fractionalDigits + |exponent| <= 350`.

### Constraints

| Constraint Key | Type | Default | Description |
| --- | --- | --- | --- |
| `integer` | `boolean` | `false` | Requires an exact integer value (`rat.IsInt()`). Fails with `integer_required`. |
| `min` | `number` | — | Inclusive lower bound (finite). Fails with `min_value`. |
| `max` | `number` | — | Inclusive upper bound (`>= min`, finite). Fails with `max_value`. |
| `step` | `number` | — | Positive finite increment (`> 0`). Value must satisfy `(value - base) / step` is an integer, where `base` is `min` if defined, otherwise `0`. Fails with `invalid_step`. |
| `precision` | `integer` | — | Maximum number of decimal places (`>= 0`). Checked by exact rational denominator factorization (powers of 2 and 5). Fails with `max_precision`. |

### Schema & Payload Examples

```json
{
  "key": "priceUsd",
  "label": "Price (USD)",
  "type": "number",
  "required": true,
  "requiredOn": "publish",
  "filterable": true,
  "sortable": true,
  "constraints": {
    "min": 0,
    "max": 99999.99,
    "step": 0.01,
    "precision": 2
  }
}
```

- **Valid:** `0`, `19.99`, `250.5`
- **Invalid:** `-0` (`negative_zero_not_allowed`), `19.995` (`invalid_step` and `max_precision`), `"19.99"` (`invalid_type`), `9007199254740992` (`unsafe_number`)

---

## `boolean`

Use `boolean` for binary flags such as `featured`, `isVerified`, or `showToc`.

- Accepts **only** JSON `true` or `false`. Strings (`"true"`), numbers (`1`), and objects fail with `invalid_type`.
- Has no type-specific `constraints` keys.
- Supports `filterable: true` (`eq`, `in`), `sortable: true`, and `defaultValue` (e.g., `false`).

```json
{
  "key": "featured",
  "label": "Featured",
  "type": "boolean",
  "defaultValue": false,
  "filterable": true,
  "sortable": true
}
```

---

## `date`

Use `date` for calendar dates without time-of-day or timezone semantics (such as publication dates, birthdays, or event start dates).

### Wire Format

- Strict 10-character ISO calendar date: **`YYYY-MM-DD`** (e.g., `"2026-11-25"`).
- Must round-trip identically via Go `time.Parse("2006-01-02", s)`—invalid calendar dates like `"2026-02-30"` or unpadded dates like `"2026-5-1"` fail with `invalid_date`.

### Constraints

| Constraint Key | Type | Description |
| --- | --- | --- |
| `minDate` | `string` (`YYYY-MM-DD`) | Inclusive minimum date. Fails with `min_date`. |
| `maxDate` | `string` (`YYYY-MM-DD`) | Inclusive maximum date (`>= minDate`). Fails with `max_date`. |

### Schema & Payload Examples

```json
{
  "key": "releaseDate",
  "label": "Release Date",
  "type": "date",
  "filterable": true,
  "sortable": true,
  "constraints": {
    "minDate": "2020-01-01",
    "maxDate": "2030-12-31"
  }
}
```

- **Valid:** `"2026-11-25"`
- **Invalid:** `"2026-02-29"` (`invalid_date` — 2026 is not a leap year), `"2026-11-25T00:00:00Z"` (`invalid_date`), `"2019-12-31"` (`min_date`)

---

## `datetime`

Use `datetime` for exact instants in time (event timestamps, deadlines, audit dates).

### Wire Format & Normalization

- Must be a valid **RFC3339 / ISO 8601** timestamp **with an explicit timezone offset or `Z`** (e.g., `"2026-11-25T16:30:00Z"` or `"2026-11-25T11:30:00-05:00"`).
- Bare datetimes without an offset (such as `"2026-11-25T16:30:00"`) are **rejected** with `invalid_datetime`.
- Valid inputs are **normalized to UTC** on save (`RFC3339` when nanoseconds are `0`, or `RFC3339Nano` when fractional seconds are present).

### Constraints

<Warning>
  Note the exact camelCase JSON casing: **`minDateTime`** and **`maxDateTime`** (capital **`T`**). Using `minDatetime` or `maxDatetime` will be rejected as an unknown field on schema writes.
</Warning>

| Constraint Key | Type | Description |
| --- | --- | --- |
| `minDateTime` | `string` (RFC3339) | Inclusive earliest instant (compared in UTC). Fails with `min_datetime`. |
| `maxDateTime` | `string` (RFC3339) | Inclusive latest instant (`>= minDateTime`). Fails with `max_datetime`. |

### Schema & Payload Examples

```json
{
  "key": "startsAt",
  "label": "Event Starts At",
  "type": "datetime",
  "required": true,
  "filterable": true,
  "sortable": true,
  "constraints": {
    "minDateTime": "2026-01-01T00:00:00Z",
    "maxDateTime": "2027-12-31T23:59:59Z"
  }
}
```

- **Valid:** `"2026-11-25T17:00:00+01:00"` (normalized to `"2026-11-25T16:00:00Z"`), `"2026-11-25T16:00:00.25Z"`
- **Invalid:** `"2026-11-25T17:00:00"` (`invalid_datetime` — missing timezone offset or `Z`), `"2025-12-31T23:59:59Z"` (`min_datetime`)

---

## `time`

Use `time` for wall-clock times of day independent of date or timezone (such as store opening hours or daily cutoffs).

### Wire Format

- Accepts **only** 24-hour **`HH:mm`** (5 characters) or **`HH:mm:ss`** (8 characters), from `00:00` to `23:59:59`.
- **No fractional seconds** (e.g., `"09:30:00.500"` is rejected).
- **No timezone offsets** (e.g., `"09:30:00Z"` is rejected).
- **No unpadded hours** (e.g., `"9:30"` is rejected).
- Malformed values fail with `invalid_time`.

### Constraints

| Constraint Key | Type | Description |
| --- | --- | --- |
| `minTime` | `string` (`HH:mm` or `HH:mm:ss`) | Inclusive earliest time of day (compared in seconds since midnight). Fails with `min_time`. |
| `maxTime` | `string` (`HH:mm` or `HH:mm:ss`) | Inclusive latest time of day (`>= minTime`). Fails with `max_time`. |

### Schema & Payload Examples

```json
{
  "key": "opensAt",
  "label": "Opening Time",
  "type": "time",
  "filterable": true,
  "sortable": true,
  "constraints": {
    "minTime": "06:00",
    "maxTime": "22:00:00"
  }
}
```

- **Valid:** `"09:00"`, `"18:30:45"`
- **Invalid:** `"9:00"` (`invalid_time`), `"09:00:00.123"` (`invalid_time`), `"09:00Z"` (`invalid_time`), `"24:00"` (`invalid_time`), `"05:30"` (`min_time`)

---

## `url`

Use `url` for links, external documentation URLs, social profiles, or optional root-relative internal paths.

### Constraints

| Constraint Key | Type | Default | Description |
| --- | --- | --- | --- |
| `allowedSchemes` | `string[]` | `["http", "https"]` | Case-insensitive list of permitted URL schemes (e.g., `["https"]` or `["https", "mailto"]`). Fails with `disallowed_url_scheme`. |
| `allowedHosts` | `string[]` | Any host | Case-insensitive exact hostname allowlist (e.g., `["github.com", "docs.overtcms.dev"]`). Fails with `disallowed_url_host`. |
| `allowRelative` | `boolean` | `false` | When `true`, allows root-relative paths starting with a single `/` (e.g., `"/pricing"`). Protocol-relative URLs (`"//evil.test"`) are always rejected. |

### Built-in Security & Placeholder Guards

Every `url` value is validated against strict security rules regardless of constraints:

1. **Character restrictions:** Must not contain whitespace (` `, `\t`, `\r`, `\n`), backslashes (`\`), curly braces (`{`, `}`), or ASCII control characters (`< 0x20` or `0x7F`). Fails with `invalid_url`.
2. **Forbidden schemes:** `javascript:`, `data:`, and `vbscript:` are **unconditionally rejected** with `unsafe_url`—even if obfuscated with whitespace or control characters (such as `java\tscript:`).
3. **Placeholder URL rejection:** Rejects LLM-generated placeholders (`#`, `TODO`, `TBD`, `url`, `[insert link]`, `{{...}}`, `example.com`, `example.org`, `example.net`, `.example`, or hosts containing `placeholder`) with `placeholder_link_detected`.
4. **Host presence:** `http` and `https` URLs must include a non-empty hostname (`invalid_url`).

### Schema & Payload Examples

```json
{
  "key": "ctaUrl",
  "label": "Call-to-Action URL",
  "type": "url",
  "required": false,
  "constraints": {
    "allowedSchemes": ["https"],
    "allowRelative": true
  }
}
```

- **Valid:** `"https://overtcms.dev/docs"`, `"/guides/quickstart"`
- **Invalid:** `"http://overtcms.dev"` (`disallowed_url_scheme`), `"//overtcms.dev/docs"` (`invalid_url`), `"javascript:alert(1)"` (`unsafe_url`), `"https://example.com/demo"` (`placeholder_link_detected`)
