Add TimeUtil for later

This commit is contained in:
Tim
2025-05-24 13:03:08 +02:00
parent 252ae36b86
commit 082edd0112

View File

@@ -0,0 +1,53 @@
package de.htwsaar.webshop.util;
/**
* Helper Class for Unix-Millis related Things
*/
public class TimeUtil {
/**
* Amount millis representing one minute
*/
public static final long MILLIS_TO_MINUTE = 60 * 1000;
/**
* Amount millis representing one hour
*/
public static final long MILLIS_TO_HOUR = MILLIS_TO_MINUTE * 60;
/**
* Amount millis representing one day
*/
private static final long MILLIS_TO_DAY = MILLIS_TO_HOUR * 24;
/**
* Amount millis representing one week
*/
public static final long MILLIS_TO_WEEK = MILLIS_TO_DAY * 7;
/**
* Amount millis in the first second of 2025
*/
public static final long VALID_MIN_MILLIS_TIMESTAMP = 1735686000000L;
/**
* Now in X days, represented as Unix Millis
*
* @param days how many days to add
* @return the calculated Unix-Millis
*/
public static long nowPlusDays(long days) {
return System.currentTimeMillis() + (days * MILLIS_TO_DAY);
}
/**
* Check whether the Unix-Millis are valid
*
* @param time the Millis to Check
* @return whether the Time <b>can</b> be valid
*/
public static boolean isValidTime(long time) {
return time >= VALID_MIN_MILLIS_TIMESTAMP;
}
}