Plex/server/src/main/java/dev/plex/util/adapter/ZonedDateTimeDeserializer.java

24 lines
832 B
Java
Raw Normal View History

2022-02-07 05:06:55 +00:00
package dev.plex.util.adapter;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import dev.plex.Plex;
2022-02-07 05:06:55 +00:00
import java.lang.reflect.Type;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
2022-02-07 05:06:55 +00:00
public class ZonedDateTimeDeserializer implements JsonDeserializer<ZonedDateTime>
2022-02-07 05:06:55 +00:00
{
2022-05-10 05:08:45 +00:00
private static final String TIMEZONE = Plex.get().config.getString("server.timezone");
2022-02-07 05:06:55 +00:00
@Override
public ZonedDateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
2022-02-07 05:06:55 +00:00
{
Instant instant = Instant.ofEpochMilli(json.getAsJsonPrimitive().getAsLong());
return ZonedDateTime.ofInstant(instant, ZoneId.of(TIMEZONE));
2022-02-07 05:06:55 +00:00
}
}