@@ -21,10 +21,8 @@ export class IgxDateTimeEditorDirective extends IgxMaskDirective implements OnIn
2121  @Input ( ) 
2222  public  value : Date ; 
2323
24-   // TODO 
25-   // locale date formats should be the same sa igxdatepicker's - shortDate, longDate, etc 
2624  @Input ( ) 
27-   public  locale :  string ; 
25+   public  locale   =   'en' ; 
2826
2927  @Input ( ) 
3028  public  minValue : string  |  Date ; 
@@ -44,14 +42,17 @@ export class IgxDateTimeEditorDirective extends IgxMaskDirective implements OnIn
4442  @Output ( ) 
4543  public  validationFailed  =  new  EventEmitter < IgxDateTimeEditorEventArgs > ( ) ; 
4644
47-   public  get  format ( ) : string  { 
45+   @Input ( ) 
46+   public  displayFormat : string ; 
47+ 
48+   public  get  inputFormat ( ) : string  { 
4849    return  this . _format ; 
4950  } 
5051
5152  @Input ( `igxDateTimeEditor` ) 
52-   public  set  format ( value : string )  { 
53+   public  set  inputFormat ( value : string )  { 
5354    this . _format  =  value ; 
54-     const  mask  =  this . buildMask ( this . format ) ; 
55+     const  mask  =  this . buildMask ( this . inputFormat ) ; 
5556    this . mask  =  value . indexOf ( 'tt' )  !==  - 1  ? mask . substring ( 0 ,  mask . length  -  2 )  +  'LL'  : mask ; 
5657  } 
5758
@@ -71,6 +72,10 @@ export class IgxDateTimeEditorDirective extends IgxMaskDirective implements OnIn
7172    return  literals ; 
7273  } 
7374
75+   private  get  emptyInput ( )  { 
76+     return  this . maskParser . applyMask ( '' ,  this . maskOptions ) ; 
77+   } 
78+ 
7479  private  get  targetDatePart ( ) : DatePart  { 
7580    if  ( this . _document . activeElement  ===  this . nativeElement )  { 
7681      return  this . _dateTimeFormatParts . find ( p  =>  p . start  <=  this . selectionStart  &&  this . selectionStart  <=  p . end ) . type ; 
@@ -94,8 +99,8 @@ export class IgxDateTimeEditorDirective extends IgxMaskDirective implements OnIn
9499
95100  /** @hidden  */ 
96101  public  ngOnInit ( ) : void   { 
97-     this . _dateTimeFormatParts  =  DatePickerUtil . parseDateTimeFormat ( DatePickerUtil . setInputFormat ( this . format ) ) ; 
98-     this . renderer . setAttribute ( this . nativeElement ,  'placeholder' ,  this . format ) ; 
102+     this . _dateTimeFormatParts  =  DatePickerUtil . parseDateTimeFormat ( this . inputFormat ) ; 
103+     this . renderer . setAttribute ( this . nativeElement ,  'placeholder' ,  this . inputFormat ) ; 
99104  } 
100105
101106  public  clear ( ) : void   { 
@@ -105,15 +110,15 @@ export class IgxDateTimeEditorDirective extends IgxMaskDirective implements OnIn
105110
106111  public  increment ( datePart ?: DatePart ) : void   { 
107112    const  newValue  =  datePart  ? this . calculateValueOnSpin ( datePart ,  1 )  : this . calculateValueOnSpin ( this . targetDatePart ,  1 ) ; 
108-     if  ( newValue   &&   this . value   &&   newValue   !==   this . value )  { 
113+     if  ( newValue )  { 
109114      this . updateValue ( newValue ) ; 
110115      this . updateMask ( ) ; 
111116    } 
112117  } 
113118
114119  public  decrement ( datePart ?: DatePart ) : void   { 
115120    const  newValue  =  datePart  ? this . calculateValueOnSpin ( datePart ,  - 1 )  : this . calculateValueOnSpin ( this . targetDatePart ,  - 1 ) ; 
116-     if  ( newValue   &&   this . value   &&   newValue   !==   this . value )  { 
121+     if  ( newValue )  { 
117122      this . updateValue ( newValue ) ; 
118123      this . updateMask ( ) ; 
119124    } 
@@ -152,6 +157,7 @@ export class IgxDateTimeEditorDirective extends IgxMaskDirective implements OnIn
152157
153158  /** @hidden  */ 
154159  public  onFocus ( ) : void   { 
160+     // TODO: apply mask on focus & focused flag 
155161    this . onTouchCallback ( ) ; 
156162    super . onFocus ( ) ; 
157163  } 
@@ -161,19 +167,21 @@ export class IgxDateTimeEditorDirective extends IgxMaskDirective implements OnIn
161167    // if inputted string does not fit in the editor, show as many chars as possible followed by "..." ? 
162168    if  ( ! this . valueInRange ( this . value ) )  { 
163169      this . validationFailed . emit ( {  oldValue : this . _oldValue ,  newValue : this . value  } ) ; 
164-       // this.updateMask(); TODO: set empty mask 
170+       this . inputValue  =  this . emptyInput ; 
171+       this . updateValue ( null ) ; 
172+       return ; 
165173    } 
166174
167-     // TODO: display value pipe 
168-     //  this.updateMask( );
175+     const   format   =   this . displayFormat  ?  this . displayFormat  :  this . inputFormat ; 
176+     this . inputValue   =   formatDate ( this . value ,   format ,   this . locale ) ; 
169177    this . onTouchCallback ( ) ; 
170178    super . onBlur ( event ) ; 
171179  } 
172180
173181  /** @hidden  */ 
174-   protected  handleInputChanged ( ) : void   { 
182+   protected  onInputChanged ( ) : void   { 
175183    // the mask must be updated before any date operations 
176-     super . handleInputChanged ( ) ; 
184+     super . onInputChanged ( ) ; 
177185    if  ( this . inputValue  ===  this . maskParser . applyMask ( '' ,  this . maskOptions ) )  { 
178186      this . updateValue ( null ) ; 
179187      return ; 
@@ -187,8 +195,6 @@ export class IgxDateTimeEditorDirective extends IgxMaskDirective implements OnIn
187195        this . validationFailed . emit ( {  oldValue : this . value ,  newValue : parsedDate . value  } ) ; 
188196      } 
189197    } 
190- 
191-     super . afterInput ( ) ; 
192198  } 
193199
194200  private  buildMask ( format : string ) : string  { 
@@ -213,7 +219,7 @@ export class IgxDateTimeEditorDirective extends IgxMaskDirective implements OnIn
213219  } 
214220
215221  private  calculateValueOnSpin ( datePart : DatePart ,  delta : number ) : Date  { 
216-     if  ( ! this . value )  {  return ;  } 
222+     if  ( ! this . value )  {  return   null ;  } 
217223    const  currentDate  =  this . value  as  Date ; 
218224    const  newDate  =  new  Date ( currentDate . getFullYear ( ) ,  currentDate . getMonth ( ) ,  currentDate . getDate ( ) , 
219225      currentDate . getHours ( ) ,  currentDate . getMinutes ( ) ,  currentDate . getSeconds ( ) ) ; 
@@ -232,7 +238,9 @@ export class IgxDateTimeEditorDirective extends IgxMaskDirective implements OnIn
232238        case  DatePart . Seconds :
233239          return  DatePickerUtil . calculateSecondsOnSpin ( delta ,  newDate ,  currentDate ,  this . isSpinLoop ) ; 
234240        case  DatePart . AmPm :
235-           return  DatePickerUtil . calculateAmPmOnSpin ( delta ,  newDate ,  currentDate ) ; 
241+           const  formatPart  =  this . _dateTimeFormatParts . find ( dp  =>  dp . type  ===  DatePart . AmPm ) ; 
242+           const  amPmFromMask  =  this . inputValue . substring ( formatPart . start ,  formatPart . end ) ; 
243+           return  DatePickerUtil . calculateAmPmOnSpin ( newDate ,  currentDate ,  amPmFromMask ) ; 
236244      } 
237245    } 
238246
@@ -253,15 +261,34 @@ export class IgxDateTimeEditorDirective extends IgxMaskDirective implements OnIn
253261      let  targetValue : string  =  this . getMaskedValue ( p . type ,  partLength ) ; 
254262
255263      if  ( p . type  ===  DatePart . Month )  { 
256-         targetValue  =  this . prependPromptChars ( 
257-           parseInt ( targetValue . replace ( new  RegExp ( this . promptChar ,  'g' ) ,  '0' ) ,  10 )  +  1 ,  partLength ) ; 
264+         targetValue  =  this . prependValue ( 
265+           parseInt ( targetValue . replace ( new  RegExp ( this . promptChar ,  'g' ) ,  '0' ) ,  10 )  +  1 ,  partLength ,  '0' ) ; 
266+       } 
267+ 
268+       if  ( p . type  ===  DatePart . Hours  &&  p . format . indexOf ( 'h' )  !==  - 1 )  { 
269+         targetValue  =  this . prependValue ( this . toTwelveHourFormat ( targetValue ) ,  partLength ,  '0' ) ; 
270+       } 
271+ 
272+       if  ( p . type  ===  DatePart . Year  &&  p . format . length  ===  2 )  { 
273+         targetValue  =  this . prependValue ( parseInt ( targetValue . slice ( - 2 ) ,  10 ) ,  partLength ,  '0' ) ; 
258274      } 
259275
260276      this . inputValue  =  this . maskParser . replaceInMask ( this . inputValue ,  targetValue ,  this . maskOptions ,  p . start ,  p . end ) . value ; 
261277    } ) ; 
262278    this . setSelectionRange ( cursor ) ; 
263279  } 
264280
281+   private  toTwelveHourFormat ( value : string ) : number  { 
282+     let  hour  =  parseInt ( value . replace ( new  RegExp ( this . promptChar ,  'g' ) ,  '0' ) ,  10 ) ; 
283+     if  ( hour  >  12 )  { 
284+       hour  -=  12 ; 
285+     }  else  if  ( hour  ===  0 )  { 
286+       hour  =  12 ; 
287+     } 
288+ 
289+     return  hour ; 
290+   } 
291+ 
265292  private  getMaskedValue ( datePart : DatePart ,  partLength : number ) : string  { 
266293    let  maskedValue ; 
267294    switch  ( datePart )  { 
@@ -289,14 +316,14 @@ export class IgxDateTimeEditorDirective extends IgxMaskDirective implements OnIn
289316    } 
290317
291318    if  ( datePart  !==  DatePart . AmPm )  { 
292-       return  this . prependPromptChars ( maskedValue ,  partLength ) ; 
319+       return  this . prependValue ( maskedValue ,  partLength ,   '0' ) ; 
293320    } 
294321
295322    return  maskedValue ; 
296323  } 
297324
298-   private  prependPromptChars ( value : number ,  partLength : number ) : string  { 
299-     return  ( this . promptChar  +  value . toString ( ) ) . slice ( - partLength ) ; 
325+   private  prependValue ( value : number ,  partLength : number ,   prependChar :  string ) : string  { 
326+     return  ( prependChar  +  value . toString ( ) ) . slice ( - partLength ) ; 
300327  } 
301328
302329  private  spin ( event : KeyboardEvent ) : void   { 
0 commit comments