diff --git a/lib/graphql/resolvers/index.ts b/lib/graphql/resolvers/index.ts index 05ae28b..128b725 100644 --- a/lib/graphql/resolvers/index.ts +++ b/lib/graphql/resolvers/index.ts @@ -134,7 +134,17 @@ export const resolvers = { sql`${matches.scoreFtHome} IS NULL`, eq(matches.isQualiPlayoff, false), )) - .orderBy(asc(matches.date), sql`SPLIT_PART(${matches.timeLocal}, ' ', 1) ASC NULLS LAST`, asc(matches.id)) + .orderBy( + sql`CASE + WHEN ${matches.timeLocal} LIKE '% UTC%' + THEN ${matches.date}::date + + SPLIT_PART(${matches.timeLocal}, ' ', 1)::time + - (REPLACE(SPLIT_PART(${matches.timeLocal}, ' ', 2), 'UTC', '') || ' hours')::interval + ELSE ${matches.date}::date + + COALESCE(NULLIF(SPLIT_PART(${matches.timeLocal}, ' ', 1), '')::time, '00:00'::time) + END ASC NULLS LAST`, + asc(matches.id), + ) .limit(limit) return Promise.all(rows.map(hydrateMatch)) } catch (e) { if (isMissingTable(e)) return []; throw e }