Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Feat(2DDoc): format date #884

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading