Added field required field in call
This commit is contained in:
@@ -1,16 +1,29 @@
|
||||
package net.gepafin.tendermanagement.util;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Component
|
||||
public class DateTimeUtil {
|
||||
|
||||
|
||||
private static final Pattern TIME_PATTERN = Pattern.compile(
|
||||
"^((([01]?\\d|2[0-3]):([0-5]\\d)(:[0-5]\\d)?(\\s?[AP]M)?)|((0?[1-9]|1[0-2]):([0-5]\\d)(:[0-5]\\d)?\\s?[AP]M))$");
|
||||
|
||||
|
||||
public static LocalDateTime DateServerToUTC(LocalDateTime systemDate) {
|
||||
|
||||
@@ -50,4 +63,25 @@ public class DateTimeUtil {
|
||||
.from(localDateTime.atZone(ZoneId.systemDefault())
|
||||
.toInstant());
|
||||
}
|
||||
|
||||
public static LocalTime parseTime(String timeString) throws DateTimeParseException {
|
||||
DateTimeFormatter formatter;
|
||||
|
||||
if (!TIME_PATTERN.matcher(timeString).matches()) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST,"Invalid time format: " + timeString);
|
||||
}
|
||||
// Try to parse using default formats if no format is provided
|
||||
String[] defaultFormats = {"HH:mm:ss", "HH:mm", "HH:mm:ss a", "hh:mm a"};
|
||||
for (String defaultFormat : defaultFormats) {
|
||||
formatter = DateTimeFormatter.ofPattern(defaultFormat);
|
||||
try {
|
||||
return LocalTime.parse(timeString, formatter);
|
||||
} catch (DateTimeParseException e) {
|
||||
// Continue to the next format
|
||||
}
|
||||
}
|
||||
|
||||
// If all parsing attempts fail, throw an exception
|
||||
throw new CustomValidationException(Status.BAD_REQUEST,"Failed to parse time: " + timeString);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user