This repository has been archived by the owner on Nov 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix cooldown logic problem; add minus symbol on duration if cooldown …
…passed
- Loading branch information
Showing
4 changed files
with
45 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.ericlam.mc.questtest; | ||
|
||
import java.sql.Timestamp; | ||
import java.time.Duration; | ||
|
||
public class DurationTest { | ||
|
||
public static void main(String[] args) { | ||
var oneDay = Duration.ofDays(1); | ||
var date = new Timestamp(1654247206150L).toLocalDateTime(); | ||
System.out.println("last finished: "+date.toString()); | ||
var cool = date.plus(oneDay); | ||
System.out.println("cool: "+cool.toString()); | ||
System.out.println("diff: "+formatDuration(Duration.between(cool, date))); | ||
} | ||
|
||
static String formatDuration(Duration duration) { | ||
long seconds = duration.getSeconds(); | ||
long absSeconds = Math.abs(seconds); | ||
return (seconds >= 0 ? "" : "-") + String.format( | ||
"%d:%02d:%02d", | ||
absSeconds / 3600, | ||
(absSeconds % 3600) / 60, | ||
absSeconds % 60); | ||
} | ||
} |