diff --git a/00-backend/src/main/java/de/htwsaar/webshop/util/TimeUtil.java b/00-backend/src/main/java/de/htwsaar/webshop/util/TimeUtil.java new file mode 100644 index 0000000..5e75a5f --- /dev/null +++ b/00-backend/src/main/java/de/htwsaar/webshop/util/TimeUtil.java @@ -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 can be valid + */ + public static boolean isValidTime(long time) { + return time >= VALID_MIN_MILLIS_TIMESTAMP; + } +}