/
dev-npgsql
/
npgsql
Обзор
Документация
Войти
/
dev-npgsql
/
npgsql
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
test-logs
src/Npgsql.NodaTime/Internal/LocalDateConverter.cs
47 строк
2 KB
Nino Floris
Remove PgBufferedConverter virtual dispatch hop (#6574)
15 май 2026, 18:24
Не верифицирован
15 май 2026, 18:24
78d37a1
Код
Авторство
О чём код?
using System; using NodaTime; using Npgsql.Internal; using Npgsql.NodaTime.Properties; namespace Npgsql.NodaTime.Internal; sealed class LocalDateConverter(bool dateTimeInfinityConversions) : PgBufferedConverter<LocalDate> { public override bool CanConvert(DataFormat format, out BufferRequirements bufferRequirements) { bufferRequirements = BufferRequirements.CreateFixedSize(sizeof(int)); return format is DataFormat.Binary; } public override LocalDate Read(PgReader reader) => reader.ReadInt32() switch { int.MaxValue => dateTimeInfinityConversions ? LocalDate.MaxIsoValue : throw new InvalidCastException(NpgsqlNodaTimeStrings.CannotReadInfinityValue), int.MinValue => dateTimeInfinityConversions ? LocalDate.MinIsoValue : throw new InvalidCastException(NpgsqlNodaTimeStrings.CannotReadInfinityValue), var value => new LocalDate().PlusDays(value + 730119) }; public override void Write(PgWriter writer, LocalDate value) { if (dateTimeInfinityConversions) { if (value == LocalDate.MaxIsoValue) { writer.WriteInt32(int.MaxValue); return; } if (value == LocalDate.MinIsoValue) { writer.WriteInt32(int.MinValue); return; } } var totalDaysSinceEra = Period.Between(default, value, PeriodUnits.Days).Days; writer.WriteInt32(totalDaysSinceEra - 730119); } }