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

io.deephaven.engine.table.impl.sources.LongAsLocalDateColumnSource 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;

import io.deephaven.engine.table.ColumnSource;
import io.deephaven.time.DateTimeUtils;
import org.jetbrains.annotations.NotNull;

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

/**
 * Reinterpret result {@link ColumnSource} implementations that translates {@code long} to {@link LocalDate} values.
 */
public class LongAsLocalDateColumnSource extends LongAsTimeSource {

    private final ZoneId zone;

    public LongAsLocalDateColumnSource(ColumnSource alternateColumnSource, ZoneId zone) {
        super(LocalDate.class, alternateColumnSource);
        this.zone = zone;
    }

    @Override
    protected LocalDate makeValue(long val) {
        final ZonedDateTime zdt = DateTimeUtils.epochNanosToZonedDateTime(val, zone);
        return zdt == null ? null : zdt.toLocalDate();
    }

    @Override
    public ColumnSource toLocalDate(@NotNull final ZoneId timeZone) {
        return zone.equals(timeZone) ? this : super.toLocalDate(timeZone);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy