Merge pull request #1262 from tdonohue/date_fixes

Ensure we are always using UTC dates in the UI, as the backend expects/uses UTC-based dates
This commit is contained in:
Tim Donohue
2021-07-13 09:06:08 -05:00
committed by GitHub
6 changed files with 25 additions and 25 deletions

View File

@@ -107,6 +107,6 @@ describe('BrowseByDatePageComponent', () => {
}); });
it('should create a list of startsWith options with the current year first', () => { it('should create a list of startsWith options with the current year first', () => {
expect(comp.startsWithOptions[0]).toEqual(new Date().getFullYear()); expect(comp.startsWithOptions[0]).toEqual(new Date().getUTCFullYear());
}); });
}); });

View File

@@ -92,7 +92,7 @@ export class BrowseByDatePageComponent extends BrowseByMetadataPageComponent {
} }
} }
const options = []; const options = [];
const currentYear = new Date().getFullYear(); const currentYear = new Date().getUTCFullYear();
const oneYearBreak = Math.floor((currentYear - environment.browseBy.oneYearLimit) / 5) * 5; const oneYearBreak = Math.floor((currentYear - environment.browseBy.oneYearLimit) / 5) * 5;
const fiveYearBreak = Math.floor((currentYear - environment.browseBy.fiveYearLimit) / 10) * 10; const fiveYearBreak = Math.floor((currentYear - environment.browseBy.fiveYearLimit) / 10) * 10;
if (lowerLimit <= fiveYearBreak) { if (lowerLimit <= fiveYearBreak) {

View File

@@ -31,9 +31,9 @@ export function dateToISOFormat(date: Date | NgbDateStruct | string): string {
const dateObj: Date = (date instanceof Date) ? date : const dateObj: Date = (date instanceof Date) ? date :
((typeof date === 'string') ? ngbDateStructToDate(stringToNgbDateStruct(date)) : ngbDateStructToDate(date)); ((typeof date === 'string') ? ngbDateStructToDate(stringToNgbDateStruct(date)) : ngbDateStructToDate(date));
let year = dateObj.getFullYear().toString(); let year = dateObj.getUTCFullYear().toString();
let month = (dateObj.getMonth() + 1).toString(); let month = (dateObj.getUTCMonth() + 1).toString();
let day = dateObj.getDate().toString(); let day = dateObj.getUTCDate().toString();
let hour = dateObj.getHours().toString(); let hour = dateObj.getHours().toString();
let min = dateObj.getMinutes().toString(); let min = dateObj.getMinutes().toString();
let sec = dateObj.getSeconds().toString(); let sec = dateObj.getSeconds().toString();
@@ -57,7 +57,7 @@ export function dateToISOFormat(date: Date | NgbDateStruct | string): string {
* the Date object * the Date object
*/ */
export function ngbDateStructToDate(date: NgbDateStruct): Date { export function ngbDateStructToDate(date: NgbDateStruct): Date {
return new Date(date.year, (date.month - 1), date.day); return new Date(Date.UTC(date.year, (date.month - 1), date.day));
} }
/** /**
@@ -86,9 +86,9 @@ export function dateToNgbDateStruct(date?: Date): NgbDateStruct {
} }
return { return {
year: date.getFullYear(), year: date.getUTCFullYear(),
month: date.getMonth() + 1, month: date.getUTCMonth() + 1,
day: date.getDate() day: date.getUTCDate()
}; };
} }
@@ -103,9 +103,9 @@ export function dateToNgbDateStruct(date?: Date): NgbDateStruct {
export function dateToString(date: Date | NgbDateStruct): string { export function dateToString(date: Date | NgbDateStruct): string {
const dateObj: Date = (date instanceof Date) ? date : ngbDateStructToDate(date); const dateObj: Date = (date instanceof Date) ? date : ngbDateStructToDate(date);
let year = dateObj.getFullYear().toString(); let year = dateObj.getUTCFullYear().toString();
let month = (dateObj.getMonth() + 1).toString(); let month = (dateObj.getUTCMonth() + 1).toString();
let day = dateObj.getDate().toString(); let day = dateObj.getUTCDate().toString();
year = (year.length === 1) ? '0' + year : year; year = (year.length === 1) ? '0' + year : year;
month = (month.length === 1) ? '0' + month : month; month = (month.length === 1) ? '0' + month : month;

View File

@@ -57,9 +57,9 @@ export class DsDatePickerComponent extends DynamicFormControlComponent implement
ngOnInit() { ngOnInit() {
const now = new Date(); const now = new Date();
this.initialYear = now.getFullYear(); this.initialYear = now.getUTCFullYear();
this.initialMonth = now.getMonth() + 1; this.initialMonth = now.getUTCMonth() + 1;
this.initialDay = now.getDate(); this.initialDay = now.getUTCDate();
if (this.model && this.model.value !== null) { if (this.model && this.model.value !== null) {
const values = this.model.value.toString().split(DS_DATE_PICKER_SEPARATOR); const values = this.model.value.toString().split(DS_DATE_PICKER_SEPARATOR);

View File

@@ -56,7 +56,7 @@ export class SearchRangeFilterComponent extends SearchFacetFilterComponent imple
/** /**
* Fallback maximum for the range * Fallback maximum for the range
*/ */
max = new Date().getFullYear(); max = new Date().getUTCFullYear();
/** /**
* The current range of the filter * The current range of the filter

View File

@@ -244,9 +244,9 @@ export class SubmissionSectionUploadFileEditComponent implements OnChanges {
if (metadataModel.type === DYNAMIC_FORM_CONTROL_TYPE_DATEPICKER) { if (metadataModel.type === DYNAMIC_FORM_CONTROL_TYPE_DATEPICKER) {
const date = new Date(accessCondition[key]); const date = new Date(accessCondition[key]);
metadataModel.value = { metadataModel.value = {
year: date.getFullYear(), year: date.getUTCFullYear(),
month: date.getMonth() + 1, month: date.getUTCMonth() + 1,
day: date.getDate() day: date.getUTCDate()
}; };
} else { } else {
metadataModel.value = accessCondition[key]; metadataModel.value = accessCondition[key];
@@ -302,9 +302,9 @@ export class SubmissionSectionUploadFileEditComponent implements OnChanges {
const min = new Date(accessCondition.maxStartDate); const min = new Date(accessCondition.maxStartDate);
startDateModel.max = { startDateModel.max = {
year: min.getFullYear(), year: min.getUTCFullYear(),
month: min.getMonth() + 1, month: min.getUTCMonth() + 1,
day: min.getDate() day: min.getUTCDate()
}; };
} }
if (accessCondition.hasEndDate) { if (accessCondition.hasEndDate) {
@@ -314,9 +314,9 @@ export class SubmissionSectionUploadFileEditComponent implements OnChanges {
const max = new Date(accessCondition.maxEndDate); const max = new Date(accessCondition.maxEndDate);
endDateModel.max = { endDateModel.max = {
year: max.getFullYear(), year: max.getUTCFullYear(),
month: max.getMonth() + 1, month: max.getUTCMonth() + 1,
day: max.getDate() day: max.getUTCDate()
}; };
} }
} }