From 0fa45bbd56f123273ec88aaa40a3c39a8d1fc790 Mon Sep 17 00:00:00 2001 From: cipchk Date: Sun, 22 Oct 2023 14:53:13 +0800 Subject: [PATCH] docs: update --- packages/util/date-time/index.en-US.md | 2 +- packages/util/date-time/index.zh-CN.md | 2 +- packages/util/date-time/time.ts | 8 +++----- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/util/date-time/index.en-US.md b/packages/util/date-time/index.en-US.md index 394e38a498..d55dca5b6c 100644 --- a/packages/util/date-time/index.en-US.md +++ b/packages/util/date-time/index.en-US.md @@ -16,7 +16,7 @@ Convert to `Date` format, support `Date, number, string` types, If the argument Format date, supports `Date, number, string` types, If the argument is a number, it is treated as a timestamp (Support seconds and milliseconds timestamp). * Please refer to [date-fnd format](https://date-fns.org/v2.30.0/docs/format) for string format -* `dateLocale` uses `NZ_DATE_LOCALE` by default to be consistent with NG-ZORRO +* `dateLocale` Recommended to be consistent with NG-ZORRO by using `inject(NZ_DATE_LOCALE)` ## dateTimePickerUtil diff --git a/packages/util/date-time/index.zh-CN.md b/packages/util/date-time/index.zh-CN.md index 8f3bd79e93..33c24aaa56 100644 --- a/packages/util/date-time/index.zh-CN.md +++ b/packages/util/date-time/index.zh-CN.md @@ -16,7 +16,7 @@ type: Tools 格式化日期,支持 `Date, number, string` 类型,如果是 `number` 表示 Unix timestamp (支持秒与毫秒)。 * 字符串格式请参考 [date-fnd format](https://date-fns.org/v2.30.0/docs/format) -* `dateLocale` 默认使用 `NZ_DATE_LOCALE` 与 NG-ZORRO 保持一致 +* `dateLocale` 建议通过使用 `inject(NZ_DATE_LOCALE)` 与 NG-ZORRO 保持一致 ## dateTimePickerUtil diff --git a/packages/util/date-time/time.ts b/packages/util/date-time/time.ts index 3c8cd13c10..7ad6f75bec 100644 --- a/packages/util/date-time/time.ts +++ b/packages/util/date-time/time.ts @@ -1,5 +1,3 @@ -import { inject } from '@angular/core'; - import { addDays, endOfDay, @@ -20,7 +18,7 @@ import { } from 'date-fns'; import type { NzSafeAny } from 'ng-zorro-antd/core/types'; -import { NZ_DATE_LOCALE, DateLocale } from 'ng-zorro-antd/i18n'; +import { DateLocale } from 'ng-zorro-antd/i18n'; /** * Get the time range, return `[ Date, Date]` for the start and end dates @@ -127,12 +125,12 @@ export function toDate(value?: Date | string | number | null, options?: string | * * @param value When is a number, it is treated as a timestamp (Support seconds and milliseconds timestamp). * @param formatString Please refer to [date-fnd format](https://date-fns.org/v2.30.0/docs/format) for string format - * @param dateLocale `dateLocale` uses `NZ_DATE_LOCALE` by default to be consistent with NG-ZORRO + * @param dateLocale Recommended to be consistent with NG-ZORRO by using `inject(NZ_DATE_LOCALE)` */ export function formatDate(value: Date | string | number, formatString: string, dateLocale?: DateLocale): string { value = toDate(value); if (isNaN(value as NzSafeAny)) return ''; - const langOpt = { locale: dateLocale ?? inject(NZ_DATE_LOCALE, { optional: true }) ?? undefined }; + const langOpt = { locale: dateLocale }; return formatString === 'fn' ? formatDistanceToNow(value, langOpt) : format(value, formatString, langOpt); }