exchange_now.sql (1416B)
1 -- 2 -- This file is part of TALER 3 -- Copyright (C) 2026 Taler Systems SA 4 -- 5 -- TALER is free software; you can redistribute it and/or modify it under the 6 -- terms of the GNU General Public License as published by the Free Software 7 -- Foundation; either version 3, or (at your option) any later version. 8 -- 9 -- TALER is distributed in the hope that it will be useful, but WITHOUT ANY 10 -- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 -- A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 -- 13 -- You should have received a copy of the GNU General Public License along with 14 -- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 -- 16 17 -- Statistics use the same time-travel offset as the exchange process. The 18 -- session setting is initialized on connection (including reconnection). 19 -- Plain SQL clients use real time unless they explicitly set the offset. 20 -- Return UTC civil time so EXTRACT(epoch) and statistic buckets do not depend 21 -- on the PostgreSQL session timezone. 22 CREATE OR REPLACE FUNCTION exchange_now() 23 RETURNS TIMESTAMP 24 LANGUAGE SQL 25 STABLE 26 AS $$ 27 SELECT (CURRENT_TIMESTAMP(0) AT TIME ZONE 'UTC') 28 + COALESCE(NULLIF(current_setting('taler.timetravel_us', true), ''), '0')::BIGINT 29 * INTERVAL '1 microsecond'; 30 $$; 31 COMMENT ON FUNCTION exchange_now 32 IS 'transaction time with the exchange session time-travel offset';