38 lines
1.2 KiB
Java
38 lines
1.2 KiB
Java
package com.nttdata.calender;
|
|
|
|
import java.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDateTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeParseException;
|
|
import java.util.TimeZone;
|
|
|
|
import com.bmc.arsys.api.Timestamp;
|
|
import com.nttdata.calender.errorhandling.ErrorTypes.ValidationError;
|
|
|
|
public class DateConverter {
|
|
|
|
final String DATEFORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
|
|
|
|
public LocalDate convertDateTime(String timestamp) throws ValidationError {
|
|
try {
|
|
LocalDate date = LocalDate.parse(timestamp, DateTimeFormatter.ofPattern(DATEFORMAT));
|
|
return date;
|
|
} catch (DateTimeParseException e) {
|
|
throw new ValidationError("Incorrect dateformat in request");
|
|
}
|
|
}
|
|
|
|
public Timestamp convertTimestamp(String timestamp) throws ValidationError {
|
|
SimpleDateFormat sdf = new SimpleDateFormat(DATEFORMAT);
|
|
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
|
try {
|
|
Timestamp ts = new Timestamp(sdf.parse(timestamp));
|
|
return ts;
|
|
} catch (ParseException e) {
|
|
throw new ValidationError("Incorrect dateformat in request");
|
|
}
|
|
}
|
|
}
|