1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package dev.metaschema.core.metapath.item.atomic.impl;
7   
8   import java.time.ZonedDateTime;
9   
10  import dev.metaschema.core.datatype.adapter.DateTimeAdapter;
11  import dev.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider;
12  import dev.metaschema.core.datatype.object.AmbiguousDateTime;
13  import edu.umd.cs.findbugs.annotations.NonNull;
14  
15  /**
16   * An implementation of a Metapath atomic item containing a date/time data value
17   * that may not have an explicit timezone.
18   * <p>
19   * For example, when parsing dates from data sources that don't specify timezone
20   * information, such as "2024-01-01" as compared to "2024-01-01Z" or
21   * "2024-01-01+05:00".
22   */
23  public class DateTimeWithoutTimeZoneItemImpl
24      extends AbstractDateTimeItem<AmbiguousDateTime> {
25  
26    /**
27     * Construct a new item with the provided {@code value}.
28     *
29     * @param value
30     *          the value to wrap
31     */
32    public DateTimeWithoutTimeZoneItemImpl(@NonNull AmbiguousDateTime value) {
33      super(value);
34    }
35  
36    @Override
37    public boolean hasTimezone() {
38      return getJavaTypeAdapter().toValue(getValue()).hasTimeZone();
39    }
40  
41    @Override
42    public ZonedDateTime asZonedDateTime() {
43      return getValue().getValue();
44    }
45  
46    @Override
47    public DateTimeAdapter getJavaTypeAdapter() {
48      return MetaschemaDataTypeProvider.DATE_TIME;
49    }
50  }