package gaf3.core.jpa.converter

import org.springframework.data.domain.Range
import java.time.LocalDateTime
import java.time.OffsetTime

class DateTimeRangeConverter: AttributeConverter<LocalDateTime?, Range<LocalDateTime>?> {
    override fun convert(attribute: LocalDateTime?, parameter: String?): Range<LocalDateTime>? {
        return attribute?.let {
            val start: LocalDateTime = it.toLocalDate().atStartOfDay()
            val end: LocalDateTime = it.toLocalDate().atTime(OffsetTime.MAX).toLocalDateTime()
            Range.open(start, end)
        }
    }
}