mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-23 02:40:56 +00:00
fix🐛: send datetime fields as RFC3339, not space-separated local time
Both date-pickers -- the search filter and the insert/edit form -- used value-format="YYYY-MM-DD HH:mm:ss", which formats a picked instant as e.g. "2026-09-19 12:30:00": no T separator, no offset. dto.go.template declares every datetime column's InsertReq/UpdateReq field as time.Time with a plain `json:"..."` tag (R6 leaves that file alone, so there is no time_format tag to reach for instead), and encoding/json's default (Un)MarshalJSON for time.Time only accepts RFC3339. The generated form would submit new and edited datetime values in a shape Go's JSON decoder cannot parse -- a runtime failure on every create and update, with nothing in `pnpm type-check` or `pnpm lint` positioned to see it: both check the request is well-typed TypeScript, not that the string it produces is a string Go can read. Changed both to value-format="YYYY-MM-DDTHH:mm:ssZ" -- dayjs's Z token renders the picker's own local offset, which is what a zero-nanosecond time.Time (anything without a database column storing sub-second precision) round-trips to on either side of the wire; confirmed separately against Go's actual json.Marshal/Unmarshal, not assumed from the RFC. The search filter needed the same fix, not just the form: GetPageReq binds a `time.Time` query field via `form:"..."` (dto.go.template), and gin's own default for an untagged time.Time binding is also RFC3339 -- the same failure mode on the query side, one call the report didn't name but the same root cause reaches. This is a runtime behaviour change no compiler catches, so it was verified as one: a Go program exercising encoding/json directly (not assumed from reading the RFC) confirmed a zero-nanosecond time.Time marshals to plain RFC3339 with no fractional seconds, and unmarshals correctly from both a numeric offset and a literal Z. Separately, a Node script loaded go-admin-ui's own installed dayjs 1.11.21 with the customParseFormat plugin -- the same plugin element-plus's date-picker extends dayjs with -- and called the same parseDate path date-picker panel.mjs uses (time-picker/src/utils.ts, no strict flag passed, so lenient parsing): formatting with this value-format produced a valid submission string, and parsing either an offset or a literal-Z string back with the same format produced a valid, correctly-valued date -- covering create, edit prefill, and update in the two directions that matter (browser to Go, Go to browser) without needing a live backend.
This commit is contained in:
@@ -99,7 +99,7 @@
|
||||
<el-date-picker
|
||||
v-model="table.query.{{.JsonField}}"
|
||||
type="datetime"
|
||||
value-format="YYYY-MM-DD HH:mm:ss"
|
||||
value-format="YYYY-MM-DDTHH:mm:ssZ"
|
||||
clearable
|
||||
/>
|
||||
{{- else}}
|
||||
@@ -223,7 +223,7 @@
|
||||
<el-date-picker
|
||||
v-model="form.model.{{.JsonField}}"
|
||||
type="datetime"
|
||||
value-format="YYYY-MM-DD HH:mm:ss"
|
||||
value-format="YYYY-MM-DDTHH:mm:ssZ"
|
||||
/>
|
||||
{{- else if eq .HtmlType "textarea"}}
|
||||
<el-input v-model="form.model.{{.JsonField}}" type="textarea" :rows="2" />
|
||||
|
||||
Reference in New Issue
Block a user