Skip to content

Commit

Permalink
fix: use ISO time format as standard parsing format
Browse files Browse the repository at this point in the history
  • Loading branch information
titivermeesch committed May 31, 2024
1 parent 5756b05 commit 9c8b03e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ java {
}

group = 'me.playbosswar.com'
version = '8.6.0'
version = '8.7.0'
description = 'CommandTimer'

repositories {
Expand Down Expand Up @@ -61,7 +61,7 @@ publishing {
maven(MavenPublication) {
groupId = 'me.playbosswar.com'
artifactId = 'commandtimer'
version = '8.6.0'
version = '8.7.0'

from components.java
}
Expand Down
4 changes: 2 additions & 2 deletions java8-build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ java {
}

group = 'me.playbosswar.com'
version = '8.6.0'
version = '8.7.0'
description = 'CommandTimer'

repositories {
Expand Down Expand Up @@ -69,7 +69,7 @@ publishing {
maven(MavenPublication) {
groupId = 'me.playbosswar.com'
artifactId = 'commandtimer'
version = '8.6.0'
version = '8.7.0'

from components.java
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/me/playbosswar/com/utils/Files.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public static List<Task> deserializeJsonFilesIntoCommandTimers() {
GsonConverter gson = new GsonConverter();
Task task = gson.fromJson(jsonParser.parse(fr).toString(), Task.class);
healTask(task);
task.storeInstance();
// We relink the tasks to commands and times because we lose this structure during serializing
task.getCommands().forEach(command -> {
command.setTask(task);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.io.Reader;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.time.LocalTime;
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/me/playbosswar/com/utils/gson/GsonDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,31 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;


public class GsonDate implements JsonSerializer<Date>, JsonDeserializer<Date> {
private final String FORMAT = "yyyy-MM-dd'T'HH:mm:ss. SSSXXX";

@Override
public Date deserialize(JsonElement jsonElement, Type type,
JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
SimpleDateFormat formatter = new SimpleDateFormat("MMM d, yyyy, H:mm:ss a", Locale.US);
SimpleDateFormat formatter = new SimpleDateFormat(FORMAT);
try {
return formatter.parse(jsonElement.getAsString());
} catch(ParseException e) {
throw new JsonParseException(e);
// Check if maybe it's in the old format
try {
SimpleDateFormat oldFormatter = new SimpleDateFormat("MMM d, yyyy, H:mm:ss a");
return oldFormatter.parse(jsonElement.getAsString());
} catch(ParseException ex) {
throw new JsonParseException(e);
}
}
}

@Override
public JsonElement serialize(Date date, Type type, JsonSerializationContext jsonSerializationContext) {
SimpleDateFormat sdf = new SimpleDateFormat("MMM d, yyyy, H:mm:ss a", Locale.US);
SimpleDateFormat sdf = new SimpleDateFormat(FORMAT);
return new JsonPrimitive(sdf.format(date));
}
}
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
main: me.playbosswar.com.CommandTimerPlugin
name: "CommandTimer"
version: "8.6.0"
version: "8.7.0"
description: "Schedule commands like you want"
author: PlayBossWar
api-version: 1.13
Expand Down

0 comments on commit 9c8b03e

Please sign in to comment.