Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISK-16] Record edit datetime field format #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
Expand Down