Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Switch to ZonedDateTime from LocalDateTime #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repositories {

dependencies {
compileOnly("io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT")
compileOnly("me.clip:placeholderapi:2.11.3")
compileOnly("me.clip:placeholderapi:2.11.6")
}

tasks {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import org.jetbrains.annotations.Nullable;

import java.time.DateTimeException;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.temporal.ChronoUnit;
Expand Down Expand Up @@ -64,15 +64,15 @@ public TimeFormatter(
* Format the current time with the given format
*
* @param format format
* @return {@code null} if the format is empty or invalid, otherwise {@link LocalDateTime#now(ZoneId)} formatted
* @return {@code null} if the format is empty or invalid, otherwise {@link ZonedDateTime#now(ZoneId)} formatted
*/
public @Nullable String formatTime(@NotNull final String format) {
if (format.trim().isEmpty()) {
return null;
}

return Optional.ofNullable(parseFormat(format))
.map(formatter -> LocalDateTime.now(timeZone).format(formatter))
.map(formatter -> ZonedDateTime.now(timeZone).format(formatter))
.orElse(null);
}

Expand Down Expand Up @@ -110,7 +110,7 @@ public TimeFormatter(
}

/**
* Calculate the time between {@link LocalDateTime#now(ZoneId)} and another date and return a formatted value
* Calculate the time between {@link ZonedDateTime#now(ZoneId)} and another date and return a formatted value
* using {@link #formatTimeInSeconds(long)} if {@code formatTime} is {@code true}.
*
* @param player player
Expand Down Expand Up @@ -146,8 +146,8 @@ public TimeFormatter(
}

try {
LocalDateTime now = LocalDateTime.now(timeZone);
LocalDateTime otherDate = LocalDateTime.parse(otherDateString, formatter);
ZonedDateTime now = ZonedDateTime.now(timeZone);
ZonedDateTime otherDate = ZonedDateTime.parse(otherDateString, formatter);

if (otherDate.isEqual(now)) {
return "0";
Expand Down