Re: [GENERAL] Converting a TimestampTz into a C# DateTime

2016-11-15 Thread valeriof
Awesome. Thanks everybody for your help



--
View this message in context: 
http://postgresql.nabble.com/Converting-a-TimestampTz-into-a-C-DateTime-tp5930221p5930465.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] Converting a TimestampTz into a C# DateTime

2016-11-15 Thread valeriof
I was able to make it work by reusing the code in TimeStampHandler.cs (in my
application I cannot directly reference Npgsql):


long datetime = GetInt64(buffer, ref pos);
// 8 bytes: datetime

if (datetime == long.MaxValue)
return DateTime.MaxValue;
else if (datetime == long.MinValue)
return DateTime.MinValue;

DateTime dt;
int date;
long time;

if (datetime >= 0)
{
date = (int)(datetime / 864L);
time = datetime % 864L;

date += 730119; // 730119 = days since era (0001-01-01)
for 2000-01-01
time *= 10; // To 100ns
}
else
{
datetime = -datetime;
date = (int)(datetime / 864L);
time = datetime % 864L;
if (time != 0)
{
++date;
time = 864L - time;
}
date = 730119 - date; // 730119 = days since era
(0001-01-01) for 2000-01-01
time *= 10; // To 100ns
}

TimeSpan ts = new TimeSpan(date, 0, 0, 0);
dt = (new DateTime(ts.Ticks) + new
TimeSpan(time)).ToLocalTime();

return dt;


BTW, a comment says this about the floating point representation: "A
deprecated compile-time option of PostgreSQL switches to a floating-point
representation of some date/time
fields. Npgsql (currently) does not support this mode." Is it safe to say
that the floating point format is less in use compared to the long int? If
Npgsql doesn't support it, any application that uses Npgsql will have this
limitation anyway. Am I correct?



--
View this message in context: 
http://postgresql.nabble.com/Converting-a-TimestampTz-into-a-C-DateTime-tp5930221p5930394.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[GENERAL] Converting a TimestampTz into a C# DateTime

2016-11-14 Thread valeriof
Hi,
I'm handling a TimestampTz value inside a plugin to stream WAL changes to a
.NET client application. What I'm trying to do is to return all possible
column changes as binary (don't like to have Postgres handle the conversion
to string as I may need to have access to the bytes at the client level). In
case of a TimestampTz, is it possible to return the 8-bytes long integer and
then from the C# application convert the value to Ticks? 

Thanks,
Valerio



--
View this message in context: 
http://postgresql.nabble.com/Converting-a-TimestampTz-into-a-C-DateTime-tp5930221.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general