Skip to content
Snippets Groups Projects
Commit 63f629ac authored by esikkala's avatar esikkala
Browse files

Properly sort production dates

parent 42d5fed3
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,25 @@ const styles = () => ({ ...@@ -21,6 +21,25 @@ const styles = () => ({
const ResultTableCell = props => { const ResultTableCell = props => {
const ISOStringToDate = str => {
let year;
let month;
let day;
if (str.charAt(0) == '-') {
year = parseInt(str.substring(0,5));
month = parseInt(str.substring(7,8));
day = parseInt(str.substring(10,11));
} else {
year = parseInt(str.substring(0,4));
month = parseInt(str.substring(6,7));
day = parseInt(str.substring(9,10));
}
// console.log(year)
// console.log(month)
// console.log(day)
return new Date(year, month, day);
};
const stringListRenderer = cell => { const stringListRenderer = cell => {
if (cell == null || cell === '-'){ if (cell == null || cell === '-'){
return '-'; return '-';
...@@ -43,7 +62,14 @@ const ResultTableCell = props => { ...@@ -43,7 +62,14 @@ const ResultTableCell = props => {
} }
else if (Array.isArray(cell)) { else if (Array.isArray(cell)) {
if (props.columnId == 'productionTimespan') { if (props.columnId == 'productionTimespan') {
cell = sortValues ? sortBy(cell, obj => Number(obj.start)) : cell; cell = sortValues
? cell.sort((a,b) => {
a = ISOStringToDate(a.start);
b = ISOStringToDate(b.start);
// arrange from the most recent to the oldest
return a > b ? 1 : a < b ? -1 : 0;
})
: cell;
} else { } else {
cell = sortValues ? orderBy(cell, 'prefLabel') : cell; cell = sortValues ? orderBy(cell, 'prefLabel') : cell;
} }
......
...@@ -18,8 +18,8 @@ export const manuscriptProperties = ` ...@@ -18,8 +18,8 @@ export const manuscriptProperties = `
?production crm:P108_has_produced ?id . ?production crm:P108_has_produced ?id .
?production crm:P4_has_time-span ?productionTimespan . ?production crm:P4_has_time-span ?productionTimespan .
?productionTimespan skos:prefLabel ?productionTimespan__id . ?productionTimespan skos:prefLabel ?productionTimespan__id .
OPTIONAL { ?productionTimespan crm:P79_beginning_is_qualified_by ?productionTimespan__start } OPTIONAL { ?productionTimespan crm:P82a_begin_of_the_begin ?productionTimespan__start }
OPTIONAL { ?productionTimespan crm:P80_end_is_qualified_by ?productionTimespan__end } OPTIONAL { ?productionTimespan crm:P82b_end_of_the_end ?productionTimespan__end }
BIND (?productionTimespan__id AS ?productionTimespan__prefLabel) BIND (?productionTimespan__id AS ?productionTimespan__prefLabel)
} }
UNION UNION
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment