ZonedDateTime INpgsqlSimpleTypeHandler <ZonedDateTime> .Read(NpgsqlReadBuffer buf, int len, FieldDescription fieldDescription)
 {
     try
     {
         if (_integerFormat)
         {
             var value = buf.ReadInt64();
             if (value == long.MaxValue || value == long.MinValue)
             {
                 throw new NpgsqlSafeReadException(new NotSupportedException("Infinity values not supported for timestamp with time zone"));
             }
             return(TimestampHandler.Decode(value).InZone(_dateTimeZoneProvider[buf.Connection.Timezone]));
         }
         else
         {
             var value = buf.ReadDouble();
             if (double.IsPositiveInfinity(value) || double.IsNegativeInfinity(value))
             {
                 throw new NpgsqlSafeReadException(new NotSupportedException("Infinity values not supported for timestamp with time zone"));
             }
             return(TimestampHandler.Decode(value).InZone(_dateTimeZoneProvider[buf.Connection.Timezone]));
         }
     }
     catch (DateTimeZoneNotFoundException e)
     {
         throw new NpgsqlSafeReadException(e);
     }
 }
Beispiel #2
0
 ZonedDateTime INpgsqlSimpleTypeHandler <ZonedDateTime> .Read(NpgsqlReadBuffer buf, int len, FieldDescription fieldDescription)
 {
     try
     {
         if (_integerFormat)
         {
             var value = buf.ReadInt64();
             if (value == long.MaxValue || value == long.MinValue)
             {
                 throw new NpgsqlSafeReadException(new NotSupportedException("Infinity values not supported for timestamp with time zone"));
             }
             return(TimestampHandler.Decode(value).InZone(_dateTimeZoneProvider[buf.Connection.Timezone]));
         }
         else
         {
             var value = buf.ReadDouble();
             if (double.IsPositiveInfinity(value) || double.IsNegativeInfinity(value))
             {
                 throw new NpgsqlSafeReadException(new NotSupportedException("Infinity values not supported for timestamp with time zone"));
             }
             return(TimestampHandler.Decode(value).InZone(_dateTimeZoneProvider[buf.Connection.Timezone]));
         }
     }
     catch (TimeZoneNotFoundException) when(string.Equals(buf.Connection.Timezone, "localtime", StringComparison.OrdinalIgnoreCase))
     {
         throw new NpgsqlSafeReadException(
                   new TimeZoneNotFoundException(
                       "The special PostgreSQL timezone 'localtime' is not supported when reading values of type 'timestamp with time zone'. " +
                       "Please specify a real timezone in 'postgresql.conf' on the server, or set the 'PGTZ' environment variable on the client."));
     }
     catch (TimeZoneNotFoundException e)
     {
         throw new NpgsqlSafeReadException(e);
     }
 }
        public override Instant Read(NpgsqlReadBuffer buf, int len, FieldDescription?fieldDescription = null)
        {
            var value = buf.ReadInt64();

            if (_convertInfinityDateTime)
            {
                if (value == long.MaxValue)
                {
                    return(Instant.MaxValue);
                }
                if (value == long.MinValue)
                {
                    return(Instant.MinValue);
                }
            }
            return(TimestampHandler.Decode(value));
        }
 public override Instant Read(NpgsqlReadBuffer buf, int len, FieldDescription fieldDescription = null)
 {
     if (_integerFormat)
     {
         var value = buf.ReadInt64();
         if (value == long.MaxValue || value == long.MinValue)
         {
             throw new NpgsqlSafeReadException(new NotSupportedException("Infinity values not supported for timestamp with time zone"));
         }
         return(TimestampHandler.Decode(value));
     }
     else
     {
         var value = buf.ReadDouble();
         if (double.IsPositiveInfinity(value) || double.IsNegativeInfinity(value))
         {
             throw new NpgsqlSafeReadException(new NotSupportedException("Infinity values not supported for timestamp with time zone"));
         }
         return(TimestampHandler.Decode(value));
     }
 }