mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-02-11 05:19:14 +00:00
listado de pedidos admin hecho
This commit is contained in:
@ -4,7 +4,9 @@ import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.security.Principal;
|
||||
import java.text.NumberFormat;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -12,6 +14,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import org.springframework.context.MessageSource;
|
||||
@ -357,4 +360,54 @@ public class Utils {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm", locale);
|
||||
return dateTime.format(formatter);
|
||||
}
|
||||
|
||||
public static String formatInstant(Instant instant, Locale locale) {
|
||||
if (instant == null) {
|
||||
return "";
|
||||
}
|
||||
ZoneId zone = zoneIdForLocale(locale);
|
||||
|
||||
DateTimeFormatter formatter = DateTimeFormatter
|
||||
.ofPattern("dd/MM/yyyy HH:mm", locale)
|
||||
.withZone(zone);
|
||||
|
||||
return formatter.format(instant);
|
||||
}
|
||||
|
||||
/*********************
|
||||
* Metodos auxiliares
|
||||
*/
|
||||
private static ZoneId zoneIdForLocale(Locale locale) {
|
||||
if (locale == null || locale.getCountry().isEmpty()) {
|
||||
return ZoneId.of("UTC");
|
||||
}
|
||||
|
||||
// Buscar timezones cuyo ID termine con el country code
|
||||
// Ej: ES -> Europe/Madrid
|
||||
String country = locale.getCountry();
|
||||
|
||||
Set<String> zoneIds = ZoneId.getAvailableZoneIds();
|
||||
for (String id : zoneIds) {
|
||||
// TimeZone# getID() no funciona por país, pero sí el prefijo + país
|
||||
if (id.endsWith("/" + country) || id.contains("/" + country)) {
|
||||
return ZoneId.of(id);
|
||||
}
|
||||
}
|
||||
|
||||
// fallback por regiones comunes (manual pero muy útil)
|
||||
Map<String, String> fallback = Map.of(
|
||||
"ES", "Europe/Madrid",
|
||||
"MX", "America/Mexico_City",
|
||||
"AR", "America/Argentina/Buenos_Aires",
|
||||
"US", "America/New_York",
|
||||
"GB", "Europe/London",
|
||||
"FR", "Europe/Paris");
|
||||
|
||||
if (fallback.containsKey(country)) {
|
||||
return ZoneId.of(fallback.get(country));
|
||||
}
|
||||
|
||||
return ZoneId.systemDefault(); // último fallback
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user