Skip to content
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
11 changes: 7 additions & 4 deletions modules/org.jkiss.utils/src/org/jkiss/utils/GsonUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
* Copyright (C) 2010-2025 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,7 +19,10 @@
import com.google.gson.*;

import java.lang.reflect.Type;
import java.time.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalQueries;
Expand All @@ -31,7 +34,7 @@ public class GsonUtils {
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter
.ofPattern("MMM d, yyyy[, h:mm:ss a]")
.localizedBy(Locale.ENGLISH)
.withZone(ZoneId.of("UTC"));
.withZone(StandardConstants.ZONE_ID_UTC);

public static GsonBuilder gsonBuilder() {
return new GsonBuilder()
Expand All @@ -55,7 +58,7 @@ public JsonElement serialize(byte[] src, Type typeOfSrc, JsonSerializationContex
public static class DateTypeAdapter implements JsonSerializer<Date>, JsonDeserializer<Date> {
@Override
public synchronized JsonElement serialize(Date date, Type type, JsonSerializationContext jsonSerializationContext) {
return new JsonPrimitive(LocalDateTime.ofInstant(date.toInstant(), ZoneId.of("UTC")).format(DATE_TIME_FORMATTER));
return new JsonPrimitive(LocalDateTime.ofInstant(date.toInstant(), StandardConstants.ZONE_ID_UTC).format(DATE_TIME_FORMATTER));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
* Copyright (C) 2010-2025 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,8 @@
*/
package org.jkiss.utils;

import java.time.ZoneId;

/**
* Standard Java constants
*/
Expand Down Expand Up @@ -46,4 +48,6 @@ public abstract class StandardConstants {
public static final String ISO_DATE_PATTERN = "yyyy-MM-dd";
public static final String ISO_TIME_PATTERN = "HH:mm:ss'Z'";
public static final String ISO_TIMESTAMP_PATTERN = "yyyy-MM-dd'T'HH:mm:ss'Z'";

public static final ZoneId ZONE_ID_UTC = ZoneId.of("UTC");
}
Loading