/
dev-npgsql
/
npgsql
Обзор
Документация
Войти
/
dev-npgsql
/
npgsql
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
test-logs
src/Npgsql.NodaTime/Internal/LegacyConverters.cs
62 строки
3 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 static Npgsql.NodaTime.Internal.NodaTimeUtils; namespace Npgsql.NodaTime.Internal; sealed class LegacyTimestampTzZonedDateTimeConverter(DateTimeZone dateTimeZone, bool dateTimeInfinityConversions) : PgBufferedConverter<ZonedDateTime> { public override bool CanConvert(DataFormat format, out BufferRequirements bufferRequirements) { bufferRequirements = BufferRequirements.CreateFixedSize(sizeof(long)); return format is DataFormat.Binary; } public override ZonedDateTime Read(PgReader reader) { var instant = DecodeInstant(reader.ReadInt64(), dateTimeInfinityConversions); if (dateTimeInfinityConversions && (instant == Instant.MaxValue || instant == Instant.MinValue)) throw new InvalidCastException("Infinity values not supported for timestamp with time zone"); return instant.InZone(dateTimeZone); } public override void Write(PgWriter writer, ZonedDateTime value) { var instant = value.ToInstant(); if (dateTimeInfinityConversions && (instant == Instant.MaxValue || instant == Instant.MinValue)) throw new ArgumentException("Infinity values not supported for timestamp with time zone"); writer.WriteInt64(EncodeInstant(instant, dateTimeInfinityConversions)); } } sealed class LegacyTimestampTzOffsetDateTimeConverter(DateTimeZone dateTimeZone, bool dateTimeInfinityConversions) : PgBufferedConverter<OffsetDateTime> { public override bool CanConvert(DataFormat format, out BufferRequirements bufferRequirements) { bufferRequirements = BufferRequirements.CreateFixedSize(sizeof(long)); return format is DataFormat.Binary; } public override OffsetDateTime Read(PgReader reader) { var instant = DecodeInstant(reader.ReadInt64(), dateTimeInfinityConversions); if (dateTimeInfinityConversions && (instant == Instant.MaxValue || instant == Instant.MinValue)) throw new InvalidCastException("Infinity values not supported for timestamp with time zone"); return instant.InZone(dateTimeZone).ToOffsetDateTime(); } public override void Write(PgWriter writer, OffsetDateTime value) { var instant = value.ToInstant(); if (dateTimeInfinityConversions && (instant == Instant.MaxValue || instant == Instant.MinValue)) throw new ArgumentException("Infinity values not supported for timestamp with time zone"); writer.WriteInt64(EncodeInstant(instant, true)); } }