[CST-5316] Wrong 'dc.date.issue' format causes loader to be shown indefinitely in "Browsing by issue date" page

This commit is contained in:
Davide Negretti
2022-02-21 19:30:34 +01:00
parent 0bbd505083
commit 0b13ea1a72
2 changed files with 10 additions and 1 deletions

View File

@@ -18,6 +18,7 @@ import { PaginationService } from '../../core/pagination/pagination.service';
import { map } from 'rxjs/operators';
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model';
import { isValidDate } from '../../shared/date.util';
@Component({
selector: 'ds-browse-by-date-page',
@@ -85,7 +86,7 @@ export class BrowseByDatePageComponent extends BrowseByMetadataPageComponent {
let lowerLimit = environment.browseBy.defaultLowerLimit;
if (hasValue(firstItemRD.payload)) {
const date = firstItemRD.payload.firstMetadataValue(metadataKeys);
if (isNotEmpty(new Date(date))) {
if (isNotEmpty(date) && isValidDate(date)) {
const dateObj = new Date(date);
// TODO: it appears that getFullYear (based on local time) is sometimes unreliable. Switching to UTC.
lowerLimit = isNaN(dateObj.getUTCFullYear()) ? lowerLimit : dateObj.getUTCFullYear();

View File

@@ -113,3 +113,11 @@ export function dateToString(date: Date | NgbDateStruct): string {
const dateStr = `${year}-${month}-${day}`;
return moment.utc(dateStr, 'YYYYMMDD').format('YYYY-MM-DD');
}
/**
* Checks if the given string represents a valid date
* @param date the string to be checked
*/
export function isValidDate(date: string) {
return moment(date).isValid();
}