From: Jane Sandberg Date: Thu, 21 Jul 2022 00:00:24 +0000 (-0400) Subject: LP1879517: Surveys shouldn't end before they begin X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=9cbb6a9f645c6edb2debad41e5133575b4af0319;p=Evergreen.git LP1879517: Surveys shouldn't end before they begin To test: 1. Go to Admin > Local > Surveys. 2. Create a new survey. 3. Attempt to create a survey where the end date comes before the start date. Without this patch, you will get no notice that this is invalid, and you can save the invalid record. 4. Edit an existing survey. 5. Repeat step 3 while editing the existing survey. 6. Apply the patch. 7. Repeat steps 1-5. Note that you now get a notice and cannot save if the end date is before the start date. This commit generalizes a validator already present in the booking module, and corrects several small bugs related to the datetime-select component. Signed-off-by: Jane Sandberg Signed-off-by: Susan Morrison Signed-off-by: Jason Boyer --- diff --git a/Open-ILS/src/eg2/src/app/core/format.service.ts b/Open-ILS/src/eg2/src/app/core/format.service.ts index 9622bd0681..26b6973725 100644 --- a/Open-ILS/src/eg2/src/app/core/format.service.ts +++ b/Open-ILS/src/eg2/src/app/core/format.service.ts @@ -167,7 +167,7 @@ export class FormatService { * Create a Moment from an ISO string */ momentizeIsoString(isoString: string, timezone: string): moment.Moment { - return (isoString.length) ? moment(isoString, timezone) : moment(); + return (isoString?.length) ? moment(isoString).tz(timezone) : moment(); } /** diff --git a/Open-ILS/src/eg2/src/app/core/format.spec.ts b/Open-ILS/src/eg2/src/app/core/format.spec.ts index 10deaf78a8..1c486125e3 100644 --- a/Open-ILS/src/eg2/src/app/core/format.spec.ts +++ b/Open-ILS/src/eg2/src/app/core/format.spec.ts @@ -142,6 +142,11 @@ describe('FormatService', () => { const moment = service.momentizeDateTimeString('7/3/12, 6:06 PM', 'Africa/Addis_Ababa', false, 'fr-CA'); expect(moment.isValid()).toBe(true); }); + it('can momentize ISO strings', () => { + const moment = service.momentizeIsoString('2022-07-29T17:56:00.000Z', 'America/New_York'); + expect(moment.isValid()).toBe(true); + expect(moment.format('YYYY')).toBe('2022'); + }); }); diff --git a/Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.spec.ts b/Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.spec.ts new file mode 100644 index 0000000000..b049dbd332 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.spec.ts @@ -0,0 +1,20 @@ +import * as moment from "moment"; +import { DateTimeSelectComponent } from "./datetime-select.component"; + + +describe('DateTimeSelectComponent', () => { + const mockFormatService = jasmine.createSpyObj('FormatService', ['transform', 'momentizeIsoString']); + mockFormatService.momentizeIsoString.and.returnValue(moment('2020-12-11T01:30:05.606Z').tz('America/Vancouver')); + const mockDateTimeValidator = jasmine.createSpyObj('DateTimeValidator', ['']); + const mockNgControl = jasmine.createSpyObj('ngControl', ['']); + const component = new DateTimeSelectComponent(mockFormatService, mockDateTimeValidator, mockNgControl); + + it('accepts an initialIso input and converts it to the correct timezone', () => { + component.initialIso = '2020-12-11T01:30:05.606Z'; + component.timezone = 'America/Vancouver'; + component.ngOnInit(); + expect(component.date.value).toEqual({year: 2020, month: 12, day: 10}); + expect(component.time.value).toEqual({hour: 17, minute: 30, second: 0}); + }); + +}); diff --git a/Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.ts b/Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.ts index ed20e841a4..5619d204a9 100644 --- a/Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.ts +++ b/Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.ts @@ -1,7 +1,6 @@ -import {Component, EventEmitter, Input, Output, forwardRef, ViewChild, OnInit, Optional, Self} from '@angular/core'; +import {Component, EventEmitter, Input, Output, ViewChild, OnInit, Optional, Self} from '@angular/core'; import {FormatService} from '@eg/core/format.service'; import {AbstractControl, ControlValueAccessor, FormControl, FormGroup, NgControl} from '@angular/forms'; -import {NgbDatepicker, NgbTimeStruct, NgbDateStruct} from '@ng-bootstrap/ng-bootstrap'; import {DatetimeValidator} from '@eg/share/validators/datetime_validator.directive'; import * as moment from 'moment-timezone'; @@ -122,7 +121,14 @@ export class DateTimeSelectComponent implements OnInit, ControlValueAccessor { } - writeValue(value: moment.Moment) { + writeValue(value: moment.Moment|string) { + if (typeof value === 'string') { + if (value.length === 0) { + return; + }; + value = this.format.momentizeIsoString(value, this.timezone); + } + if (value !== undefined && value !== null) { this.dateTimeForm.patchValue({ stringVersion: this.format.transform({value: value, datatype: 'timestamp', datePlusTime: true})}); diff --git a/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.html b/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.html index 3096173a77..5d4dba9e50 100644 --- a/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.html +++ b/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.html @@ -13,20 +13,27 @@