Search in sources :

Example 1 with DateFormat

use of uk.nhs.adaptors.oneoneone.cda.report.enums.DateFormat in project integration-adaptor-111 by nhsconnect.

the class DateUtil method parse.

public static DateTimeType parse(String dateToParse) {
    DateFormat format = getFormat(dateToParse);
    SimpleDateFormat formatter = getFormatter(format);
    try {
        Date date = formatter.parse(dateToParse);
        return new DateTimeType(date, format.getPrecision(), TimeZone.getTimeZone(ZoneOffset.UTC));
    } catch (ParseException e) {
        throw new IllegalStateException(String.format(ERROR_MESSAGE, dateToParse), e);
    }
}
Also used : DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(uk.nhs.adaptors.oneoneone.cda.report.enums.DateFormat) DateTimeParseException(java.time.format.DateTimeParseException) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 2 with DateFormat

use of uk.nhs.adaptors.oneoneone.cda.report.enums.DateFormat in project integration-adaptor-111 by nhsconnect.

the class DateUtil method parseToInstantType.

public static InstantType parseToInstantType(String dateToParse) {
    DateFormat format = getFormat(dateToParse);
    SimpleDateFormat formatter = getFormatter(format);
    try {
        Date date = formatter.parse(dateToParse);
        return new InstantType(date, TemporalPrecisionEnum.MILLI, TimeZone.getTimeZone(ZoneOffset.UTC));
    } catch (ParseException e) {
        throw new IllegalStateException(String.format(ERROR_MESSAGE, dateToParse), e);
    }
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(uk.nhs.adaptors.oneoneone.cda.report.enums.DateFormat) DateTimeParseException(java.time.format.DateTimeParseException) ParseException(java.text.ParseException) InstantType(org.hl7.fhir.dstu3.model.InstantType) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 DateTimeParseException (java.time.format.DateTimeParseException)2 Date (java.util.Date)2 DateFormat (uk.nhs.adaptors.oneoneone.cda.report.enums.DateFormat)2 DateTimeType (org.hl7.fhir.dstu3.model.DateTimeType)1 InstantType (org.hl7.fhir.dstu3.model.InstantType)1