estruyf / vscode-front-matter

Front Matter is a CMS running straight in Visual Studio Code. Can be used with static site generators like Hugo, Jekyll, Hexo, NextJs, Gatsby, and many more...

Home Page:https://frontmatter.codes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enhancement: Add "dateOnly" field type or boolean setting to "datetime" fields

SummittDweller opened this issue · comments

Is your feature request related to a problem? Please describe.
Yes, see https://discord.com/channels/992409023607476224/1205057740104404994/1205721223443779614 for more detail. I have a "datetime" field where I specify the "dateFormat" as just "yyyy-MM-dd" so there's no time component, I just need to capture the date/day. The widget displays nicely with no time element required (that's perfect) but I find that I have to pick the "day after" my target in order to save the correct date. Presumably this is because I'm in the GMT -06:00 timezone and the picker is selecting a time of 00:00:00, and when that is converted to my local time it's in the previous day.

Describe the solution you'd like
A simple fix would be to add a "dateOnly" option to "datetime" fields, or create a "dateOnly" field type, OR detect when there is no hours or timezone component in a field's "dateFormat" and make it "dateOnly", no time or timezones involved. If necessary store the selected date as mid-day/noon/12:00:00 so that any timezone offset won't cause it to capture the wrong date.

Describe alternatives you've considered
I have 40+ years of programming experience so I forked your code to see if I might be able to help directly, but I don't know React so I'm sorry to say I can't be much help. Appreciate your efforts though! I also tried setting a "default" value of "2024-01-01 19:00-0600" for my date field (since most of my events are at 7 PM local time) but it doesn't appear to work, I always get a default of {{now}} regardless.

Additional context
I find that I can get past this issue by specifying a "dateFormat" of "yyyy-MM-dd HH:mmxx" but then I'm forced to select an accurate time of day. Doing that along with the "xx" timezone offset gives me the correct date, but also more effort and information than my editors expect to deal with.

@SummittDweller, I saw I pushed the fix to a branch where I was implementing another enhancement. I just brought the fix to the dev branch, so it should work in the beta.

Closing this issue as it was due to a bug. The dateFormat property can be used to exclude time.