Skip to content

Commit

Permalink
Fixed #1231
Browse files Browse the repository at this point in the history
  • Loading branch information
Çağatay Çivici committed Nov 8, 2016
1 parent 5a42aca commit ecd3b04
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions components/calendar/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,25 +670,7 @@ export class Calendar implements AfterViewInit,OnInit,OnDestroy,ControlValueAcce

onInput(event) {
try {
let rawValue = event.target.value;
let parsedValue;
let parts: string[] = rawValue.split(' ');

if(this.timeOnly) {
parsedValue = new Date();
this.populateTime(parsedValue, parts[0], parts[1]);
}
else {
if(this.showTime) {
parsedValue = this.parseDate(parts[0], this.dateFormat);
this.populateTime(parsedValue, parts[1], parts[2]);
}
else {
parsedValue = this.parseDate(event.target.value, this.dateFormat);
}
}

this.value = parsedValue;
this.value = this.parseValueFromString(event.target.value);
this.updateUI();
}
catch(err) {
Expand All @@ -699,6 +681,27 @@ export class Calendar implements AfterViewInit,OnInit,OnDestroy,ControlValueAcce
this.updateModel();
}

parseValueFromString(text: string): Date {
let dateValue;
let parts: string[] = text.split(' ');

if(this.timeOnly) {
dateValue = new Date();
this.populateTime(dateValue, parts[0], parts[1]);
}
else {
if(this.showTime) {
dateValue = this.parseDate(parts[0], this.dateFormat);
this.populateTime(dateValue, parts[1], parts[2]);
}
else {
dateValue = this.parseDate(text, this.dateFormat);
}
}

return dateValue;
}

populateTime(value, timeString, ampm) {
let time = this.parseTime(timeString);

Expand Down Expand Up @@ -741,6 +744,9 @@ export class Calendar implements AfterViewInit,OnInit,OnDestroy,ControlValueAcce

writeValue(value: any) : void {
this.value = value;
if(this.value && typeof this.value === 'string') {
this.value = this.parseValueFromString(this.value);
}

this.updateInputfield();
this.updateUI();
Expand Down

0 comments on commit ecd3b04

Please sign in to comment.