refactor: don't use joda time and use java's time classes
This commit is contained in:
parent
a9fb768795
commit
ed15e9b023
6 changed files with 50 additions and 51 deletions
|
@ -50,7 +50,6 @@ dependencies {
|
|||
implementation 'org.yaml:snakeyaml:2.0'
|
||||
implementation 'org.luaj:luaj-jse:3.0.1'
|
||||
implementation 'net.dv8tion:JDA:5.0.0-beta.12'
|
||||
implementation 'joda-time:joda-time:2.12.4'
|
||||
implementation 'net.kyori:adventure-text-serializer-legacy:4.15.0'
|
||||
implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.20.0'
|
||||
implementation 'io.socket:socket.io-client:2.1.0'
|
||||
|
|
|
@ -16,14 +16,15 @@ import me.chayapak1.chomens_bot.util.PersistentDataUtilities;
|
|||
import me.chayapak1.chomens_bot.util.UUIDUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
@ -174,8 +175,12 @@ public class MailCommand extends Command {
|
|||
|
||||
if (!mail.sentTo.equals(sender.profile.getName())) continue;
|
||||
|
||||
final DateTimeFormatter formatter = DateTimeFormat.forPattern("MMMM d, YYYY, hh:mm:ss a Z");
|
||||
final String formattedTime = formatter.print(mail.timeSent);
|
||||
final Instant instant = Instant.ofEpochMilli(mail.timeSent);
|
||||
final ZoneId zoneId = ZoneId.systemDefault();
|
||||
final OffsetDateTime localDateTime = OffsetDateTime.ofInstant(instant, zoneId);
|
||||
|
||||
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM d, yyyy, hh:mm:ss a Z");
|
||||
final String formattedTime = localDateTime.format(formatter);
|
||||
|
||||
mailsComponent.add(
|
||||
Component.translatable(
|
||||
|
|
|
@ -12,11 +12,9 @@ import me.chayapak1.chomens_bot.util.ColorUtilities;
|
|||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
|
||||
import java.time.*;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -70,10 +68,12 @@ public class SeenCommand extends Command {
|
|||
|
||||
if (time == null) throw new CommandException(Component.text("This player does not have the `lastSeen.time` entry in the database for some reason."));
|
||||
|
||||
final DateTime dateTime = new DateTime(time.getAsLong(), DateTimeZone.UTC);
|
||||
final Instant instant = Instant.ofEpochMilli(time.getAsLong());
|
||||
final ZoneId zoneId = ZoneId.of("UTC"); // should i be doing this?
|
||||
final OffsetDateTime localDateTime = OffsetDateTime.ofInstant(instant, zoneId);
|
||||
|
||||
final DateTimeFormatter formatter = DateTimeFormat.forPattern("EEEE, MMMM d, YYYY, hh:mm:ss a z");
|
||||
final String formattedTime = formatter.print(dateTime);
|
||||
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEEE, MMMM d, yyyy, hh:mm:ss a Z");
|
||||
final String formattedTime = localDateTime.format(formatter);
|
||||
|
||||
final String server = lastSeen.get("server").getAsString();
|
||||
|
||||
|
|
|
@ -8,10 +8,11 @@ import me.chayapak1.chomens_bot.command.TrustLevel;
|
|||
import me.chayapak1.chomens_bot.util.ColorUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
|
||||
import java.time.DateTimeException;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class TimeCommand extends Command {
|
||||
public TimeCommand () {
|
||||
|
@ -27,26 +28,24 @@ public class TimeCommand extends Command {
|
|||
|
||||
@Override
|
||||
public Component execute(CommandContext context) throws CommandException {
|
||||
final Bot bot = context.bot;
|
||||
|
||||
final String timezone = context.getString(true, true);
|
||||
|
||||
DateTimeZone zone;
|
||||
try {
|
||||
zone = DateTimeZone.forID(timezone);
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
final Bot bot = context.bot;
|
||||
|
||||
final String timezone = context.getString(true, true);
|
||||
|
||||
final ZoneId zoneId = ZoneId.of(timezone);
|
||||
final ZonedDateTime zonedDateTime = ZonedDateTime.now(zoneId);
|
||||
|
||||
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEEE, MMMM d, yyyy, hh:mm:ss a");
|
||||
final String formattedTime = zonedDateTime.format(formatter);
|
||||
|
||||
return Component.translatable(
|
||||
"The current time for %s is: %s",
|
||||
Component.text(timezone).color(ColorUtilities.getColorByString(bot.config.colorPalette.string)),
|
||||
Component.text(formattedTime).color(NamedTextColor.GREEN)
|
||||
).color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
||||
} catch (DateTimeException e) {
|
||||
throw new CommandException(Component.text("Invalid timezone (case-sensitive)"));
|
||||
}
|
||||
|
||||
final DateTime dateTime = new DateTime(zone);
|
||||
|
||||
final DateTimeFormatter formatter = DateTimeFormat.forPattern("EEEE, MMMM d, YYYY, hh:mm:ss a");
|
||||
final String formattedTime = formatter.print(dateTime);
|
||||
|
||||
return Component.translatable(
|
||||
"The current time for %s is: %s",
|
||||
Component.text(timezone).color(ColorUtilities.getColorByString(bot.config.colorPalette.string)),
|
||||
Component.text(formattedTime).color(NamedTextColor.GREEN)
|
||||
).color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,14 +11,13 @@ import me.chayapak1.chomens_bot.util.ColorUtilities;
|
|||
import me.chayapak1.chomens_bot.util.HttpUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class WeatherCommand extends Command {
|
||||
public WeatherCommand () {
|
||||
|
@ -53,13 +52,11 @@ public class WeatherCommand extends Command {
|
|||
|
||||
final JsonObject jsonObject = gson.fromJson(jsonOutput, JsonObject.class);
|
||||
|
||||
final DateTimeFormatter formatter = DateTimeFormat.forPattern("hh:mm:ss a");
|
||||
final ZoneId zoneId = ZoneId.of(jsonObject.get("location").getAsJsonObject().get("tz_id").getAsString());
|
||||
final ZonedDateTime zonedDateTime = ZonedDateTime.now(zoneId);
|
||||
|
||||
final DateTimeZone zone = DateTimeZone.forID(jsonObject.get("location").getAsJsonObject().get("tz_id").getAsString());
|
||||
|
||||
final DateTime dateTime = new DateTime(zone);
|
||||
|
||||
final String time = formatter.print(dateTime);
|
||||
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("hh:mm:ss a");
|
||||
final String time = zonedDateTime.format(formatter);
|
||||
|
||||
return Component.translatable(
|
||||
"Weather forecast for %s, %s:\n%s (%s), feels like %s (%s)\nTime: %s",
|
||||
|
|
|
@ -5,10 +5,9 @@ import me.chayapak1.chomens_bot.data.PlayerEntry;
|
|||
import me.chayapak1.chomens_bot.util.ColorUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -64,10 +63,10 @@ public class TrustedPlugin extends PlayersPlugin.Listener {
|
|||
Component.text(target.profile.getName()).color(ColorUtilities.getColorByString(bot.config.colorPalette.username))
|
||||
).color(NamedTextColor.GREEN);
|
||||
} else {
|
||||
final DateTime now = DateTime.now();
|
||||
final LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
final DateTimeFormatter formatter = DateTimeFormat.forPattern("hh:mm:ss a");
|
||||
final String formattedTime = formatter.print(now);
|
||||
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("hh:mm:ss a");
|
||||
final String formattedTime = now.format(formatter);
|
||||
|
||||
component = Component.translatable(
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue