From e4ce12d1a3bcf9abda7130009ca3739c1f750699 Mon Sep 17 00:00:00 2001 From: Guido Fioravantti Date: Mon, 5 Oct 2015 11:51:13 +0200 Subject: [PATCH 1/3] Changes CDB_DateToNumber() to accept timestamps with time zones 2202 --- scripts-available/CDB_DateToNumber.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts-available/CDB_DateToNumber.sql b/scripts-available/CDB_DateToNumber.sql index 1b9a449..84c3395 100644 --- a/scripts-available/CDB_DateToNumber.sql +++ b/scripts-available/CDB_DateToNumber.sql @@ -1,6 +1,6 @@ -- Convert timestamp to double precision -- -CREATE OR REPLACE FUNCTION CDB_DateToNumber(input timestamp) +CREATE OR REPLACE FUNCTION CDB_DateToNumber(input timestamp with time zone) RETURNS double precision AS $$ DECLARE output double precision; BEGIN From 186ed34ee54eb43a36d433078dc6ef8a768e9bb7 Mon Sep 17 00:00:00 2001 From: Guido Fioravantti Date: Mon, 5 Oct 2015 13:32:03 +0200 Subject: [PATCH 2/3] Overloads CDB_DateToNumber() and adds test --- scripts-available/CDB_DateToNumber.sql | 16 ++++++++++++++++ test/CDB_DateToNumberTest.sql | 2 ++ test/CDB_DateToNumberTest_expect | 2 ++ 3 files changed, 20 insertions(+) create mode 100644 test/CDB_DateToNumberTest.sql create mode 100644 test/CDB_DateToNumberTest_expect diff --git a/scripts-available/CDB_DateToNumber.sql b/scripts-available/CDB_DateToNumber.sql index 84c3395..651d429 100644 --- a/scripts-available/CDB_DateToNumber.sql +++ b/scripts-available/CDB_DateToNumber.sql @@ -1,5 +1,21 @@ -- Convert timestamp to double precision -- +CREATE OR REPLACE FUNCTION CDB_DateToNumber(input timestamp) +RETURNS double precision AS $$ +DECLARE output double precision; +BEGIN + BEGIN + SELECT extract (EPOCH FROM input) INTO output; + EXCEPTION WHEN OTHERS THEN + RETURN NULL; + END; +RETURN output; +END; +$$ +LANGUAGE 'plpgsql' STABLE STRICT; + +-- Convert timestamp with time zone to double precision +-- CREATE OR REPLACE FUNCTION CDB_DateToNumber(input timestamp with time zone) RETURNS double precision AS $$ DECLARE output double precision; diff --git a/test/CDB_DateToNumberTest.sql b/test/CDB_DateToNumberTest.sql new file mode 100644 index 0000000..3821bd1 --- /dev/null +++ b/test/CDB_DateToNumberTest.sql @@ -0,0 +1,2 @@ +SELECT * FROM CDB_DateToNumber('1999-01-08 00:00:00+00'::timestamp); +SELECT * FROM CDB_DateToNumber('1999-01-08 00:00:00+00'::timestamp with time zone); diff --git a/test/CDB_DateToNumberTest_expect b/test/CDB_DateToNumberTest_expect new file mode 100644 index 0000000..8445360 --- /dev/null +++ b/test/CDB_DateToNumberTest_expect @@ -0,0 +1,2 @@ +915753600 +915753600 From 6b3b28f01f20bdaf829aacffe9c2260bd745367e Mon Sep 17 00:00:00 2001 From: Guido Fioravantti Date: Mon, 5 Oct 2015 14:56:45 +0200 Subject: [PATCH 3/3] Makes CDB_DateToNumber() tests more intuitive 2202 --- test/CDB_DateToNumberTest.sql | 4 ++-- test/CDB_DateToNumberTest_expect | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/CDB_DateToNumberTest.sql b/test/CDB_DateToNumberTest.sql index 3821bd1..0c1051c 100644 --- a/test/CDB_DateToNumberTest.sql +++ b/test/CDB_DateToNumberTest.sql @@ -1,2 +1,2 @@ -SELECT * FROM CDB_DateToNumber('1999-01-08 00:00:00+00'::timestamp); -SELECT * FROM CDB_DateToNumber('1999-01-08 00:00:00+00'::timestamp with time zone); +SELECT * FROM CDB_DateToNumber('1999-01-08 00:00:00'::timestamp); +SELECT * FROM CDB_DateToNumber('1999-01-08 00:00:00+05'::timestamp with time zone); diff --git a/test/CDB_DateToNumberTest_expect b/test/CDB_DateToNumberTest_expect index 8445360..bd3d3b0 100644 --- a/test/CDB_DateToNumberTest_expect +++ b/test/CDB_DateToNumberTest_expect @@ -1,2 +1,2 @@ 915753600 -915753600 +915735600