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.OffsetTime;
9   
10  import dev.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider;
11  import dev.metaschema.core.datatype.adapter.TimeAdapter;
12  import dev.metaschema.core.datatype.object.AmbiguousTime;
13  import edu.umd.cs.findbugs.annotations.NonNull;
14  
15  /**
16   * An implementation of a Metapath atomic item containing a time data value that
17   * 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 TimeWithoutTimeZoneItemImpl
24      extends AbstractTimeItem<AmbiguousTime> {
25  
26    /**
27     * Construct a new item with the provided {@code value}.
28     *
29     * @param value
30     *          the value to wrap
31     */
32    public TimeWithoutTimeZoneItemImpl(@NonNull AmbiguousTime value) {
33      super(value);
34    }
35  
36    @Override
37    public boolean hasTimezone() {
38      return getJavaTypeAdapter().toValue(getValue()).hasTimeZone();
39    }
40  
41    @Override
42    public TimeAdapter getJavaTypeAdapter() {
43      return MetaschemaDataTypeProvider.TIME;
44    }
45  
46    @Override
47    public OffsetTime asOffsetTime() {
48      return getValue().getValue();
49    }
50  }