Query editor
WITH contract_start AS (SELECTTRY_CAST('2023-10-28 07:15:23+00' AS TIMESTAMP WITH TIME ZONE) AT TIME ZONE 'UTC' AS start_date), cycle_lengths AS (SELECT*FROM (VALUES(8),(28),(90),(369),(888)) AS cycle_length(days)), cycles AS (SELECTcycle_lengths.days,start_date + INTERVAL '1' day * cycle_lengths.days * cycle_series AS cycle_end_dateFROM contract_start, cycle_lengths, UNNEST(SEQUENCE(1, 100) /* WARNING: Check out the docs for example of time series generation: https://dune.com/docs/query/syntax-differences/ *//* WARNING: Check out the docs for example of time series generation: https://dune.com/docs/query/syntax-differences/ */) AS _u(cycle_series)), next_cycles AS (SELECTcycles.days AS cycle_length,cycle_end_dateFROM cyclesWHEREcycle_end_date > (CURRENT_TIMESTAMP AT TIME ZONE 'UTC')), min_cycles AS (SELECTcycle_length,MIN(cycle_end_date) AS next_cycle_dateFROM next_cyclesGROUP BYcycle_length)SELECTcycle_length AS "Cycle Length (days)",next_cycle_date - INTERVAL '1' day AS "Adjusted Next Cycle Date",(next_cycle_date - INTERVAL '1' day - (CURRENT_TIMESTAMP AT TIME ZONE 'UTC')) AS "Adjusted Time Remaining"FROM min_cyclesORDER BYcycle_length