Merge remote-tracking branch 'origin/develop' into develop
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
This commit is contained in:
@@ -19,7 +19,6 @@ public class UtilityLocalDate {
|
||||
|
||||
private static final ZoneId currentZone = ZoneId.systemDefault();
|
||||
|
||||
|
||||
public static String formatDate(LocalDate dateToFormat, String format) {
|
||||
if (dateToFormat != null) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
|
||||
@@ -268,16 +267,28 @@ public class UtilityLocalDate {
|
||||
return prossimaData;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static BigDecimal timeDiff(LocalDateTime start, LocalDateTime end){
|
||||
/**
|
||||
* Calcola la differenza tra due LocalDateTime in base all'unità di tempo specificata.
|
||||
*
|
||||
* @param start Data e ora di inizio.
|
||||
* @param end Data e ora di fine.
|
||||
* @param timeUnit Unità di tempo per la differenza (SECONDS, MINUTES, HOURS).
|
||||
* @return Differenza tra le due date nel formato BigDecimal.
|
||||
* @throws Exception Se l'unità di tempo non è supportata.
|
||||
*/
|
||||
public static BigDecimal timeDiff(LocalDateTime start, LocalDateTime end, TimeUnit timeUnit) throws Exception {
|
||||
if (start == null || end == null)
|
||||
return BigDecimal.ZERO;
|
||||
|
||||
long diffInMillis = MILLIS.between(start, end);
|
||||
long diffInMillis = MILLIS.between(end, start);
|
||||
BigDecimal diffInSeconds = BigDecimal.valueOf(diffInMillis).divide(BigDecimal.valueOf(1000), 6, RoundingMode.HALF_UP);
|
||||
|
||||
//Conversione in minuti
|
||||
return diffInSeconds.divide(BigDecimal.valueOf(60), 6, RoundingMode.HALF_UP);
|
||||
if (timeUnit == TimeUnit.SECONDS)
|
||||
return diffInSeconds;
|
||||
else if (timeUnit == TimeUnit.HOURS)
|
||||
return diffInSeconds.divide(BigDecimal.valueOf(3600), 6, RoundingMode.HALF_UP);
|
||||
else if (timeUnit == TimeUnit.MINUTES)
|
||||
return diffInSeconds.divide(BigDecimal.valueOf(60), 6, RoundingMode.HALF_UP);
|
||||
else throw new Exception("Unsupported TimeUnit: " + timeUnit);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user