jdorn / json-editor

JSON Schema Based Editor
MIT License
5.81k stars 1.08k forks source link

Inconsistency in format for date/time #313

Open rpavlik opened 9 years ago

rpavlik commented 9 years ago

Using this schema:

{

      "title": "Last-Modified timestamp",
      "description": "Should use RFC 3339, section 5.6 format, aka javascript Date.toJSON()",
      "type": "string",
      "format": "date-time"
}

I don't get a date/time picker. Per the spec (or at least this tutorial ) I would expect one - I thought this was initially a mismatch between the editor and the spec, but I still don't get one in your example if I change it to "format": "datetime" either. I'm using Bootstrap3.

jdorn commented 9 years ago

JSON Editor uses HTML5 input types (so 'date', 'datetime', or 'datetime-local') and relies on the browser for the datepicker and choosing a date format. The format keyword has no impact on validation.

I'd like to make dates more flexible in the future and make it better align to the JSON Schema spec.

odrotbohm commented 9 years ago

I just tried datetime and it doesn't seem to work. datetime-localhowever, does.

SteveHiner commented 7 years ago

If you make it more flexible can you make it accept seconds on datetime-local values? I've found that I have to zero out the seconds or the validation gives me an error message. For 01/27/2017 11:59:59 PM it will tell me it's invalid and the nearest valid dates are 01/27/2017 11:59 PM and 01/28/2017 12:00 AM.

It turns out that it's Chrome's validation kicking in. This can be fixed by setting the step size explicitly. Seems that Chrome internally sets the step size to a full minute. I fixed the validation problem on my site by running this on page load: $("input[type='datetime-local']").each(function () { var inp = $(this); inp.attr("step", "1"); });

If json-editor had a way to explicitly set the step size it would be nice. I guess I didn't try something like: "options": { "step": 1 } I guess I should try that.