MCPcopy Create free account
hub / github.com/FiscalAPI/fiscalapi-java / OptUtil

Class OptUtil

src/main/java/com/fiscalapi/OptUtil.java:11–37  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9import static com.fiscalapi.models.invoicing.InvoiceConstants.SAT_DATE_FORMAT_IN;
10
11public 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected