-
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enhance date formatting (#428)
* feat: enhance date formatting * fix: recommended corrections * fix: recommended corrections * feat: add support for special string date * fix: timezone & add related test cases * chore(deps): repair merge conflict * feat: add support for non-string date conversion * test: locks the test timezone * feat: added error log information * refactor: handleTimeWithDefaultZone logic optimization * feat: tell Temporal timezone * feat: convert Temporal.PlainDate to Temporal.ZonedDateTime * refactor: non-ISO 8601 format & remove @js-temporal/polyfill * refactor: adjust logs * style: delete history code
- Loading branch information
Showing
19 changed files
with
284 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<script setup lang="ts"> | ||
import { formatDate } from 'valaxy' | ||
import type { FormatOptionsWithTZ } from 'date-fns-tz' | ||
defineProps<{ date?: string | number | Date, format?: string, timezone?: string, options?: FormatOptionsWithTZ }>() | ||
</script> | ||
|
||
<template> | ||
<div flex="~"> | ||
<time mr-4> | ||
{{ formatDate(date ?? new Date(), format, timezone, options) }} | ||
</time> | ||
|
||
<code> | ||
{{ format }} | ||
</code> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { expect, test } from '@playwright/test' | ||
import { env } from '../env' | ||
|
||
test.use({ | ||
baseURL: env['theme-yun'], | ||
}) | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto('/posts/date') | ||
}) | ||
|
||
test.describe('Frontmatter', () => { | ||
test('time format validation', async ({ page }) => { | ||
await expect(page.locator('#text-time-format-1 time')).toHaveText('20230719') | ||
await expect(page.locator('#text-time-format-2 time')).toHaveText('20210301120000') | ||
await expect(page.locator('#text-time-format-3 time')).toHaveText('2021/12/03 01:07') | ||
}) | ||
|
||
test('timezone format validation', async ({ page }) => { | ||
await expect(page.locator('#text-time-zone-1 time')).toHaveText('2004-06-15 18:00:00+02:00 GMT+2') | ||
await expect(page.locator('#text-time-zone-2 time')).toHaveText('2004-06-15 18:00:00+02:00 GMT+2') | ||
await expect(page.locator('#text-time-zone-3 time')).toHaveText('2004-06-16 00:00:00+08:00 GMT+8') | ||
await expect(page.locator('#text-time-zone-4 time')).toHaveText('2004-06-16 02:00:00+02:00 GMT+2') | ||
await expect(page.locator('#text-time-zone-5 time')).toHaveText('2004-06-15 23:00:00+07:00 GMT+7') | ||
await expect(page.locator('#text-time-zone-6 time')).toHaveText('2004-06-16 06:00:00+08:00 GMT+8') | ||
await expect(page.locator('#text-time-zone-6 time')).toHaveText('2004-06-16 06:00:00+08:00 GMT+8') | ||
await expect(page.locator('#text-time-zone-7 time')).toHaveText('2004-06-16 00:00:00+02:00 GMT+2') | ||
await expect(page.locator('#text-time-zone-8 time')).toHaveText('2004-06-16 08:00:00+08:00 GMT+8') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import yaml, { CORE_SCHEMA } from 'js-yaml' | ||
import type matter from 'gray-matter' | ||
import { EXCERPT_SEPARATOR } from '../../../constants' | ||
|
||
type GrayMatterOptions = matter.GrayMatterOption<string, GrayMatterOptions> | ||
|
||
export const matterOptions: GrayMatterOptions = { | ||
excerpt_separator: EXCERPT_SEPARATOR, | ||
engines: { | ||
yaml: { | ||
// Use the CORE_SCHEMA with more basic support to manually handle time (#409) | ||
parse: (str: string) => yaml.load(str, { schema: CORE_SCHEMA }) as object, | ||
stringify: (data: any) => yaml.dump(data), | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
49e8008
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://yun.valaxy.site as production
🚀 Deployed on https://66c0a0e2c2489885cd946bc2--valaxy.netlify.app