Skip to content

Commit

Permalink
✨ Feat(2DDoc): format date (#884)
Browse files Browse the repository at this point in the history
  • Loading branch information
poissoj authored Oct 21, 2024
1 parent 6cfc337 commit 8bbf3ff
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import lombok.RequiredArgsConstructor;

import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

import fr.dossierfacile.process.file.util.TwoDDocUtil;

import static fr.dossierfacile.process.file.barcode.twoddoc.parsing.TwoDDocC40Parser.ASCII_GROUP_SEPARATOR;

public record TwoDDocData(Map<TwoDDocDataType, String> data) {
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("dd/MM/yyyy");

static TwoDDocData parse(String rawData) {
RawDataReader reader = new RawDataReader(rawData);
Expand All @@ -17,6 +21,10 @@ static TwoDDocData parse(String rawData) {
while (reader.charactersRemaining()) {
TwoDDocDataType dataType = reader.readDataId();
String value = reader.readDataValue(dataType);
if (dataType.equals(TwoDDocDataType.ID_53) || dataType.equals(TwoDDocDataType.ID_54)) {
value = TwoDDocUtil.getLocalDateFrom2DDocHexDate(value)
.format(DATE_TIME_FORMATTER);
}
parsedData.put(dataType, value);
}

Expand All @@ -28,8 +36,7 @@ public Map<String, String> withLabels() {
.stream()
.collect(Collectors.toMap(
entry -> entry.getKey().getLabel(),
Map.Entry::getValue)
);
Map.Entry::getValue));
}

@RequiredArgsConstructor
Expand Down

0 comments on commit 8bbf3ff

Please sign in to comment.