All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.deephaven.engine.table.impl.sources.immutable.Immutable2DZonedDateTimeArraySource Maven / Gradle / Ivy

There is a newer version: 0.37.1
Show newest version
/**
 * Copyright (c) 2016-2023 Deephaven Data Labs and Patent Pending
 */
package io.deephaven.engine.table.impl.sources.immutable;

import io.deephaven.engine.table.ColumnSource;
import io.deephaven.engine.table.impl.ImmutableColumnSourceGetDefaults;
import io.deephaven.engine.table.impl.sources.ConvertibleTimeSource;
import io.deephaven.time.DateTimeUtils;
import org.jetbrains.annotations.NotNull;

import java.time.ZoneId;
import java.time.ZonedDateTime;

/**
 * ImmutableArraySource for {@link ZonedDateTime}s. Allows reinterpretation as long.
 */
public class Immutable2DZonedDateTimeArraySource extends Immutable2DNanosBasedTimeArraySource
        implements ImmutableColumnSourceGetDefaults.ForObject, ConvertibleTimeSource.Zoned {
    private final ZoneId zone;

    public Immutable2DZonedDateTimeArraySource(
            @NotNull final ZoneId zone) {
        super(ZonedDateTime.class);
        this.zone = zone;
    }

    public Immutable2DZonedDateTimeArraySource(
            @NotNull final ZoneId zone,
            @NotNull final Immutable2DLongArraySource nanoSource) {
        super(ZonedDateTime.class, nanoSource);
        this.zone = zone;
    }

    @Override
    protected ZonedDateTime makeValue(long nanos) {
        return DateTimeUtils.epochNanosToZonedDateTime(nanos, zone);
    }

    @Override
    protected long toNanos(ZonedDateTime value) {
        return DateTimeUtils.epochNanos(value);
    }

    @Override
    public ColumnSource toZonedDateTime(@NotNull final ZoneId zone) {
        if (this.zone.equals(zone)) {
            return this;
        }

        return new Immutable2DZonedDateTimeArraySource(zone, this.nanoSource);
    }

    @Override
    public ZoneId getZone() {
        return zone;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy