| 9 | import static com.fiscalapi.models.invoicing.InvoiceConstants.SAT_DATE_FORMAT_IN; |
| 10 | |
| 11 | public class OptUtil { |
| 12 | public static LocalDateTime parseLocalDateTime(String stringDate) { |
| 13 | LocalDateTime parsedDate = null; |
| 14 | if (stringDate == null || stringDate.isEmpty()) { |
| 15 | return null; |
| 16 | } |
| 17 | |
| 18 | try { |
| 19 | if (stringDate.contains("T")) { |
| 20 | // Intenta primero parsearlo como LocalDateTime |
| 21 | parsedDate = LocalDateTime.parse(stringDate, SAT_DATE_FORMAT_IN); |
| 22 | } |
| 23 | else { |
| 24 | parsedDate = LocalDate.parse(stringDate).atStartOfDay(); |
| 25 | } |
| 26 | } catch (DateTimeParseException e) { |
| 27 | try { |
| 28 | // Si falla, intenta parsearlo como ZonedDateTime y convertirlo a LocalDateTime |
| 29 | ZonedDateTime zdt = ZonedDateTime.parse(stringDate); |
| 30 | parsedDate = zdt.toLocalDateTime(); |
| 31 | } catch (DateTimeParseException e2) { |
| 32 | throw new DateTimeParseException("Fecha en formato no reconocido: " + stringDate, stringDate, 0, e2); |
| 33 | } |
| 34 | } |
| 35 | return parsedDate; |
| 36 | } |
| 37 | } |
nothing calls this directly
no outgoing calls
no test coverage detected