2222import java .text .DecimalFormat ;
2323import java .text .DecimalFormatSymbols ;
2424import java .text .SimpleDateFormat ;
25+ import java .time .Instant ;
26+ import java .time .LocalDate ;
27+ import java .time .ZoneId ;
28+ import java .time .ZonedDateTime ;
2529import java .util .Date ;
2630import java .util .HashMap ;
2731import java .util .Locale ;
@@ -35,6 +39,7 @@ public class NumberFormat {
3539
3640 /**
3741 * Utility class to format different numbers
42+ *
3843 * @param toolStats Plugin instance.
3944 */
4045 public NumberFormat (ToolStats toolStats ) {
@@ -140,8 +145,9 @@ public String formatDate(Date date) {
140145 }
141146
142147 /**
143- * Returns a human readable form of time in milliseconds.
144- * E.g. given 3752348000L outputs 1 years, 5 months, 3 days, 14 hours, 12 minutes, 28 seconds.
148+ * Returns a human-readable form of time in milliseconds.
149+ * E.g. given 3752348000L outputs 1 year, 5 months, 3 days, 14 hours, 12 minutes, 28 seconds.
150+ *
145151 * @param time The time in ms.
146152 * @return Map with units as keys and time value, e.g. "years" (key) -> 1 (value)
147153 */
@@ -155,7 +161,7 @@ public Map<String, String> formatTime(Long time) {
155161 long totalSeconds = time / 1000 ;
156162
157163 Map <String , String > timeUnits = new HashMap <>();
158-
164+
159165 long years = totalSeconds / (DAYS_PER_YEAR * HOURS_PER_DAY * MINUTES_PER_HOUR * SECONDS_PER_MINUTE );
160166 if (years > 0 ) {
161167 timeUnits .put ("years" , Long .toString (years ));
@@ -190,7 +196,16 @@ public Map<String, String> formatTime(Long time) {
190196 if (seconds > 0 || timeUnits .isEmpty ()) { // Always include seconds if everything else is zero
191197 timeUnits .put ("seconds" , Long .toString (seconds ));
192198 }
193-
199+
194200 return timeUnits ;
195201 }
202+
203+ public Date normalizeTime (Long time ) {
204+ Instant instant = Instant .ofEpochMilli (time );
205+ ZoneId zone = ZoneId .systemDefault ();
206+
207+ LocalDate localDate = instant .atZone (zone ).toLocalDate ();
208+ ZonedDateTime midnight = localDate .atStartOfDay (zone );
209+ return Date .from (midnight .toInstant ());
210+ }
196211}
0 commit comments