Skip to content

Date binding misbehaves (probably depending on locale) #7897

Closed
@tosinek

Description

@tosinek

Describe the bug

Date binding input type=date bind:value={date} is broken if system locale (at least on Windows) is not set to MM/DD/YY (so it is broken for DD/MM/YY or YY/MM/DD), especially when editing an existing date.

I tested Chrome, Edge and Firefox.

Using on:input={e => date=e} or on:change will not work either.

Reproduction

With locale DD/MM/YYYY, the most annoying case is when you type "0" (for 01) in days or months, it resets the whole field (if there is an existing date already).

REPL with examples:
https://svelte.dev/repl/594639752b464fdc8ad7cc2d50f3d499?version=4.2.8

Logs

No particular logs, in some cases I was able to make it log

The specified value "[object Event]" does not conform to the required format, "yyyy-MM-dd".
prop_dev	@	VM233:350
update	@	VM233:426
update	@	VM233:177
flush	@	VM233:144
Promise.then (async)		
schedule_update	@	VM233:109
make_dirty	@	VM233:222
eval	@	VM233:260
change_handler	@	VM233:472

System Info

Windows 11, regional settings set to Czech. Newest Chrome and Firefox. Newest Svelte (from 3.55.1 up to 4.2.8)

Severity

annoyance

Workaround

As a workaround, use two variables instead of one.

<input type=date value={initialDate} on:change={handleDateChange}>
let otherDate
const handleDateChange = () => {
    otherDate = event.target.value
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions