Package de.galan.commons.time
Class Durations
- java.lang.Object
-
- de.galan.commons.time.Durations
-
public class Durations extends Object
Utility class to handle human readable time durations.
-
-
Constructor Summary
Constructors Constructor Description Durations()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static Longdehumanize(String time)Converts a human readable duration in the format "Xd Xh Xm Xs Xms" to miliseconds.static StringfromDuration(Duration duration)Deprecated.static Stringhumanize(long time)Converts a time in miliseconds to human readable duration in the format "Xd Xh Xm Xs Xms"static Stringhumanize(long time, String separator)static StringtimeAgo(Instant date)Prints how long the given date is ago in the format "Xd Xh Xm Xs Xms"protected static StringtimeAgo(Instant date, Instant reference)static StringtimeAgo(Date date)Prints how long the given date is ago in the format "Xd Xh Xm Xs Xms"static StringtimeLeft(Instant date)Prints how long the given date is in the future in the format "Xd Xh Xm Xs Xms"static StringtimeLeft(Date date)Prints how long the given date is in the future in the format "Xd Xh Xm Xs Xms"static DurationtoDuration(String time)Converts a time in human readable format "Xd Xh Xm Xs Xms" to java.util.time.Duration (for interoperability).
-
-
-
Field Detail
-
MS_MILLISECOND
public static final long MS_MILLISECOND
- See Also:
- Constant Field Values
-
MS_SECOND
public static final long MS_SECOND
- See Also:
- Constant Field Values
-
MS_MINUTE
public static final long MS_MINUTE
- See Also:
- Constant Field Values
-
MS_HOUR
public static final long MS_HOUR
- See Also:
- Constant Field Values
-
MS_DAY
public static final long MS_DAY
- See Also:
- Constant Field Values
-
MS_WEEK
public static final long MS_WEEK
- See Also:
- Constant Field Values
-
-
Method Detail
-
timeLeft
public static String timeLeft(Date date)
Prints how long the given date is in the future in the format "Xd Xh Xm Xs Xms"
-
timeLeft
public static String timeLeft(Instant date)
Prints how long the given date is in the future in the format "Xd Xh Xm Xs Xms"
-
timeAgo
public static String timeAgo(Date date)
Prints how long the given date is ago in the format "Xd Xh Xm Xs Xms"
-
timeAgo
public static String timeAgo(Instant date)
Prints how long the given date is ago in the format "Xd Xh Xm Xs Xms"
-
humanize
public static String humanize(long time)
Converts a time in miliseconds to human readable duration in the format "Xd Xh Xm Xs Xms"
-
dehumanize
public static Long dehumanize(String time)
Converts a human readable duration in the format "Xd Xh Xm Xs Xms" to miliseconds.
-
toDuration
public static Duration toDuration(String time)
Converts a time in human readable format "Xd Xh Xm Xs Xms" to java.util.time.Duration (for interoperability).
-
fromDuration
@Deprecated public static String fromDuration(Duration duration)
Deprecated.Converts a time from java.util.time.Duration to human readable format "Xd Xh Xm Xs Xms" (for interoperability).
TODO broken: https://stackoverflow.com/questions/24491243/why-cant-i-get-a-duration-in-minutes-or-hours-in-java-time
-
-