[Library | Trunk]: Fix getDate function

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59197 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2020-07-30 09:31:15 +00:00
parent 79ffb5f6d0
commit fd7b774f73
3 changed files with 15 additions and 16 deletions

View File

@ -91,7 +91,7 @@ export class ResultLandingService {
if (data[0] != null) {
let date: string = (data[0].dateofacceptance ? data[0].dateofacceptance : '') + ''; // transform to string in case it is an integer
this.resultLandingInfo.date = (date && (date).indexOf('-') !== -1) ? date.split('-')[0] : date;
this.resultLandingInfo.dateofacceptance = data[0].dateofacceptance?new Date(data[0].dateofacceptance):null;
this.resultLandingInfo.dateofacceptance = data[0].dateofacceptance?Dates.getDate(data[0].dateofacceptance):null;
this.resultLandingInfo.publisher = data[0].publisher;
if(!Array.isArray(data[0].description)) {
//this.resultLandingInfo.description = String(data[0].description);
@ -100,7 +100,7 @@ export class ResultLandingService {
//this.resultLandingInfo.description = String(data[0].description[0]);
this.resultLandingInfo.description = (data[0] && data[0].description[0]) ? String(data[0].description[0]) : "";
}
this.resultLandingInfo.embargoEndDate = data[0].embargoenddate?Dates.getDateFromString(data[0].embargoenddate):null;
this.resultLandingInfo.embargoEndDate = data[0].embargoenddate?Dates.getDate(data[0].embargoenddate):null;
}
if(data[0]['bestaccessright'] && data[0]['bestaccessright'].hasOwnProperty("classname")) {

View File

@ -297,7 +297,7 @@ export class SearchResearchResultsService {
}
if(resData.embargoenddate && resData.embargoenddate != '') {
result.embargoEndDate = Dates.getDateFromString(resData.embargoenddate);
result.embargoEndDate = Dates.getDate(resData.embargoenddate);
}
if(!Array.isArray(resData.publisher)) {

View File

@ -86,6 +86,18 @@ export class Dates {
}
public static getDate(dateString: string): Date {
let date = new Date(dateString);
if (Object.prototype.toString.call(date) === "[object Date]") {
if (isNaN(date.getTime())) {
return null;
} else {
return date;
}
} else {
return null;
}
}
}
export class DOI {
@ -271,17 +283,4 @@ export class StringUtils {
}
return false;
}
public static getDateFromString(dateString: string): Date {
let date = new Date(dateString);
if (Object.prototype.toString.call(date) === "[object Date]") {
if (isNaN(date.getTime())) {
return null;
} else {
return date;
}
} else {
return null;
}
}
}