mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 07:23:03 +00:00
Merge pull request #1535 from 4Science/CST-5316-browse-by-issue-date
[CST-5316] "Browsing by issue date" is stuck on loading
This commit is contained in:
@@ -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,10 +86,10 @@ export class BrowseByDatePageComponent extends BrowseByMetadataPageComponent {
|
||||
let lowerLimit = environment.browseBy.defaultLowerLimit;
|
||||
if (hasValue(firstItemRD.payload)) {
|
||||
const date = firstItemRD.payload.firstMetadataValue(metadataKeys);
|
||||
if (hasValue(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 = dateObj.getUTCFullYear();
|
||||
lowerLimit = isNaN(dateObj.getUTCFullYear()) ? lowerLimit : dateObj.getUTCFullYear();
|
||||
}
|
||||
}
|
||||
const options = [];
|
||||
|
@@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user