From 23a46b4be35277e06ec89f48730eeb694e686be8 Mon Sep 17 00:00:00 2001
From: Kenmegne <stephanie.kenmegne@gmail.com>
Date: Thu, 18 Jun 2026 15:40:06 +0000
Subject: [PATCH] add fdx-commons and fdx-consultation
---
fdx-commons/fdxcommons-tools/src/main/java/com/megatim/fdxcommons/tools/database/queries/metadata/InsertionLocalDateTimeValue.java | 88 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 88 insertions(+), 0 deletions(-)
diff --git a/fdx-commons/fdxcommons-tools/src/main/java/com/megatim/fdxcommons/tools/database/queries/metadata/InsertionLocalDateTimeValue.java b/fdx-commons/fdxcommons-tools/src/main/java/com/megatim/fdxcommons/tools/database/queries/metadata/InsertionLocalDateTimeValue.java
new file mode 100644
index 0000000..a6b4c11
--- /dev/null
+++ b/fdx-commons/fdxcommons-tools/src/main/java/com/megatim/fdxcommons/tools/database/queries/metadata/InsertionLocalDateTimeValue.java
@@ -0,0 +1,88 @@
+package com.megatim.fdxcommons.tools.database.queries.metadata;
+
+import com.megatim.fdxcommons.tools.database.exceptions.LocalDateTimeValueParseError;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeParseException;
+
+/**
+ *
+ * @author ASUS
+ */
+public class InsertionLocalDateTimeValue {
+
+ private final String format;
+ private final Object value;
+
+ public InsertionLocalDateTimeValue(String format, Object value) {
+ this.format = format;
+ this.value = value;
+ }
+
+ public LocalDateTime value() throws LocalDateTimeValueParseError {
+ final String stringValue = value.toString().trim();
+
+ try {
+
+ if (format.length() == 4 && format.equals("yyyy") && stringValue.matches("\\d{4}")) {
+ return LocalDateTime.of(Integer.parseInt(stringValue), 1, 1, 0, 0, 0);
+
+ } else if ((format.length() == 6 && stringValue.length() == 6) || (format.length() == 7) && stringValue.length() == 7) {
+
+ int monthIndex = index(format, "MM");
+ int yearIndex = index(format, "yyyy");
+
+ return date(yearIndex, monthIndex, stringValue);
+
+ } else if ((format.length() == 8 && stringValue.length() == 8)
+ || (format.length() == 10 && stringValue.length() == 10)) {
+
+ int dayIndex = index(format, "dd");
+ int monthIndex = index(format, "MM");
+ int yearIndex = index(format, "yyyy");
+
+ return date(yearIndex, monthIndex, dayIndex, stringValue);
+ }
+
+ } catch (DateTimeParseException e) {
+ throw new LocalDateTimeValueParseError("Impossible de parser la valeur " + value + " au format " + format);
+ }
+
+ throw new LocalDateTimeValueParseError("Impossible de parser la valeur " + value + " au format " + format);
+ }
+
+ private int index(String format, String subSequence) {
+ return format.indexOf(subSequence);
+ }
+ private LocalDateTime date(int yearIndex, int monthIdex, int dayIndex, String stringValue) throws LocalDateTimeValueParseError {
+
+ if (yearIndex >= 0 && monthIdex >= 0 && dayIndex >= 0) {
+ int annee = Integer.parseInt(stringValue.substring(yearIndex, yearIndex + 4));
+ int mois = Integer.parseInt(stringValue.substring(monthIdex, monthIdex + 2));
+ int jour = Integer.parseInt(stringValue.substring(dayIndex, dayIndex + 2));
+
+ if (mois >= 1 && mois <= 12 && jour >= 1 && jour <= 31) {
+ if ((mois == 1 || mois == 3 || mois == 5 || mois == 7 || mois == 8 || mois == 10 || mois == 12) && jour <= 31//Les mois ayant 31 jours
+ || ((mois == 4 || mois == 6 || mois == 9 || mois == 11) && jour <= 30)//les ayant 30 jours
+ || (mois == 2 && (annee % 4 == 0 && jour <= 29 || jour <= 28))) { //Le mois de février
+
+ return LocalDateTime.of(annee, mois, jour, 0, 0, 0, 0);
+ }
+ }
+ }
+ throw new LocalDateTimeValueParseError("Impossible de parser la valeur " + stringValue + " au format " + format);
+ }
+
+ private LocalDateTime date(int yearIndex, int monthIdex, String stringValue) throws LocalDateTimeValueParseError {
+
+ if (yearIndex >= 0 && monthIdex >= 0) {
+ int annee = Integer.parseInt(stringValue.substring(yearIndex, yearIndex + 4));
+ int mois = Integer.parseInt(stringValue.substring(monthIdex, monthIdex + 2));
+ int jour = 1;
+
+ if (mois >= 1 && mois <= 12) {
+ return LocalDateTime.of(annee, mois, jour, 0, 0, 0, 0);
+ }
+ }
+ throw new LocalDateTimeValueParseError("Impossible de parser la valeur " + stringValue + " au format " + format);
+ }
+}
--
Gitblit v1.10.0