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...
https://frontmatter.codes
MIT License
1.94k stars 77 forks source link

Enhancement: Custom date format with specific timezone #736

Closed dimaslanjaka closed 8 months ago

dimaslanjaka commented 8 months ago

Is your feature request related to a problem? Please describe. Iam using hexo framework.

Hexo output time string when used format 2024-01-21T06:34:03.845Z is wrong hour. the result is 2024-01-21T16:54:43+07:00 image

i've tried changing config date format, but not working. image this also not work image

Describe the solution you'd like I want print custom date format like 2024-01-21T13:29:27+07:00

Discussion: https://github.com/estruyf/vscode-front-matter/discussions/735

Related forum:

estruyf commented 8 months ago

On the datetime field, you can set how to format your date.

For instance, in your case, you can set the following:

{
  "title": "Date",
  "name": "date",
  "type": "datetime",
  "dateFormat": "yyyy-MM-dd'T'HH:mm:ssxxx"
}

If you want to set it for all your date fields, you can use the frontMatter.taxonomy.dateFormat setting and use the same value like the dateFormat property.

dimaslanjaka commented 8 months ago
yyyy-MM-dd'T'HH:mm:ssxxx

not work, the result still UTC ISO format.

image result image

How to set date format like 2024-01-21T16:54:43+07:00 ? i've tried YYYY-MM-DD'T'HH:mm:ssZ not work

dimaslanjaka commented 8 months ago

btw, in hexo _config.yml we can set timezone property like:

timezone: Asia/Jakarta

so, hexo will parse date with the given timezone or using config timezone. i think this caused inaccurate date output.

so, need custom formatting from frontmatter plugin to sync date with hexo.

dimaslanjaka commented 8 months ago

hey I found same format like hexo YYYY-MM-DD'T'HH:mm:ssZ.

the format is yyyy-MM-dd'T'HH:mm:ss.SSSXXX result 2024-01-25T22:03:38.825+07:00

how to output it like 2024-01-25T22:03:38+07:00 ?

dimaslanjaka commented 8 months ago

I fixed this issue with set custom date format to yyyy-MM-dd'T'HH:mm:ssXXX

here working config example for hexo:

{
  "$schema": "https://frontmatter.codes/frontmatter.schema.json",
  "frontMatter.content.autoUpdateDate": false,
  "frontMatter.preview.host": "http://localhost:4000",
  "frontMatter.taxonomy.contentTypes": [
    {
      "name": "default",
      "pageBundle": false,
      "fields": [
        {
          "title": "Title",
          "name": "title",
          "type": "string"
        },
        {
          "title": "Description",
          "name": "description",
          "type": "string"
        },
        {
          "title": "Publishing date",
          "name": "date",
          "type": "datetime",
          "default": "{{now}}",
          "isPublishDate": true,
          "dateFormat": "yyyy-MM-dd'T'HH:mm:ssXXX"
        },
        {
          "title": "Thumbnail",
          "name": "thumbnail",
          "type": "image"
        },
        {
          "title": "Is in draft",
          "name": "draft",
          "type": "boolean"
        },
        {
          "title": "Tags",
          "name": "tags",
          "type": "tags"
        },
        {
          "title": "Categories",
          "name": "categories",
          "type": "categories"
        },
        {
          "title": "updated",
          "name": "updated",
          "type": "datetime",
          "default": "{{now}}",
          "isModifiedDate": true,
          "dateFormat": "yyyy-MM-dd'T'HH:mm:ssXXX"
        },
        {
          "name": "permalink",
          "editable": true,
          "type": "slug"
        },
        {
          "title": "Author",
          "name": "author",
          "type": "divider"
        }
      ]
    }
  ],
  "frontMatter.framework.id": "hexo",
  "frontMatter.content.publicFolder": "hexo:post_asset_folder",
  "frontMatter.content.pageFolders": [
    {
      "path": "[[workspace]]/posts",
      "title": "Source Posts"
    }
  ],
  "frontMatter.site.baseURL": "https://www.webmanajemen.com/"
}

result image

estruyf commented 8 months ago

On the datetime field, you can set how to format your date.

For instance, in your case, you can set the following:

{
  "title": "Date",
  "name": "date",
  "type": "datetime",
  "dateFormat": "yyyy-MM-dd'T'HH:mm:ssxxx"
}

If you want to set it for all your date fields, you can use the frontMatter.taxonomy.dateFormat setting and use the same value like the dateFormat property.

Thanks @dimaslanjaka I proposed it as well, might be that you've missed it. Glad you found it as well.

dimaslanjaka commented 4 months ago

@estruyf the auto update date when file is modified not follow the pattern, please fix. i mentioned this closed issue for reference.