-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
144 additions
and
111 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
53 changes: 53 additions & 0 deletions
53
core/riot-core/src/main/java/com/redis/riot/core/RiotDuration.java
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,53 @@ | ||
package com.redis.riot.core; | ||
|
||
import java.time.Duration; | ||
import java.time.temporal.ChronoUnit; | ||
|
||
import org.springframework.boot.convert.DurationStyle; | ||
|
||
/** | ||
* Wrapper around java.time.Duration with a custom toString | ||
*/ | ||
public class RiotDuration { | ||
|
||
private final Duration value; | ||
private final ChronoUnit displayUnit; | ||
|
||
public RiotDuration(long value, ChronoUnit unit) { | ||
this(Duration.of(value, unit), unit); | ||
} | ||
|
||
public RiotDuration(Duration duration, ChronoUnit displayUnit) { | ||
this.value = duration; | ||
this.displayUnit = displayUnit; | ||
} | ||
|
||
public Duration getValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return DurationStyle.SIMPLE.print(value, displayUnit); | ||
} | ||
|
||
public static RiotDuration parse(String string) { | ||
return new RiotDuration(DurationStyle.SIMPLE.parse(string), ChronoUnit.MILLIS); | ||
} | ||
|
||
public static RiotDuration of(long value, ChronoUnit unit) { | ||
return new RiotDuration(value, unit); | ||
} | ||
|
||
public static RiotDuration of(Duration duration, ChronoUnit unit) { | ||
return new RiotDuration(duration, unit); | ||
} | ||
|
||
public static RiotDuration ofSeconds(long seconds) { | ||
return new RiotDuration(seconds, ChronoUnit.SECONDS); | ||
} | ||
|
||
public static RiotDuration ofMillis(long millis) { | ||
return new RiotDuration(millis, ChronoUnit.MILLIS); | ||
} | ||
} |
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
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
Oops, something went wrong.