diff --git a/src/app/pages/data-management/edit-record/edit-record.component.ts b/src/app/pages/data-management/edit-record/edit-record.component.ts index bbb1f45..12cec82 100644 --- a/src/app/pages/data-management/edit-record/edit-record.component.ts +++ b/src/app/pages/data-management/edit-record/edit-record.component.ts @@ -11,7 +11,7 @@ import * as moment from 'moment/moment'; import { APIError, Project, Dataset, Record, RecordMedia } from '../../../../biosys-core/interfaces/api.interfaces'; import { APIService } from '../../../../biosys-core/services/api.service'; -import { pyDateFormatToMomentDateFormat } from '../../../../biosys-core/utils/functions'; +import { pyDateFormatToMomentDateFormat, findDateTimeFormat} from '../../../../biosys-core/utils/functions'; import { AMBIGUOUS_DATE_PATTERN } from '../../../../biosys-core/utils/consts'; import { getDefaultValue } from '../../../shared/utils/functions'; import { getExtentFromPoint } from '../../../shared/utils/maputils'; @@ -177,6 +177,11 @@ export class EditRecordComponent implements OnInit { if (field.type === 'date' && recordCopy.data[field.name]) { recordCopy.data[field.name] = moment(recordCopy.data[field.name]).format(pyDateFormatToMomentDateFormat(field.format)); } + if (field.type === 'datetime' && recordCopy.data[field.name]) { + // Make sure the datetime field stays a datetime field when we save + // It'll accept DD/MM/YYYY or YYYY-MM-DDTHH:mm:ss + recordCopy.data[field.name] = moment(recordCopy.data[field.name], findDateTimeFormat(field.format)).format(); + } } if ('id' in recordCopy) { diff --git a/src/app/shared/edit-records-table/edit-records-table.component.ts b/src/app/shared/edit-records-table/edit-records-table.component.ts index 1153296..42a4779 100644 --- a/src/app/shared/edit-records-table/edit-records-table.component.ts +++ b/src/app/shared/edit-records-table/edit-records-table.component.ts @@ -7,7 +7,7 @@ import { Table } from 'primeng/table'; import * as moment from 'moment/moment'; import { APIError, Dataset, Record, RecordResponse, User } from '../../../biosys-core/interfaces/api.interfaces'; -import { pyDateFormatToMomentDateFormat } from '../../../biosys-core/utils/functions'; +import {findDateTimeFormat, pyDateFormatToMomentDateFormat} from '../../../biosys-core/utils/functions'; import { APIService } from '../../../biosys-core/services/api.service'; import { AuthService } from '../../../biosys-core/services/auth.service'; import { AMBIGUOUS_DATE_PATTERN } from '../../../biosys-core/utils/consts'; @@ -186,9 +186,14 @@ export class EditRecordsTableComponent { // convert Date types back to string in field's specified format (or DD/MM/YYYY if unspecified) for (const field of this._dataset.data_package.resources[0].schema.fields) { - if ((field.type === 'date' || field.type === 'datetime') && data[field.name]) { + if ((field.type === 'date') && data[field.name]) { data[field.name] = moment(data[field.name]).format(pyDateFormatToMomentDateFormat(field.format)); } + if (field.type === 'datetime' && data[field.name]) { + // Make sure the datetime field stays a datetime field when we save + // It'll accept DD/MM/YYYY or YYYY-MM-DDTHH:mm:ss + data[field.name] = moment(data[field.name], findDateTimeFormat(field.format)).format(); + } } this.apiService.updateRecordDataField(id, data, true).subscribe(