Package dev.demeng.pluginbase
Class Time
java.lang.Object
dev.demeng.pluginbase.Time
Utilities for time/duration parsing and formatting.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ThreadLocal<DateFormat>The date format used for dates.static final ThreadLocal<DateFormat>The date format used for dates and times combined. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringformatDate(long time) Formats the date usingDATE_FORMAT.static StringformatDateTime(long time) Formats the date and time usingDATE_TIME_FORMAT.static StringformatDuration(Time.DurationFormatter formatter, long duration) Formats the duration using the selected formatter.static longfromSqlTimestamp(@NotNull String timestamp) Converts the SQL timestamp into a long.static @NotNull DurationConverts the given duration string into milliseconds and wraps it inside an Optional.parseSafely(@NotNull String input) static TimestamptoSqlTimestamp(long timestamp) Converts the long timestamp into an SQL timestamp.
-
Field Details
-
DATE_TIME_FORMAT
The date format used for dates and times combined. -
DATE_FORMAT
The date format used for dates.
-
-
Constructor Details
-
Time
public Time()
-
-
Method Details
-
formatDateTime
Formats the date and time usingDATE_TIME_FORMAT.- Parameters:
time- The time to format- Returns:
- The formatted date and time
-
formatDate
Formats the date usingDATE_FORMAT.- Parameters:
time- The time to format- Returns:
- The formatted date
-
parse
@NotNull public static @NotNull Duration parse(@NotNull @NotNull String input) throws IllegalArgumentException Converts the given duration string into milliseconds and wraps it inside an Optional. Supported time units include years (y), months (mo), weeks (w), days (d), hours (h), minutes (m), and seconds (s).- Parameters:
input- The duration string- Returns:
- The parsed duration
- Throws:
IllegalArgumentException- If the input could not be parsed
-
parseSafely
- Parameters:
input- The input string- Returns:
- An Optional Duration
- See Also:
-
formatDuration
Formats the duration using the selected formatter.- Parameters:
formatter- The formatter to useduration- The duration to format- Returns:
- The formatted duration
-
toSqlTimestamp
Converts the long timestamp into an SQL timestamp.- Parameters:
timestamp- The long timestamp- Returns:
- The equivalent timestamp, as one used by SQL
-
fromSqlTimestamp
Converts the SQL timestamp into a long.- Parameters:
timestamp- The SQL timestamp- Returns:
- The equivalent timestamp, as a long
-