diff --git a/src/app/pages/oaipmh-validator/validation-analysis/oaipmh-analysis.component.ts b/src/app/pages/oaipmh-validator/validation-analysis/oaipmh-analysis.component.ts index 8231891..04f8aa5 100644 --- a/src/app/pages/oaipmh-validator/validation-analysis/oaipmh-analysis.component.ts +++ b/src/app/pages/oaipmh-validator/validation-analysis/oaipmh-analysis.component.ts @@ -162,14 +162,15 @@ export class OaipmhAnalysisComponent implements OnInit { this.jobResult = result; let startDate = new Date(this.jobResult.startDate); let endDate = this.jobResult.endDate ? new Date(this.jobResult.endDate) : new Date(); + this.jobDuration = new Duration(); - this.jobDuration.years = endDate.getFullYear() - startDate.getFullYear(); - this.jobDuration.months = endDate.getMonth() - startDate.getMonth(); - this.jobDuration.days = endDate.getDate() - startDate.getDate(); - this.jobDuration.hours = endDate.getHours() - startDate.getHours(); - this.jobDuration.minutes = endDate.getMinutes() - startDate.getMinutes(); - this.jobDuration.seconds = endDate.getSeconds() - startDate.getSeconds(); - console.log(this.jobDuration); + const msBetweenDates = endDate.getTime() - startDate.getTime(); + this.jobDuration.seconds = Math.ceil(msBetweenDates / 1000 % 60); + this.jobDuration.minutes = Math.floor(msBetweenDates / 1000 / 60 % 60); + this.jobDuration.hours = Math.floor(msBetweenDates / 1000 / 60 / 60 % 24); + this.jobDuration.days = Math.floor(msBetweenDates / 1000 / 60 / 60 / 24); + this.jobDuration.months = Math.floor(this.jobDuration.days / 31); + this.jobDuration.years = Math.floor(this.jobDuration.months / 12); } ); }