Re: Converting a TimestampTz into a C# DateTime

Поиск
Список
Период
Сортировка
От valeriof
Тема Re: Converting a TimestampTz into a C# DateTime
Дата
Msg-id 1479207611814-5930394.post@n3.nabble.com
обсуждение исходный текст
Ответ на Re: Converting a TimestampTz into a C# DateTime  (Arjen Nienhuis <a.g.nienhuis@gmail.com>)
Ответы Re: Converting a TimestampTz into a C# DateTime  (Albe Laurenz <laurenz.albe@wien.gv.at>)
Список pgsql-general
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 / 86400000000L);
                    time = datetime % 86400000000L;

                    date += 730119; // 730119 = days since era (0001-01-01)
for 2000-01-01
                    time *= 10; // To 100ns
                }
                else
                {
                    datetime = -datetime;
                    date = (int)(datetime / 86400000000L);
                    time = datetime % 86400000000L;
                    if (time != 0)
                    {
                        ++date;
                        time = 86400000000L - 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.


В списке pgsql-general по дате отправления:

Предыдущее
От: Venkata B Nagothi
Дата:
Сообщение: Re: Fwd: Mail to be posted in PostgreSQL community
Следующее
От: kaustubh kelkar
Дата:
Сообщение: Re: Fwd: Mail to be posted in PostgreSQL community