Skip to content

Commit 414a62d

Browse files
committed
Ensure valid year is read from local storage (experiment search)
1 parent 4ae1837 commit 414a62d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/app/user/instance-new/instance-experiment-select.component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ export class InstanceExperimentSelectComponent implements OnInit {
118118
this.includeOpenData = true;
119119
}
120120

121+
// Ensure valid years read from localStorage
122+
const currentYear = new Date().getFullYear();
123+
121124
const localInstrumentId = localStorage.getItem(InstanceExperimentSelectComponent.USER_INSTANCE_EXPERIMENTS_INSTRUMENT_ID_KEY);
122125
const localFromYear = localStorage.getItem(InstanceExperimentSelectComponent.USER_INSTANCE_EXPERIMENTS_FROM_YEAR_KEY);
123126
const localToYear = localStorage.getItem(InstanceExperimentSelectComponent.USER_INSTANCE_EXPERIMENTS_TO_YEAR_KEY);
@@ -129,10 +132,10 @@ export class InstanceExperimentSelectComponent implements OnInit {
129132
this._instrumentId = +localInstrumentId;
130133
}
131134
if (localFromYear) {
132-
this._fromYear = +localFromYear;
135+
this._fromYear = Math.min(+localFromYear, currentYear);
133136
}
134137
if (localToYear) {
135-
this._toYear = +localToYear;
138+
this._toYear = Math.min(+localToYear, currentYear);
136139
}
137140
if (localIncludingOpenData) {
138141
this._includeOpenData = localIncludingOpenData === 'true';

0 commit comments

Comments
 (0)