From 702a59c0fa6587fa18494a192c63a0a089ae1ae6 Mon Sep 17 00:00:00 2001 From: Johnathan Aspinwall Date: Tue, 2 Jul 2024 08:56:49 -0600 Subject: [PATCH 1/2] chore: Bump version to 1.5.0-beta.28 in package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ee7ea3005..d99171d7a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mdeditor", - "version": "1.5.0-beta.27", + "version": "1.5.0-beta.28", "description": "A web application for authoring and editing metadata.", "repository": { "type": "git", From 65fe1ead5430cd5e5a330d85a686744f246f2726 Mon Sep 17 00:00:00 2001 From: Johnathan Aspinwall Date: Tue, 2 Jul 2024 08:57:23 -0600 Subject: [PATCH 2/2] fix: Date time behavior issues fixed when selecting precision. --- .../input/md-date-range/component.js | 57 +++++++------- .../components/object/md-date/component.js | 46 ++++++------ .../components/object/md-date/template.hbs | 74 ++++++------------- 3 files changed, 70 insertions(+), 107 deletions(-) diff --git a/app/pods/components/input/md-date-range/component.js b/app/pods/components/input/md-date-range/component.js index cf6391256..bf8205694 100644 --- a/app/pods/components/input/md-date-range/component.js +++ b/app/pods/components/input/md-date-range/component.js @@ -6,10 +6,13 @@ import { notEmpty, alias } from '@ember/object/computed'; import Component from '@ember/component'; -import { set, get, computed } from '@ember/object'; +import { set, computed } from '@ember/object'; import { observer } from '@ember/object'; import { once } from '@ember/runloop'; import dayjs from 'dayjs'; +import utc from 'dayjs/plugin/utc'; + +dayjs.extend(utc); import { validator, buildValidations } from 'ember-cp-validations'; @@ -54,37 +57,30 @@ export default Component.extend(Validations, { selectedPrecisionChanged: observer('selectedPrecision', function () { const startDate = this.start; const endDate = this.end; - if (!startDate || !endDate) return; - - const parsedStartDate = dayjs(startDate); - const parsedEndDate = dayjs(endDate); let newStartDate, newEndDate; switch (this.selectedPrecision) { - case 'Time': - newStartDate = parsedStartDate.format('YYYY-MM-DD HH:mm:ss'); - newEndDate = parsedEndDate.format('YYYY-MM-DD HH:mm:ss'); - this.set('selectedFormat', 'YYYY-MM-DDTHH:mm:ssZ'); - break; - case 'Day': - newStartDate = parsedStartDate.format('YYYY-MM-DD'); - newEndDate = parsedEndDate.format('YYYY-MM-DD'); - this.set('selectedFormat', 'YYYY-MM-DD'); + case 'Year': + this.set('selectedFormat', 'YYYY'); + if (startDate) newStartDate = dayjs(startDate).format('YYYY'); + if (endDate) newEndDate = dayjs(endDate).format('YYYY'); break; case 'Month': - newStartDate = parsedStartDate.format('YYYY-MM'); - newEndDate = parsedEndDate.format('YYYY-MM'); this.set('selectedFormat', 'YYYY-MM'); + if (startDate) newStartDate = dayjs(startDate).format('YYYY-MM'); + if (endDate) newEndDate = dayjs(endDate).format('YYYY-MM'); break; - case 'Year': - newStartDate = parsedStartDate.format('YYYY'); - newEndDate = parsedEndDate.format('YYYY'); - this.set('selectedFormat', 'YYYY'); + case 'Day': + this.set('selectedFormat', 'YYYY-MM-DD'); + if (startDate) newStartDate = dayjs(startDate).format('YYYY-MM-DD'); + if (endDate) newEndDate = dayjs(endDate).format('YYYY-MM-DD'); break; + case 'Time': default: - newStartDate = parsedStartDate.format('YYYY-MM-DD HH:mm:ss'); - newEndDate = parsedEndDate.format('YYYY-MM-DD HH:mm:ss'); this.set('selectedFormat', 'YYYY-MM-DDTHH:mm:ssZ'); + if (startDate) + newStartDate = dayjs(startDate).format('YYYY-MM-DDTHH:mm:ssZ'); + if (endDate) newEndDate = dayjs(endDate).format('YYYY-MM-DDTHH:mm:ssZ'); break; } @@ -103,18 +99,15 @@ export default Component.extend(Validations, { this.set('selectedFormat', 'YYYY'); return; } - if (/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(date)) { - this.set('selectedPrecision', 'Time'); - this.set('selectedFormat', 'YYYY-MM-DDTHH:mm:ssZ'); - } else if (/\d{4}-\d{2}-\d{2}/.test(date)) { - this.set('selectedPrecision', 'Day'); - this.set('selectedFormat', 'YYYY-MM-DD'); - } else if (/\d{4}-\d{2}/.test(date)) { - this.set('selectedPrecision', 'Month'); - this.set('selectedFormat', 'YYYY-MM'); - } else if (/\d{4}/.test(date)) { + if (/^\d{4}$/.test(date)) { this.set('selectedPrecision', 'Year'); this.set('selectedFormat', 'YYYY'); + } else if (/^\d{4}-\d{2}$/.test(date)) { + this.set('selectedPrecision', 'Month'); + this.set('selectedFormat', 'YYYY-MM'); + } else if (/^\d{4}-\d{2}-\d{2}$/.test(date)) { + this.set('selectedPrecision', 'Day'); + this.set('selectedFormat', 'YYYY-MM-DD'); } else { this.set('selectedPrecision', 'Time'); this.set('selectedFormat', 'YYYY-MM-DDTHH:mm:ssZ'); diff --git a/app/pods/components/object/md-date/component.js b/app/pods/components/object/md-date/component.js index 473989719..5e7147c98 100644 --- a/app/pods/components/object/md-date/component.js +++ b/app/pods/components/object/md-date/component.js @@ -30,37 +30,37 @@ export default Component.extend(Validations, { }, selectedPrecision: null, + selectedFormat: 'YYYY-MM-DDTHH:mm:ssZ', tagName: '', date: alias('model.date'), dateType: alias('model.dateType'), selectedPrecisionChanged: observer('selectedPrecision', function () { - const date = this.get('model.date'); - if (!date) return; - - const parsedDate = dayjs(date); + const dateObj = this.get('model.date'); let newDate; - switch (this.get('selectedPrecision')) { - case 'Time': - newDate = parsedDate.format('YYYY-MM-DD HH:mm:ss'); - break; - case 'Day': - newDate = parsedDate.format('YYYY-MM-DD'); + switch (this.selectedPrecision) { + case 'Year': + this.set('selectedFormat', 'YYYY'); + if (dateObj) newDate = dayjs(dateObj).format('YYYY'); break; case 'Month': - newDate = parsedDate.format('YYYY-MM'); + this.set('selectedFormat', 'YYYY-MM'); + if (dateObj) newDate = dayjs(dateObj).format('YYYY-MM'); break; - case 'Year': - newDate = parsedDate.format('YYYY'); + case 'Day': + this.set('selectedFormat', 'YYYY-MM-DD'); + if (dateObj) newDate = dayjs(dateObj).format('YYYY-MM-DD'); break; + case 'Time': default: - newDate = parsedDate.format('YYYY-MM-DD HH:mm:ss'); + this.set('selectedFormat', 'YYYY-MM-DDTHH:mm:ssZ'); + if (dateObj) newDate = dayjs(dateObj).format('YYYY-MM-DDTHH:mm:ssZ'); break; } - if (newDate !== date) { + if (newDate !== dateObj) { this.set('model.date', newDate); } }), @@ -71,16 +71,18 @@ export default Component.extend(Validations, { this.set('selectedPrecision', 'Year'); return; } - if (/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(date)) { - this.set('selectedPrecision', 'Time'); - } else if (/\d{4}-\d{2}-\d{2}/.test(date)) { - this.set('selectedPrecision', 'Day'); - } else if (/\d{4}-\d{2}/.test(date)) { - this.set('selectedPrecision', 'Month'); - } else if (/\d{4}/.test(date)) { + if (/^\d{4}$/.test(date)) { this.set('selectedPrecision', 'Year'); + this.set('selectedFormat', 'YYYY'); + } else if (/^\d{4}-\d{2}$/.test(date)) { + this.set('selectedPrecision', 'Month'); + this.set('selectedFormat', 'YYYY-MM'); + } else if (/^\d{4}-\d{2}-\d{2}$/.test(date)) { + this.set('selectedPrecision', 'Day'); + this.set('selectedFormat', 'YYYY-MM-DD'); } else { this.set('selectedPrecision', 'Time'); + this.set('selectedFormat', 'YYYY-MM-DDTHH:mm:ssZ'); } }, }); diff --git a/app/pods/components/object/md-date/template.hbs b/app/pods/components/object/md-date/template.hbs index 9e3ed9cb7..4274c3402 100644 --- a/app/pods/components/object/md-date/template.hbs +++ b/app/pods/components/object/md-date/template.hbs @@ -1,59 +1,27 @@ {{input/md-select showValidations=true - valuePath="value" - namePath="name" + valuePath='value' + namePath='name' model=this - path="selectedPrecision" + path='selectedPrecision' objectArray=precisionOptions searchEnabled=false - placeholder="Date Precision" + placeholder='Date Precision' }} - {{#if (eq selectedPrecision "Time")}} - {{input/md-datetime - valuePath="date" - model=this - showValidations=true - required=true - forceDateOutput=true - profilePath=(concat profilePath ".date") - }} - {{else if (eq selectedPrecision "Day")}} - {{input/md-datetime - valuePath="date" - model=this - showValidations=true - required=true - forceDateOutput=true - format="YYYY-MM-DD" - placeholder="Enter date" - profilePath=(concat profilePath ".date") - }} - {{else if (eq selectedPrecision "Month")}} - {{input/md-datetime - valuePath="date" - model=this - showValidations=true - required=true - forceDateOutput=true - format="YYYY-MM" - placeholder="Enter Year/Month" - profilePath=(concat profilePath ".date") - }} - {{else if (eq selectedPrecision "Year")}} - {{input/md-datetime - valuePath="date" - model=this - showValidations=true - required=true - forceDateOutput=true - format="YYYY" - placeholder="Enter Year" - profilePath=(concat profilePath ".date") - }} - {{/if}} + {{input/md-datetime + valuePath='date' + model=this + showValidations=true + forceDateOutput=true + showClear=true + format=selectedFormat + placeholder='Enter date' + profilePath=(concat profilePath '.date') + required=true + }} {{input/md-codelist @@ -64,18 +32,18 @@ disabled=disabled allowClear=true showValidations=true - mdCodeName="dateType" - profilePath=(concat profilePath ".dateType") - path="dateType" + mdCodeName='dateType' + profilePath=(concat profilePath '.dateType') + path='dateType' model=this - placeholder="Choose date type" + placeholder='Choose date type' }} {{input/md-input value=model.description - profilePath=(concat profilePath ".description") - placeholder="Describe the date." + profilePath=(concat profilePath '.description') + placeholder='Describe the date.' }} {{yield}} \ No newline at end of file