Skip to Content
Octopus Energy Packages

Resolve a Property Timezone

Resolve an IANA timezone from property coordinates on the server

A property's measurement calendar may not match the viewer's timezone. When an application serves properties across multiple timezones, resolve the property's IANA timezone before creating the timeframe or fetching measurements.

This guide builds on Avoid Empty Charts and keeps the existing client-rendered overview. The route performs only the geographic timezone lookup, then passes the resulting string into the complete measurements pipeline.

What you'll build

By the end of this guide, the server will resolve an IANA timezone from Kraken property coordinates. The client overview will use that timezone for its anchor date, timeframe, measurement requests, aggregation, and Coral display.

Use configuration when possible

If every property served by a deployment uses one timezone, configure that IANA timezone directly. A geographic lookup is useful when one application serves properties across multiple timezones.

Choose a coordinate lookup

Kraken exposes property coordinates, but it does not expose an IANA timezone. Use a geographic timezone library or service to map latitude and longitude to a timezone.

This example uses @photostructure/tz-lookup:

pnpm add @photostructure/tz-lookup

Keep the lookup on the server

The library embeds geographic boundary data, so keep it on the server rather than adding it to the client bundle.

Resolve the property timezone

Query only the coordinates needed by the lookup. Throw when the property or its coordinates are unavailable instead of silently substituting the server or browser timezone.

lib/measurements/resolve-property-timezone.ts
import timezoneLookup from "@photostructure/tz-lookup";
import { getUserScopedGraphQLClient } from "#/lib/auth/server";
import { graphql } from "#/lib/graphql";

const propertyCoordinatesQuery = graphql(`
  query getPropertyCoordinates($propertyId: ID!) {
    property(id: $propertyId) {
      coordinates {
        latitude
        longitude
      }
    }
  }
`);

export async function resolvePropertyTimezone(propertyId: string): Promise<string> {
  const client = getUserScopedGraphQLClient();
  const { property } = await client.request(propertyCoordinatesQuery, {
    propertyId,
  });

  if (!property) {
    throw new Error(`Property not found: ${propertyId}`);
  }

  const { coordinates } = property;
  if (coordinates?.latitude == null || coordinates?.longitude == null) {
    throw new Error(`Property coordinates are missing: ${propertyId}`);
  }

  return timezoneLookup(coordinates.latitude, coordinates.longitude);
}

Keep this module behind a server boundary. getUserScopedGraphQLClient represents your application's authenticated server client. Use the equivalent integration in your app. The browser only needs the resolved IANA timezone string.

Pass the timezone from the route

Resolve the timezone on the server, then pass it to the client overview with the route parameters.

app/accounts/[accountNumber]/properties/[propertyId]/consumption/page.tsx
import { ConsumptionOverview } from "./_components/consumption-overview";
import { resolvePropertyTimezone } from "#/lib/measurements/resolve-property-timezone";

export default async function ConsumptionPage({
  params,
}: PageProps<"/accounts/[accountNumber]/properties/[propertyId]/consumption">) {
  const { accountNumber, propertyId } = await params;
  const timezone = await resolvePropertyTimezone(propertyId);

  return (
    <ConsumptionOverview
      accountNumber={accountNumber}
      propertyId={propertyId}
      timezone={timezone}
    />
  );
}

Use the timezone for the anchor date

Accept the timezone in the client overview and pass it to anchorDateQueryOptions. This makes the fallback date query use the same local calendar as the final timeframe.

_components/consumption-overview.tsx
"use client";

type Props = {
  accountNumber: string;
  propertyId: string;
  timezone: string;
};

export function ConsumptionOverview({ accountNumber, propertyId, timezone }: Props) {
  const anchorDateQuery = useQuery(
    anchorDateQueryOptions(client, {
      enabled: !storedTimeframe.date,
      interval: storedTimeframe.interval,
      marketSupplyPoints: marketSupplyPointsQuery.data,
      period: storedTimeframe.period,
      propertyId,
      timezone,
    }),
  );

  // Create the timeframe and measurement query below.
}

Create the timeframe with the timezone

Pass the same value to useTimeframe. The resulting timeframe carries the resolved timezone alongside its date boundaries.

_components/consumption-overview.tsx
const [timeframe, timeframeActions] = useTimeframe({
  defaults: {
    date: storedTimeframe.date ?? anchorDateQuery.data,
  },
  storage: timeframeStorage,
  timezone,
});

Continue passing that timeframe to measurementsQueryOptions. Measurement requests include timeframe.timezone, and timeframe changes trigger queries with boundaries resolved in the property calendar.

_components/consumption-overview.tsx
const measurementsQuery = useQuery(
  measurementsQueryOptions(client, {
    marketSupplyPoints: marketSupplyPointsQuery.data,
    propertyId,
    timeframe,
  }),
);

Keep aggregation and display aligned

Pass the same timeframe to createMeasurementsOverview, then pass its timezone to Coral's card. This keeps fetched records, chart buckets, labels, tooltips, and table dates on one calendar.

_components/market-supply-point-card.tsx
const overview = createMeasurementsOverview(measurements, {
  preferences,
  timeframe,
});

return (
  <EnergyOverviewCard
    {...card}
    currency="GBP"
    dateLocale={enGB}
    locale="en-GB"
    timezone={timeframe.timezone}
  >
    {/* Render the card content. */}
  </EnergyOverviewCard>
);

Implementation checkpoint

The server now resolves one IANA timezone string from property coordinates. The client uses that value when resolving the anchor date and timeframe, while the measurement query, aggregation, and Coral card consume the resulting shared timeframe.

The important invariant is consistency: fetching, transforming, and displaying the measurements must all use the same timezone.

On this page