Skip to content
Snippets Groups Projects
Commit b9d17c0e authored by Florent Poittevin's avatar Florent Poittevin
Browse files

Fix date format offset iso 8601

parent 06442fe2
No related branches found
No related tags found
No related merge requests found
import * as moment from "moment";
export class DateUtil {
private static readonly ISO_8601_DATE: string = "YYYY-MM-DD";
private static readonly LOCAL_DATE_DATE_SIMPLE: string = "YYYY-MM-DD";
private static readonly OFFSET_DATE_TIME_DATE_ISO8601: string = "YYYY-MM-DDTHH:mm:ssZZ";
static convertToISO8601(date: Date | string): string {
static convertToLocalDateDateSimple(date: Date | string): string {
if (date === "") {
return null;
}
return moment(date).format(this.ISO_8601_DATE);
return moment(date).format(this.LOCAL_DATE_DATE_SIMPLE);
}
static convertToOffsetDateTimeIso8601(date: Date | string): string {
// expected format "2019-07-27T00:00:00+0200"
if (date === "") {
return null;
}
return moment(date).format(this.OFFSET_DATE_TIME_DATE_ISO8601);
}
}
......@@ -83,8 +83,9 @@ export class FormComponent extends AbstractFormComponent<DepositsModel> {
}
protected treatmentBeforeSubmit(deposit: DepositsModel): DepositsModel {
deposit.publicationDate = DateUtil.convertToISO8601(deposit.publicationDate);
// deposit.collectionBegin = DateUtil.convertToDateTime(deposit.collectionBegin);
deposit.publicationDate = DateUtil.convertToLocalDateDateSimple(deposit.publicationDate);
deposit.collectionBegin = DateUtil.convertToOffsetDateTimeIso8601(deposit.collectionBegin);
deposit.collectionEnd = DateUtil.convertToOffsetDateTimeIso8601(deposit.collectionEnd);
return deposit;
}
}
......
......@@ -33,11 +33,11 @@ export interface DepositsModel {
/**
* The beginning of the deposit collection
*/
collectionBegin?: Date;
collectionBegin?: string;
/**
* The end of the deposit collection
*/
collectionEnd?: Date;
collectionEnd?: string;
/**
* Size of AIP collection
*/
......
......@@ -66,8 +66,8 @@ export class FormComponent extends AbstractFormComponent<OrganizationalUnitsMode
}
protected treatmentBeforeSubmit(organizationalUnit: OrganizationalUnitsModel): OrganizationalUnitsModel {
organizationalUnit.openingDate = DateUtil.convertToISO8601(organizationalUnit.openingDate);
organizationalUnit.closingDate = DateUtil.convertToISO8601(organizationalUnit.closingDate);
organizationalUnit.openingDate = DateUtil.convertToLocalDateDateSimple(organizationalUnit.openingDate);
organizationalUnit.closingDate = DateUtil.convertToLocalDateDateSimple(organizationalUnit.closingDate);
return organizationalUnit;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment