decaporg / decap-cms

A Git-based CMS for Static Site Generators
https://decapcms.org
MIT License
17.65k stars 3.02k forks source link

`picker_utc` of datetime widget is broken in #6980, resulting in a timezone mismatch #7132

Closed hangvane closed 2 months ago

hangvane commented 4 months ago

Describe the bug

picker_utc is broken in #6980, that takes no effect on the behavior of processing timezone.

https://github.com/decaporg/decap-cms/commit/22370b13e49a4a5f58a60ebd4bc40ce4b141eb11#diff-93df641b502cdffd0d6642a8c06ad7ba617a16ee4907262538db0820a966a886L161

As a result, the time displayed stored are mismatched.

If I pick the current time, I will get a time that is 8 hours early (in the filename slug: {{day}}-{{hour}}), and there's no way to change the behavior.

To Reproduce

  1. Add a datetime widget
    collections:
    - name: 'Post' # Used in routes, e.g., /admin/collections/blog
    label: 'post' # Used in the UI
    folder: 'source/_posts' # The path to the folder where the documents are stored
    create: true # Allow users to create new documents in this collection
    slug: '{{year}}{{month}}{{day}}-{{hour}}{{minute}}-{{filename}}' # Filename template, e.g., YYYY-MM-DD-title.md
    preview_path: '{{year}}-{{month}}/{{urlname}}.htm'
    fields: # The fields for each document, usually in front matter
      - {label: 'title', name: 'title', widget: 'string'}
      - {label: 'filename', name: 'filename', widget: 'string'}
      - {label: 'urlname', name: 'urlname', widget: 'string'}
      - {label: 'date', name: 'date', widget: 'datetime', picker_utc: true}
  2. Edit the date in the UI
  3. Check the front-matter and filename of the generated markdown file.

Expected behavior

The stored datetime string should be the same as picked.

Screenshots

Applicable Versions:

CMS configuration

collections:
  - name: 'Post' # Used in routes, e.g., /admin/collections/blog
    label: 'post' # Used in the UI
    folder: 'source/_posts' # The path to the folder where the documents are stored
    create: true # Allow users to create new documents in this collection
    slug: '{{year}}{{month}}{{day}}-{{hour}}{{minute}}-{{filename}}' # Filename template, e.g., YYYY-MM-DD-title.md
    preview_path: '{{year}}-{{month}}/{{urlname}}.htm'
    fields: # The fields for each document, usually in front matter
      - {label: 'title', name: 'title', widget: 'string'}
      - {label: 'filename', name: 'filename', widget: 'string'}
      - {label: 'urlname', name: 'urlname', widget: 'string'}
      - {label: 'date', name: 'date', widget: 'datetime', picker_utc: true}

Additional context

martinjagodic commented 3 months ago

A fix is released in v3.1.6 (#7091). @hangvane can you please test if it works now?

msfjarvis commented 3 months ago

This is still broken for me, when I try to use Decap to update a date I lose the TZ component and the invalid date causes Hugo to start ignoring that post. The change I made to my config.yml file is here, and this is what Decap did when I updated the date on a blog post: https://github.com/msfjarvis/msfjarvis.dev/commit/feb7f759c9157ce9d477febd670c86c2b0b375b5

demshy commented 3 months ago

@msfjarvis we also stumbled upon this issue on one of our projects, patch released just now in 3.1.8 seems so solve it for us. Do you mind checking it out?

msfjarvis commented 3 months ago

@msfjarvis we also stumbled upon this issue on one of our projects, patch released just now in 3.1.8 seems so solve it for us. Do you mind checking it out?

v3.1.8 fixed it, thank you!