This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
The following commit(s) were added to refs/heads/geoapi-4.0 by this push: new f8a9c9ae79 Partial replacement of `java.util.TimeZone` by `java.time.ZoneId`. The old timezone is kept in codes related to `java.text.Format`. This commit has two incompatible changes: f8a9c9ae79 is described below commit f8a9c9ae792f5da2c2f4da4195c1b0048f4b28ce Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Sat Apr 5 11:09:52 2025 +0200 Partial replacement of `java.util.TimeZone` by `java.time.ZoneId`. The old timezone is kept in codes related to `java.text.Format`. This commit has two incompatible changes: - `OptionKey.TIMEZONE` parameterized type changed from `<TimeZone>` to `<ZoneId>`. This change was announced in the Javadoc comment. - `XML.TIMEZONE` property is now associated to a value of class `ZoneId`. However, the `setProperty(…)` method accepts a value of the two classes. --- .../main/org/apache/sis/console/AboutCommand.java | 4 ++-- .../main/org/apache/sis/console/CommandRunner.java | 9 +++++---- .../org/apache/sis/console/CommandRunnerTest.java | 11 ++++++----- .../main/org/apache/sis/xml/MarshalContext.java | 21 +++++++++++++++------ .../main/org/apache/sis/xml/Pooled.java | 21 +++++++++++++++++---- .../main/org/apache/sis/xml/XML.java | 5 +++-- .../main/org/apache/sis/xml/bind/Context.java | 8 ++++---- .../org/apache/sis/xml/privy/XmlUtilitiesTest.java | 2 +- .../test/org/apache/sis/xml/test/TestCase.java | 4 ++-- .../main/org/apache/sis/io/wkt/WKTFormat.java | 16 +++++++++++++++- .../test/org/apache/sis/io/wkt/WKTFormatTest.java | 3 ++- .../apache/sis/storage/geotiff/GeoTiffStore.java | 5 +++-- .../apache/sis/storage/netcdf/base/GridMapping.java | 3 +-- .../sis/storage/xml/stream/StaxDataStore.java | 4 ++-- .../org/apache/sis/storage/base/URIDataStore.java | 4 ++-- .../main/org/apache/sis/storage/folder/Store.java | 8 ++++---- .../apache/sis/storage/folder/StoreProvider.java | 6 +++--- .../org/apache/sis/storage/wkt/StoreFormat.java | 4 ++-- .../main/org/apache/sis/setup/OptionKey.java | 11 +++-------- .../sis/storage/shapefile/ShapefileStore.java | 3 +-- .../org/apache/sis/gui/referencing/WKTPane.java | 3 ++- .../main/org/apache/sis/storage/gdal/GDALStore.java | 2 +- 22 files changed, 96 insertions(+), 61 deletions(-) diff --git a/endorsed/src/org.apache.sis.console/main/org/apache/sis/console/AboutCommand.java b/endorsed/src/org.apache.sis.console/main/org/apache/sis/console/AboutCommand.java index 3744340a70..ffad45f08c 100644 --- a/endorsed/src/org.apache.sis.console/main/org/apache/sis/console/AboutCommand.java +++ b/endorsed/src/org.apache.sis.console/main/org/apache/sis/console/AboutCommand.java @@ -108,7 +108,7 @@ final class AboutCommand extends CommandRunner { /* * Provide information about the local SIS installation. */ - configuration = About.configuration(sections, locale, timezone).toString(); + configuration = About.configuration(sections, locale, getTimeZone()).toString(); } else { /* * Provide information about a remote SIS installation. Those information are accessible @@ -128,7 +128,7 @@ final class AboutCommand extends CommandRunner { try (JMXConnector jmxc = JMXConnectorFactory.connect(url)) { final MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); final SupervisorMBean bean = JMX.newMBeanProxy(mbsc, new ObjectName(Supervisor.NAME), SupervisorMBean.class); - table = bean.configuration(sections, locale, timezone); + table = bean.configuration(sections, locale, getTimeZone()); warnings = bean.warnings(locale); } } catch (IOException e) { diff --git a/endorsed/src/org.apache.sis.console/main/org/apache/sis/console/CommandRunner.java b/endorsed/src/org.apache.sis.console/main/org/apache/sis/console/CommandRunner.java index 0435c1e702..cfc28604dc 100644 --- a/endorsed/src/org.apache.sis.console/main/org/apache/sis/console/CommandRunner.java +++ b/endorsed/src/org.apache.sis.console/main/org/apache/sis/console/CommandRunner.java @@ -16,6 +16,7 @@ */ package org.apache.sis.console; +import java.time.ZoneId; import java.util.List; import java.util.ArrayList; import java.util.Locale; @@ -91,13 +92,13 @@ abstract class CommandRunner { /** * The locale specified by the {@code "--timezone"} option, or null if no timezone was specified. - * The null value may be interpreted as the {{@linkplain TimeZone#getDefault() default timezone} + * The null value may be interpreted as the {{@linkplain ZoneId#systemDefault() default timezone} * or as UTC, depending on the context. For example, WKT parsing and formatting use UTC unless * specified otherwise. * * @see #getTimeZone() */ - protected final TimeZone timezone; + protected final ZoneId timezone; /** * The encoding specified by the {@code "--encoding"} option. If no such option was provided, @@ -225,7 +226,7 @@ abstract class CommandRunner { locale = (s != null) ? Locales.parse(s) : Locale.getDefault(Locale.Category.DISPLAY); value = s = getOptionAsString(option = Option.TIMEZONE); - timezone = (s != null) ? TimeZone.getTimeZone(s) : null; + timezone = (s != null) ? ZoneId.of(s) : null; value = s = getOptionAsString(option = Option.ENCODING); explicitEncoding = (s != null); @@ -267,7 +268,7 @@ abstract class CommandRunner { * but the {@linkplain TimeZone#getDefault() default timezone} is preferred instead. */ protected final TimeZone getTimeZone() { - return (timezone != null) ? timezone : TimeZone.getDefault(); + return (timezone != null) ? TimeZone.getTimeZone(timezone) : TimeZone.getDefault(); } /** diff --git a/endorsed/src/org.apache.sis.console/test/org/apache/sis/console/CommandRunnerTest.java b/endorsed/src/org.apache.sis.console/test/org/apache/sis/console/CommandRunnerTest.java index 4f73725875..0081614e8c 100644 --- a/endorsed/src/org.apache.sis.console/test/org/apache/sis/console/CommandRunnerTest.java +++ b/endorsed/src/org.apache.sis.console/test/org/apache/sis/console/CommandRunnerTest.java @@ -16,6 +16,7 @@ */ package org.apache.sis.console; +import java.time.ZoneId; import java.util.EnumSet; import java.util.Locale; import java.util.TimeZone; @@ -85,10 +86,10 @@ public final class CommandRunnerTest extends TestCase { */ @Test public void testTimeZone() throws InvalidOptionException { - final CommandRunner c = new Dummy(EnumSet.allOf(Option.class), CommandRunner.TEST, "--timezone", "JST"); + final CommandRunner c = new Dummy(EnumSet.allOf(Option.class), CommandRunner.TEST, "--timezone", "Asia/Tokyo"); assertEquals(Option.TIMEZONE, getSingleton(c.options.keySet())); - assertEquals(TimeZone.getTimeZone("JST"), c.timezone, "timezone"); - assertEquals(TimeUnit.HOURS.toMillis(9), c.timezone.getRawOffset(), "rawoffset"); + assertEquals(TimeZone.getTimeZone("Asia/Tokyo"), c.getTimeZone(), "timezone"); + assertEquals(TimeUnit.HOURS.toMillis(9), c.getTimeZone().getRawOffset(), "rawoffset"); assertTrue(c.files.isEmpty(), "files.isEmpty()"); } @@ -113,12 +114,12 @@ public final class CommandRunnerTest extends TestCase { @Test public void testOptionMix() throws InvalidOptionException { final CommandRunner c = new Dummy(EnumSet.allOf(Option.class), CommandRunner.TEST, - "--brief", "--locale", "ja", "--verbose", "--timezone", "JST"); + "--brief", "--locale", "ja", "--verbose", "--timezone", "Asia/Tokyo"); assertEquals(EnumSet.of(Option.BRIEF, Option.LOCALE, Option.VERBOSE, Option.TIMEZONE), c.options.keySet(), "options"); // Test specific values. assertSame(Locale.JAPANESE, c.locale, "locale"); - assertEquals(TimeZone.getTimeZone("JST"), c.timezone, "timezone"); + assertEquals(ZoneId.of("Asia/Tokyo"), c.timezone, "timezone"); assertTrue(c.files.isEmpty(), "files.isEmpty()"); } diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/MarshalContext.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/MarshalContext.java index 4509ff7470..d876e8a5de 100644 --- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/MarshalContext.java +++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/MarshalContext.java @@ -16,6 +16,7 @@ */ package org.apache.sis.xml; +import java.time.ZoneId; import java.net.URI; import java.util.Locale; import java.util.Optional; @@ -80,16 +81,24 @@ public abstract class MarshalContext implements Localized { * * <h4>Handling of <code>null</code> timezone</h4> * A {@code null} value means that the timezone is unspecified. Callers are encouraged - * to use the UTC timezone as the default value, but some flexibility is allowed. + * to use the <abbr>UTC</abbr> timezone as the default value, but some flexibility is allowed. * - * <div class="warning"><b>Upcoming API change — Java time API</b>: - * return type may be changed to {@link java.time.ZoneId} in a future version. - * This change may be applied in synchronization with GeoAPI 4.0. - * </div> + * @return the timezone for the <abbr>XML</abbr> fragment being (un)marshalled, or {@code null} if unspecified. + * + * @since 1.5 + */ + public abstract ZoneId getZoneId(); + + /** + * Returns the legacy timezone to use for (un)marshalling, or {@code null} if none was explicitly specified. + * This is he value returned by {@link #getZoneId()} converted to the legacy Java object. * * @return the timezone for the XML fragment being (un)marshalled, or {@code null} if unspecified. */ - public abstract TimeZone getTimeZone(); + public TimeZone getTimeZone() { + ZoneId timezone = getZoneId(); + return (timezone != null) ? TimeZone.getTimeZone(timezone) : null; + } /** * Returns the schema version of the XML document being (un)marshalled. diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/Pooled.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/Pooled.java index 5a6fb9bff1..b2c170c47c 100644 --- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/Pooled.java +++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/Pooled.java @@ -20,11 +20,12 @@ import java.util.Map; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.ConcurrentModificationException; -import java.util.IllformedLocaleException; import java.util.Locale; import java.util.TimeZone; import java.util.function.UnaryOperator; import java.util.logging.Filter; +import java.time.ZoneId; +import java.time.DateTimeException; import javax.xml.validation.Schema; import jakarta.xml.bind.Marshaller; import jakarta.xml.bind.JAXBException; @@ -97,7 +98,7 @@ abstract class Pooled { * The timezone, or {@code null} if unspecified. * Can be set by the {@link XML#TIMEZONE} property. */ - private TimeZone timezone; + private ZoneId timezone; /** * The base URL of ISO 19115-3 (or other standards) schemas. It shall be an unmodifiable @@ -310,7 +311,19 @@ abstract class Pooled { return; } case XML.TIMEZONE: { - timezone = (value instanceof CharSequence) ? TimeZone.getTimeZone(value.toString()) : (TimeZone) value; + if (value instanceof CharSequence) { + String id = value.toString(); + try { + timezone = ZoneId.of(id); + } catch (DateTimeException e) { + timezone = TimeZone.getTimeZone(id).toZoneId(); + if (timezone.getId().equals("GMT")) { + throw e; + } + } + } else { + timezone = (value instanceof TimeZone) ? ((TimeZone) value).toZoneId() : (ZoneId) value; + } return; } case XML.SCHEMAS: { @@ -390,7 +403,7 @@ abstract class Pooled { return; } } - } catch (ClassCastException | IllformedLocaleException e) { + } catch (RuntimeException e) { throw new PropertyException(Errors.format( Errors.Keys.IllegalPropertyValueClass_2, name, value.getClass()), e); } diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/XML.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/XML.java index 80958b3447..1c7567d5c8 100644 --- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/XML.java +++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/XML.java @@ -16,6 +16,7 @@ */ package org.apache.sis.xml; +import java.time.ZoneId; import java.util.Map; import java.util.Locale; import java.util.TimeZone; @@ -125,8 +126,8 @@ public final class XML extends Static { /** * Specifies the timezone to use for marshalling dates and times. - * The value for this property shall be an instance of {@link TimeZone} - * or a {@link CharSequence} recognized by {@link TimeZone#getTimeZone(String)}. + * The value for this property shall be an instance of {@link ZoneId}, {@link TimeZone}, or a + * {@link CharSequence} recognized by {@link ZoneId#of(String)} or {@link TimeZone#getTimeZone(String)}. * * <h4>Default behavior</h4> * If this property is never set, then (un)marshalling will use the diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/Context.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/Context.java index 006ebf9d9f..5c9ca975f4 100644 --- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/Context.java +++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/Context.java @@ -17,11 +17,11 @@ package org.apache.sis.xml.bind; import java.net.URI; +import java.time.ZoneId; import java.util.Map; import java.util.HashMap; import java.util.IdentityHashMap; import java.util.Locale; -import java.util.TimeZone; import java.util.Collections; import java.util.Optional; import java.util.logging.Level; @@ -152,7 +152,7 @@ public final class Context extends MarshalContext { * The timezone, or {@code null} if unspecified. * In the latter case, an implementation-default (typically UTC) timezone is used. */ - private final TimeZone timezone; + private final ZoneId timezone; /** * The base URL of ISO 19115-3 (or other standards) schemas. @@ -287,7 +287,7 @@ public final class Context extends MarshalContext { public Context(int bitMasks, final MarshallerPool pool, final Locale locale, - final TimeZone timezone, + final ZoneId timezone, final Map<String,String> schemas, final Version versionGML, final Version versionMetadata, @@ -389,7 +389,7 @@ public final class Context extends MarshalContext { * @return the timezone in the context of current (un)marshalling process. */ @Override - public final TimeZone getTimeZone() { + public final ZoneId getZoneId() { return timezone; } diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/privy/XmlUtilitiesTest.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/privy/XmlUtilitiesTest.java index 5666f93d76..b54098ad63 100644 --- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/privy/XmlUtilitiesTest.java +++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/privy/XmlUtilitiesTest.java @@ -79,7 +79,7 @@ public final class XmlUtilitiesTest extends TestCase { */ @Test public void testTemporalToXML() throws DatatypeConfigurationException, JAXBException { - createContext(false, Locale.JAPAN, "JST"); + createContext(false, Locale.JAPAN, "Asia/Tokyo"); XMLGregorianCalendar calendar; Temporal t; diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/test/TestCase.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/test/TestCase.java index 092eb318a5..4c6a54088f 100644 --- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/test/TestCase.java +++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/test/TestCase.java @@ -19,8 +19,8 @@ package org.apache.sis.xml.test; import java.util.Map; import java.util.HashMap; import java.util.Locale; -import java.util.TimeZone; import java.util.logging.Logger; +import java.time.ZoneId; import java.io.InputStream; import java.io.StringReader; import java.io.StringWriter; @@ -186,7 +186,7 @@ public abstract class TestCase extends org.apache.sis.test.TestCase { */ protected final void createContext(final boolean marshal, final Locale locale, final String timezone) throws JAXBException { context = new Context(marshal ? Context.MARSHALLING : 0, getMarshallerPool(), locale, - (timezone != null) ? TimeZone.getTimeZone(timezone) : null, null, null, null, null, null, null, null); + (timezone != null) ? ZoneId.of(timezone) : null, null, null, null, null, null, null, null); } /** diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/WKTFormat.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/WKTFormat.java index d2ff6dda46..62390ce515 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/WKTFormat.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/WKTFormat.java @@ -16,6 +16,7 @@ */ package org.apache.sis.io.wkt; +import java.time.ZoneId; import java.util.Date; import java.util.Locale; import java.util.TimeZone; @@ -306,7 +307,7 @@ public class WKTFormat extends CompoundFormat<Object> { * @since 1.5 */ public WKTFormat() { - this(null, null); + this(null, (TimeZone) null); } /** @@ -321,6 +322,19 @@ public class WKTFormat extends CompoundFormat<Object> { * * @see #getLocale() * @see #getTimeZone() + * + * @since 1.5 + */ + public WKTFormat(final Locale locale, final ZoneId timezone) { + this(locale, (timezone != null) ? TimeZone.getTimeZone(timezone) : null); + } + + /** + * Creates a format for the given locale and legacy timezone. + * See {@link #WKTFormat(Locale, ZoneId)} for the description. + * + * @param locale the locale for the new {@code Format}, or {@code null} for {@code Locale.ROOT}. + * @param timezone the timezone for dates in the WKT temporal elements, or {@code null} for UTC. */ public WKTFormat(final Locale locale, final TimeZone timezone) { super(locale, timezone); diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTFormatTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTFormatTest.java index 964f757318..1a556fdeb6 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTFormatTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTFormatTest.java @@ -20,6 +20,7 @@ import java.net.URI; import java.util.Map; import java.util.Locale; import java.text.ParseException; +import java.time.ZoneId; import org.opengis.parameter.ParameterValue; import org.opengis.referencing.crs.VerticalCRS; import org.opengis.referencing.operation.MathTransformFactory; @@ -429,7 +430,7 @@ public final class WKTFormatTest extends EPSGDependentTestCase { final var pm = new DefaultPrimeMeridian( Map.of(DefaultPrimeMeridian.NAME_KEY, "Invalid “$name” here"), -10, Units.DEGREE); - format = new WKTFormat(Locale.US, null); + format = new WKTFormat(Locale.US, (ZoneId) null); final String wkt = format.format(pm); final Warnings warnings = format.getWarnings(); assertNotNull(warnings, "warnings"); diff --git a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/GeoTiffStore.java b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/GeoTiffStore.java index 5abdde61d1..23303078b0 100644 --- a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/GeoTiffStore.java +++ b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/GeoTiffStore.java @@ -23,6 +23,7 @@ import java.util.TimeZone; import java.util.Optional; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.time.ZoneId; import java.net.URI; import java.io.IOException; import java.nio.charset.Charset; @@ -124,7 +125,7 @@ public class GeoTiffStore extends DataStore implements Aggregate { /** * The timezone for the date and time parsing, or {@code null} for the default. */ - private final TimeZone timezone; + private final ZoneId timezone; /** * The object to use for parsing and formatting dates. Created when first needed. @@ -508,7 +509,7 @@ public class GeoTiffStore extends DataStore implements Aggregate { if (dateFormat == null) { dateFormat = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss", Locale.US); if (timezone != null) { - dateFormat.setTimeZone(timezone); + dateFormat.setTimeZone(TimeZone.getTimeZone(timezone)); } } return dateFormat; diff --git a/endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/GridMapping.java b/endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/GridMapping.java index 45015c40de..bc1f628017 100644 --- a/endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/GridMapping.java +++ b/endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/GridMapping.java @@ -22,7 +22,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.Locale; -import java.util.TimeZone; import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.function.Supplier; @@ -567,7 +566,7 @@ final class GridMapping { * The WKT is presumed to use the GDAL flavor of WKT 1, and warnings are redirected to decoder listeners. */ private CoordinateReferenceSystem createFromWKT(final String wkt) throws ParseException { - final var f = new WKTFormat(Decoder.DATA_LOCALE, TimeZone.getTimeZone(mapping.decoder.getTimeZone())); + final var f = new WKTFormat(Decoder.DATA_LOCALE, mapping.decoder.getTimeZone()); f.setConvention(org.apache.sis.io.wkt.Convention.WKT1_COMMON_UNITS); final var parsed = (CoordinateReferenceSystem) f.parseObject(wkt); final Warnings warnings = f.getWarnings(); diff --git a/endorsed/src/org.apache.sis.storage.xml/main/org/apache/sis/storage/xml/stream/StaxDataStore.java b/endorsed/src/org.apache.sis.storage.xml/main/org/apache/sis/storage/xml/stream/StaxDataStore.java index f07e8e7833..27d65b56a7 100644 --- a/endorsed/src/org.apache.sis.storage.xml/main/org/apache/sis/storage/xml/stream/StaxDataStore.java +++ b/endorsed/src/org.apache.sis.storage.xml/main/org/apache/sis/storage/xml/stream/StaxDataStore.java @@ -17,10 +17,10 @@ package org.apache.sis.storage.xml.stream; import java.util.Locale; -import java.util.TimeZone; import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.Filter; +import java.time.ZoneId; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; @@ -77,7 +77,7 @@ public abstract class StaxDataStore extends URIDataStore { * * @see OptionKey#TIMEZONE */ - protected final TimeZone timezone; + protected final ZoneId timezone; /** * The character encoding of the file content, or {@code null} if unspecified. diff --git a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/URIDataStore.java b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/URIDataStore.java index 0be020891b..bcd4ff3af0 100644 --- a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/URIDataStore.java +++ b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/URIDataStore.java @@ -21,9 +21,9 @@ import java.util.HashMap; import java.util.Arrays; import java.util.Optional; import java.util.Locale; -import java.util.TimeZone; import java.util.logging.Level; import java.util.logging.LogRecord; +import java.time.ZoneId; import java.io.BufferedWriter; import java.io.BufferedInputStream; import java.io.InputStream; @@ -106,7 +106,7 @@ public abstract class URIDataStore extends DataStore implements StoreResource { * User-specified timezone for dates, or {@code null} for UTC. * Subclasses may replace this value by a value read from the data file. */ - protected TimeZone timezone; + protected ZoneId timezone; /** * Creates a new data store. This constructor does not open the file, diff --git a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/folder/Store.java b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/folder/Store.java index 62fbf4df1c..c172a021c7 100644 --- a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/folder/Store.java +++ b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/folder/Store.java @@ -21,10 +21,10 @@ import java.util.List; import java.util.ArrayList; import java.util.Collection; import java.util.Locale; -import java.util.TimeZone; import java.util.Optional; import java.util.logging.Level; import java.util.concurrent.ConcurrentHashMap; +import java.time.ZoneId; import java.io.IOException; import java.io.UncheckedIOException; import java.nio.charset.Charset; @@ -205,9 +205,9 @@ class Store extends DataStore implements StoreResource, UnstructuredAggregate, D final String format = StoreUtilities.getFormatName(componentProvider); final ParameterValueGroup pg = (provider != null ? provider.getOpenParameters() : StoreProvider.PARAMETERS).createValue(); pg.parameter(DataStoreProvider.LOCATION).setValue(location); - Locale locale = configuration.getOption(OptionKey.LOCALE); - TimeZone timezone = configuration.getOption(OptionKey.TIMEZONE); - Charset encoding = configuration.getOption(OptionKey.ENCODING); + Locale locale = configuration.getOption(OptionKey.LOCALE); + ZoneId timezone = configuration.getOption(OptionKey.TIMEZONE); + Charset encoding = configuration.getOption(OptionKey.ENCODING); if (locale != null) pg.parameter("locale" ).setValue(locale ); if (timezone != null) pg.parameter("timezone").setValue(timezone); if (encoding != null) pg.parameter("encoding").setValue(encoding); diff --git a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/folder/StoreProvider.java b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/folder/StoreProvider.java index dd72fe7799..d6534556e0 100644 --- a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/folder/StoreProvider.java +++ b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/folder/StoreProvider.java @@ -18,8 +18,8 @@ package org.apache.sis.storage.folder; import java.util.EnumSet; import java.util.Locale; -import java.util.TimeZone; import java.util.logging.Logger; +import java.time.ZoneId; import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Path; @@ -84,7 +84,7 @@ public final class StoreProvider extends DataStoreProvider { /** * Description of the parameter for timezone of dates in the data store. */ - private static final ParameterDescriptor<TimeZone> TIMEZONE; + private static final ParameterDescriptor<ZoneId> TIMEZONE; /** * Description of the parameter for character encoding used by the data store. @@ -107,7 +107,7 @@ public final class StoreProvider extends DataStoreProvider { final InternationalString remark = Resources.formatInternational(Resources.Keys.UsedOnlyIfNotEncoded); ENCODING = annotate(builder, URIDataStoreProvider.ENCODING, remark); LOCALE = builder.addName("locale" ).setDescription(Resources.formatInternational(Resources.Keys.DataStoreLocale )).setRemarks(remark).create(Locale.class, null); - TIMEZONE = builder.addName("timezone").setDescription(Resources.formatInternational(Resources.Keys.DataStoreTimeZone)).setRemarks(remark).create(TimeZone.class, null); + TIMEZONE = builder.addName("timezone").setDescription(Resources.formatInternational(Resources.Keys.DataStoreTimeZone)).setRemarks(remark).create(ZoneId.class, null); FORMAT = builder.addName("format" ).setDescription(Resources.formatInternational(Resources.Keys.DirectoryContentFormatName)).create(String.class, null); location = new ParameterBuilder(URIDataStoreProvider.LOCATION_PARAM).create(Path.class, null); PARAMETERS = builder.addName(NAME).createGroup(location, LOCALE, TIMEZONE, ENCODING, FORMAT, URIDataStoreProvider.CREATE_PARAM); diff --git a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/wkt/StoreFormat.java b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/wkt/StoreFormat.java index fc3a29b6d7..73842aa99e 100644 --- a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/wkt/StoreFormat.java +++ b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/wkt/StoreFormat.java @@ -17,8 +17,8 @@ package org.apache.sis.storage.wkt; import java.text.ParseException; +import java.time.ZoneId; import java.util.Locale; -import java.util.TimeZone; import java.util.logging.Level; import java.util.logging.LogRecord; import org.opengis.geometry.Geometry; @@ -67,7 +67,7 @@ public final class StoreFormat extends WKTFormat { * @param library the geometry library, or {@code null} for the default. * @param listeners where to send warnings. */ - public StoreFormat(final Locale locale, final TimeZone timezone, + public StoreFormat(final Locale locale, final ZoneId timezone, final GeometryLibrary library, final StoreListeners listeners) { super(locale, timezone); diff --git a/endorsed/src/org.apache.sis.util/main/org/apache/sis/setup/OptionKey.java b/endorsed/src/org.apache.sis.util/main/org/apache/sis/setup/OptionKey.java index d98fea5257..509985913f 100644 --- a/endorsed/src/org.apache.sis.util/main/org/apache/sis/setup/OptionKey.java +++ b/endorsed/src/org.apache.sis.util/main/org/apache/sis/setup/OptionKey.java @@ -19,8 +19,8 @@ package org.apache.sis.setup; import java.util.Map; import java.util.HashMap; import java.util.Locale; -import java.util.TimeZone; import java.util.Objects; +import java.time.ZoneId; import java.nio.ByteBuffer; import java.io.Serializable; import java.io.ObjectStreamException; @@ -93,18 +93,13 @@ public class OptionKey<T> implements Serializable { /** * The timezone to use when parsing or formatting dates and times without explicit timezone. * If this option is not provided, then the default value is format specific. - * That default is often, but not necessarily, the {@linkplain TimeZone#getDefault() platform default}. - * - * <div class="warning"><b>Upcoming API change — Java time API</b>: - * the type may be changed to {@link java.time.ZoneId} in a future version. - * This change may be applied in synchronization with GeoAPI 4.0. - * </div> + * That default is often, but not necessarily, the {@linkplain ZoneId#systemDefault() platform default}. * * @see org.apache.sis.xml.XML#TIMEZONE * * @since 0.8 */ - public static final OptionKey<TimeZone> TIMEZONE = new OptionKey<>("TIMEZONE", TimeZone.class); + public static final OptionKey<ZoneId> TIMEZONE = new OptionKey<>("TIMEZONE", ZoneId.class); /** * The character encoding of document content. diff --git a/incubator/src/org.apache.sis.storage.shapefile/main/org/apache/sis/storage/shapefile/ShapefileStore.java b/incubator/src/org.apache.sis.storage.shapefile/main/org/apache/sis/storage/shapefile/ShapefileStore.java index 19e8bef9f8..8589e3280a 100644 --- a/incubator/src/org.apache.sis.storage.shapefile/main/org/apache/sis/storage/shapefile/ShapefileStore.java +++ b/incubator/src/org.apache.sis.storage.shapefile/main/org/apache/sis/storage/shapefile/ShapefileStore.java @@ -174,8 +174,7 @@ public final class ShapefileStore extends DataStore implements WritableFeatureSe public ShapefileStore(StorageConnector cnx) throws IllegalArgumentException, DataStoreException { this.shpPath = cnx.getStorageAs(Path.class); this.userDefinedCharSet = cnx.getOption(OptionKey.ENCODING); - var tz = cnx.getOption(OptionKey.TIMEZONE); - this.timezone = (tz != null) ? tz.toZoneId() : null; + this.timezone = cnx.getOption(OptionKey.TIMEZONE); this.files = new ShpFiles(shpPath); } diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/WKTPane.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/WKTPane.java index 7d9622e9ba..2818320b00 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/WKTPane.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/WKTPane.java @@ -18,6 +18,7 @@ package org.apache.sis.gui.referencing; import java.util.EnumMap; import java.util.Locale; +import java.time.ZoneId; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; @@ -83,7 +84,7 @@ final class WKTPane extends StringConverter<Convention> implements ChangeListene for (final Convention c : sc) { conventionTexts.put(c, toString(c, vocabulary)); } - format = new WKTFormat(locale, null); + format = new WKTFormat(locale, (ZoneId) null); format.setConvention(Convention.WKT2_SIMPLIFIED); convention = new ChoiceBox<>(FXCollections.observableArrayList(sc)); convention.setConverter(this); diff --git a/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/GDALStore.java b/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/GDALStore.java index d1622c988d..2c15336284 100644 --- a/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/GDALStore.java +++ b/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/GDALStore.java @@ -426,7 +426,7 @@ public class GDALStore extends DataStore implements Aggregate { */ final WKTFormat wktFormat() { if (wktFormat == null) { - wktFormat = new WKTFormat(null, null); + wktFormat = new WKTFormat(); wktFormat.setConvention(Convention.WKT1_COMMON_UNITS); } return wktFormat;