diff --git a/packages/abc/cell/cell.service.ts b/packages/abc/cell/cell.service.ts index 2210a50595..d319d8c508 100644 --- a/packages/abc/cell/cell.service.ts +++ b/packages/abc/cell/cell.service.ts @@ -3,7 +3,7 @@ import { DomSanitizer } from '@angular/platform-browser'; import { map, Observable, of } from 'rxjs'; import { yn } from '@delon/theme'; -import { AlainCellConfig, AlainConfigService } from '@delon/util/config'; +import { AlainConfigService } from '@delon/util/config'; import { formatDate } from '@delon/util/date-time'; import { CurrencyService, formatMask } from '@delon/util/format'; import { deepMerge } from '@delon/util/other'; @@ -25,12 +25,22 @@ export class CellService { private readonly nzI18n = inject(NzI18nService); private readonly currency = inject(CurrencyService); private readonly dom = inject(DomSanitizer); - private globalOptions!: AlainCellConfig; + private readonly configSrv = inject(AlainConfigService); + private globalOptions = this.configSrv.merge('cell', { + date: { format: 'yyyy-MM-dd HH:mm:ss' }, + img: { size: 32 }, + default: { text: '-' } + })!; private widgets: { [key: string]: CellWidget } = { date: { type: 'fn', ref: (value, opt) => { - return { text: formatDate(value as string, opt.date!.format!, this.nzI18n.getDateLocale()) }; + return { + text: formatDate(value as string, opt.date!.format!, { + locale: this.nzI18n.getDateLocale(), + customFormat: this.configSrv.get('themePipe')?.dateFormatCustom + }) + }; } }, mega: { @@ -66,14 +76,6 @@ export class CellService { } }; - constructor(configSrv: AlainConfigService) { - this.globalOptions = configSrv.merge('cell', { - date: { format: 'yyyy-MM-dd HH:mm:ss' }, - img: { size: 32 }, - default: { text: '-' } - })!; - } - registerWidget(key: string, widget: Type): void { this.widgets[key] = { type: 'widget', ref: widget }; } diff --git a/packages/theme/src/pipes/date/date.pipe.ts b/packages/theme/src/pipes/date/date.pipe.ts index 338eef4139..4b15642808 100644 --- a/packages/theme/src/pipes/date/date.pipe.ts +++ b/packages/theme/src/pipes/date/date.pipe.ts @@ -7,9 +7,14 @@ import { NzI18nService } from 'ng-zorro-antd/i18n'; @Pipe({ name: '_date', standalone: true }) export class DatePipe implements PipeTransform { private nzI18n = inject(NzI18nService); - private defFormat = inject(AlainConfigService).get('themePipe')?.dateFormat ?? 'yyyy-MM-dd HH:mm'; + private cog = inject(AlainConfigService).get('themePipe'); transform(value: Date | string | number, formatString?: string | null): string { - return formatDate(value, formatString ?? this.defFormat, this.nzI18n.getDateLocale()); + const formatStr = formatString ?? this.cog?.dateFormat ?? 'yyyy-MM-dd HH:mm'; + + return formatDate(value, formatStr, { + locale: this.nzI18n.getDateLocale(), + customFormat: this.cog?.dateFormatCustom + }); } } diff --git a/packages/util/config/theme/index.ts b/packages/util/config/theme/index.ts index 8ba6b19c7d..e30d7107da 100644 --- a/packages/util/config/theme/index.ts +++ b/packages/util/config/theme/index.ts @@ -1,3 +1,4 @@ export * from './http.type'; export * from './responsive.type'; export * from './i18n.type'; +export * from './pipe.type'; diff --git a/packages/util/config/theme/pipe.type.ts b/packages/util/config/theme/pipe.type.ts index 546ebb8bd1..209fcf6fc7 100644 --- a/packages/util/config/theme/pipe.type.ts +++ b/packages/util/config/theme/pipe.type.ts @@ -1,3 +1,10 @@ export interface AlainThemePipeConfig { dateFormat?: string; + dateFormatCustom?: AlainThemePipeDateFormatCustom; } + +export type AlainThemePipeDateFormatCustom = ( + value: Date, + formatString?: string | null, + options?: { locale?: Locale } +) => string; diff --git a/packages/util/date-time/time.ts b/packages/util/date-time/time.ts index 726f25c2d4..1b3d40e5db 100644 --- a/packages/util/date-time/time.ts +++ b/packages/util/date-time/time.ts @@ -17,6 +17,7 @@ import { formatDistanceToNow } from 'date-fns'; +import type { AlainThemePipeDateFormatCustom } from '@delon/util/config'; import type { NzSafeAny } from 'ng-zorro-antd/core/types'; import { DateLocale } from 'ng-zorro-antd/i18n'; @@ -129,10 +130,16 @@ export function toDate(value?: Date | string | number | null, options?: string | * @param formatString Please refer to [date-fnd format](https://date-fns.org/v2.30.0/docs/format) for string format * @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 { +export function formatDate( + value: Date | string | number, + formatString: string, + options?: { locale?: DateLocale; customFormat?: AlainThemePipeDateFormatCustom } +): string { value = toDate(value); if (isNaN(value as NzSafeAny)) return ''; - const langOpt = { locale: dateLocale }; - return formatString === 'fn' ? formatDistanceToNow(value, langOpt) : format(value, formatString, langOpt); + const langOpt = { locale: options?.locale }; + return formatString === 'fn' + ? formatDistanceToNow(value, langOpt) + : (options?.customFormat ?? format)(value, formatString, langOpt); } diff --git a/scripts/ci/build-artifacts.sh b/scripts/ci/build-artifacts.sh index c639bcbfeb..b5e070af89 100755 --- a/scripts/ci/build-artifacts.sh +++ b/scripts/ci/build-artifacts.sh @@ -92,10 +92,10 @@ echo "https://${ACCESS_TOKEN}:@github.com" > .git/credentials if [[ $(git ls-remote origin "refs/tags/${buildTagName}") ]]; then echo "removed tag because tag is already published" - git tag -d ${buildTagName} - git push --delete origin ${buildTagName} - git push origin :refs/tags/${buildTagName} - sleep 2 + git tag -d ${buildTagName} || true + git push --delete origin ${buildTagName} || true + git push origin :refs/tags/${buildTagName} || true + sleep 5 fi echo "Git configuration has been updated to match the last commit author. Publishing now.."