decap-cms icon indicating copy to clipboard operation
decap-cms copied to clipboard

datetime widget shows user's timezone but saves in UTC

Open Strubbl opened this issue 1 year ago • 3 comments

Describe the bug If i see the datetime widget, it correctly shows my local time. When i set the date to now and save, the date&time is saved for UTC, e.g. 2024-10-31T20:57:00.000Z but should save it as 2024-10-31T20:57:00+02:00.

To Reproduce

  1. create content
  2. use the a datetime widget
  3. hit the "now" button
  4. save

Expected behavior 2024-10-31T20:57:00+02:00 is saved

Applicable Versions:

  • Decap CMS version: 3.3.3
  • Git provider: gitlab
  • OS: Archlinux
  • Browser version Firefox 132

CMS configuration

backend:
  name: gitlab
  repo: asdf/gfhrehrther
  branch: master
  auth_type: pkce
  app_id: asdf
site_url: https://sadfgsdfgsdfgsdfg.as
media_folder: "static/images"
public_folder: "/images"
collections:
  - name: "blog"
    label: "Blog Posts"
    label_singular: "Blog Post"
    folder: "content/post"
    create: true
    slug: "{{slug}}"
    editor:
      preview: false
    fields:
      - { label: "Title", name: "title", widget: "string" }
      - { label: "Draft", name: "draft", widget: "boolean" }
      - { label: "Publish Date", name: "date", widget: "datetime" }
      - { label: "Category", name: "category", widget: "select", multiple: true, min: 1, options: [] }
      - { label: "Tags", name: "tag", widget: "list", min: 1 }
      - { label: "Body", name: "body", widget: "markdown" }
    view_filters:
      - label: Drafts
        field: draft
        pattern: true
    view_groups:
      - label: Category
        field: category

Strubbl avatar Oct 31 '24 22:10 Strubbl

Working on it probably will open a PR to fix it through out this week

dfdez avatar Jan 30 '25 18:01 dfdez

Hey @Strubbl,

I've submitted a PR (#7386) that addresses this timezone handling issue. While waiting for the PR to be merged, you can apply an immediate fix to your project:

Add this configuration to your datetime widgets:

fields:
  - label: "Your Date Field"
    name: "date"
    widget: "datetime"
    picker_utc: false
    format: "YYYY-MM-DDTHH:mm:ss.SSSZ"

dfdez avatar Jan 30 '25 21:01 dfdez

Wow, thank you very much. It works as you described already now. My issue is fixed.

Strubbl avatar Jan 30 '25 22:01 Strubbl