Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
#465 Date display format in table
Browse files Browse the repository at this point in the history
  • Loading branch information
damianprzygodzki committed Mar 3, 2017
1 parent ce6aa77 commit ed52fad
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/components/table/TableCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,40 @@ class TableCell extends Component {
}
}

createDate = (field) => {
if(field){
let d = new Date(field);
let date = Moment(d).format('DD.MM.YYYY');
return date;
} else {
// specified case to avoid parsing "error" text
return '';
getDateFormat = (type) => {
switch(type) {
case 'DateTime':
return 'DD.MM.YYYY HH:mm:ss';
case 'Date':
return 'DD.MM.YYYY';
case 'Time':
return 'HH:mm:ss';
default:
return 'DD.MM.YYYY';
}
}

createDate = (field, type) => {
return field ?
Moment(new Date(field)).format(this.getDateFormat(type)) : '';
}

fieldToString = (field, type) => {
if(field === null){
return '';
}else{
switch(typeof field){
case 'object':
if(type === 'Date' || type === 'DateTime' || type === 'Time'){
return this.createDate(field);
return this.createDate(field, type);
} else {
return field[Object.keys(field)[0]];
}
case 'boolean':
return field ? <i className="meta-icon-checkbox-1" /> : <i className="meta-icon-checkbox" />;
case 'string':
if(type === 'Date' || type === 'DateTime' || type === 'Time'){
return this.createDate(field);
return this.createDate(field, type);
} else {
return field;
}
Expand Down

0 comments on commit ed52fad

Please sign in to comment.