@@ -2,7 +2,7 @@ import { Component, EventEmitter, forwardRef, Input, OnDestroy, Output } from '@
22import { ControlValueAccessor , NG_VALUE_ACCESSOR } from '@angular/forms' ;
33import { div_rd , max , min } from '@tubular/math' ;
44import { CalendarType , DateTime , defaultLocale , getStartOfWeek , GregorianChange , Timezone , YMDDate } from '@tubular/time' ;
5- import { clone , isEqual , isObject , isString , noop , toBoolean , toNumber } from '@tubular/util' ;
5+ import { clone , convertDigits , convertDigitsToAscii , isEqual , isObject , isString , noop , toBoolean , toNumber } from '@tubular/util' ;
66import { Subscription , timer } from 'rxjs' ;
77import { SafeHtml } from '@angular/platform-browser' ;
88
@@ -32,21 +32,22 @@ const multiplier = [0, 1, 1, 10, 100, 1000];
3232 providers : [ { provide : NG_VALUE_ACCESSOR , useExisting : forwardRef ( ( ) => CalendarPanelComponent ) , multi : true } ]
3333} )
3434export class CalendarPanelComponent implements ControlValueAccessor , OnDestroy {
35- private ymd : YMDDate = { y : 2021 , m : 1 , d : 1 } ;
36- private _gregorianChange : GregorianChange ;
37- private _showDst = false ;
38- private _minYear = 1 ;
39- private _maxYear = 9999 ;
40- private _firstDay = getStartOfWeek ( defaultLocale ) ;
4135 private baseValue = [ 0 , 0 , 0 ] ;
4236 private dateTime : DateTime = new DateTime ( ) ;
43- private onTouchedCallback : ( ) => void = noop ;
37+ private digitBase = '0' ;
38+ private _firstDay = getStartOfWeek ( defaultLocale ) ;
39+ private _gregorianChange : GregorianChange ;
40+ private _maxYear = 9999 ;
41+ private _minYear = 1 ;
4442 private onChangeCallback : ( _ : any ) => void = noop ;
45- private timerSubscription : Subscription ;
43+ private onTouchedCallback : ( ) => void = noop ;
4644 private pendingDelta = 0 ;
4745 private pendingEvent : MouseEvent = null ;
46+ private _showDst = false ;
47+ private timerSubscription : Subscription ;
4848 private _weekDayFormat = 'ddd' ;
49- private _yearMonthFormat = 'MMM Y' ;
49+ private _yearMonthFormat = 'MMM~Y~' ;
50+ private ymd : YMDDate = { y : 2021 , m : 1 , d : 1 } ;
5051
5152 @Input ( ) backgroundDecorator : DayDecorator ;
5253 calendar : CalendarDateInfo [ ] [ ] = [ ] ;
@@ -64,6 +65,9 @@ export class CalendarPanelComponent implements ControlValueAccessor, OnDestroy {
6465
6566 constructor ( ) {
6667 this . updateDayHeadings ( ) ;
68+ const base : string [ ] = [ ] ;
69+ convertDigitsToAscii ( this . dateTime . format ( 'D' ) , base ) ;
70+ this . digitBase = base [ 0 ] ;
6771 }
6872
6973 ngOnDestroy ( ) : void {
@@ -102,6 +106,17 @@ export class CalendarPanelComponent implements ControlValueAccessor, OnDestroy {
102106 }
103107 }
104108
109+ get locale ( ) : string | string [ ] { return this . dateTime . locale ; }
110+ @Input ( ) set locale ( value : string | string [ ] ) {
111+ if ( ! isEqual ( this . dateTime . locale , value ) ) {
112+ this . dateTime . locale = value ;
113+ const base : string [ ] = [ ] ;
114+ convertDigitsToAscii ( this . dateTime . format ( 'D' ) , base ) ;
115+ this . digitBase = base [ 0 ] ;
116+ this . updateCalendar ( ) ;
117+ }
118+ }
119+
105120 get gregorianChangeDate ( ) : GregorianChange { return this . _gregorianChange ; }
106121 @Input ( ) set gregorianChangeDate ( newChange : GregorianChange ) {
107122 if ( ! isEqual ( this . _gregorianChange , newChange ) ) {
@@ -182,7 +197,7 @@ export class CalendarPanelComponent implements ControlValueAccessor, OnDestroy {
182197
183198 for ( let d = 1 ; d <= 7 ; ++ d )
184199 this . daysOfWeek . push ( new DateTime ( { y : 2017 , m : 1 , d : d + this . _firstDay , hrs : 12 } ,
185- 'UTC' , 'en-us' ) . format ( this . _weekDayFormat ) ) ;
200+ 'UTC' , this . dateTime . locale ) . format ( this . _weekDayFormat ) ) ;
186201 }
187202
188203 updateCalendar ( ) : void {
@@ -198,7 +213,7 @@ export class CalendarPanelComponent implements ControlValueAccessor, OnDestroy {
198213 const col = index % 7 ;
199214
200215 date . dayLength = dayLength ;
201- date . text = String ( date . d ) ;
216+ date . text = convertDigits ( String ( date . d ) , this . digitBase ) ;
202217 date . otherMonth = ( date . m !== month ) ;
203218 date . highlight = ( date . m === month && date . d === day ) ;
204219
@@ -230,7 +245,8 @@ export class CalendarPanelComponent implements ControlValueAccessor, OnDestroy {
230245 }
231246
232247 private updateTitle ( ) : void {
233- this . title [ 0 ] = new DateTime ( { y : this . ymd ?. y ?? 2021 , m : this . ymd ?. m ?? 1 } , 'UTC' , 'en-us' ) . format ( this . _yearMonthFormat ) ;
248+ this . title [ 0 ] = new DateTime ( { y : this . ymd ?. y ?? 2021 , m : this . ymd ?. m ?? 1 } , 'UTC' ,
249+ this . dateTime . locale ) . format ( this . _yearMonthFormat ) ;
234250 }
235251
236252 reset ( ) : void {
@@ -338,7 +354,7 @@ export class CalendarPanelComponent implements ControlValueAccessor, OnDestroy {
338354 else if ( mode === SelectMode . MONTH ) {
339355 const m = row * 4 + col + 1 ;
340356
341- return ( this . months [ m ] = new DateTime ( { y : 4000 , m, hrs : 12 } ) . format ( 'MMM' ) ) ;
357+ return ( this . months [ m ] = new DateTime ( { y : 4000 , m, hrs : 12 } , 'UTC' , this . dateTime . locale ) . format ( 'MMM' ) ) ;
342358 }
343359
344360 let index = row * this . cols + col ;
@@ -353,7 +369,7 @@ export class CalendarPanelComponent implements ControlValueAccessor, OnDestroy {
353369 const maxx = ( div_rd ( this . _maxYear - 1 , multiplier [ mode ] ) + 1 ) * multiplier [ mode ] ;
354370
355371 if ( ( minn <= value && value <= maxx ) )
356- return min ( max ( value , this . _minYear ) , this . _maxYear ) . toString ( ) ;
372+ return convertDigits ( min ( max ( value , this . _minYear ) , this . _maxYear ) . toString ( ) , this . digitBase ) ;
357373 else
358374 return '' ;
359375 }
0 commit comments