Skip to content

Commit cf2065e

Browse files
committed
Add TimepickerI18nAdapter for ng-bootstrap timepicker
Introduces TimepickerI18nAdapter to provide localized AM/PM labels for NgbTimepickerI18n. Updates providers and index exports to register and expose the new adapter.
1 parent 212290b commit cf2065e

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

npm/ng-packs/packages/theme-shared/src/lib/adapters/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from './date-time.adapter';
22
export * from './date.adapter';
33
export * from './datepicker-i18n.adapter';
44
export * from './time.adapter';
5+
export * from './timepicker-i18n.adapter';
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { formatDate } from '@angular/common';
2+
import { inject, Injectable, LOCALE_ID } from '@angular/core';
3+
import { NgbTimepickerI18n } from '@ng-bootstrap/ng-bootstrap';
4+
import { ConfigStateService } from '@abp/ng.core';
5+
6+
@Injectable()
7+
export class TimepickerI18nAdapter extends NgbTimepickerI18n {
8+
private configState = inject(ConfigStateService, { optional: true });
9+
private defaultLocale = inject(LOCALE_ID);
10+
11+
private get locale(): string {
12+
return this.configState?.getDeep('localization.currentCulture.cultureName') || this.defaultLocale;
13+
}
14+
15+
getMorningPeriod(): string {
16+
const date = new Date(2000, 0, 1, 10, 0, 0);
17+
return formatDate(date, 'a', this.locale);
18+
}
19+
20+
getAfternoonPeriod(): string {
21+
const date = new Date(2000, 0, 1, 22, 0, 0);
22+
return formatDate(date, 'a', this.locale);
23+
}
24+
}

npm/ng-packs/packages/theme-shared/src/lib/providers/ng-bootstrap-config.provider.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { inject, provideAppInitializer } from '@angular/core';
2-
import { NgbDatepickerI18n, NgbInputDatepickerConfig, NgbTypeaheadConfig } from '@ng-bootstrap/ng-bootstrap';
3-
import { DatepickerI18nAdapter } from '../adapters';
2+
import { NgbDatepickerI18n, NgbInputDatepickerConfig, NgbTypeaheadConfig, NgbTimepickerI18n } from '@ng-bootstrap/ng-bootstrap';
3+
import { DatepickerI18nAdapter, TimepickerI18nAdapter } from '../adapters';
44

55
export const NG_BOOTSTRAP_CONFIG_PROVIDERS = [
66
{
77
provide: NgbDatepickerI18n,
88
useClass: DatepickerI18nAdapter,
99
},
10+
{
11+
provide: NgbTimepickerI18n,
12+
useClass: TimepickerI18nAdapter,
13+
},
1014
provideAppInitializer(() => {
1115
configureNgBootstrap();
1216
}),

0 commit comments

Comments
 (0)