client.geo.utc_offset

INTEGER, read-only.

Available in all subroutines.

Time zone offset from coordinated universal time (UTC) for client.geo.city.

Values may be negative. Values are given as base-10 numbers of three or four digits in the form (-)HHMM or (-)HMM where H is hours and M is minutes. For example, -230 would be offset of minus two hours and thirty minutes from UTC.

This may be formatted to an ISO 8601 four-digit form (-)HHMM by VCL:

sub client_geo_offset_iso8601 STRING {
return regsub(client.geo.gmt_offset, "^(-?)(...)$", "\10\2");
}

The special value 0 is used to indicate absent data, and the special value 9999 to indicate an invalid region.

Not all timezone offsets are on the hour. For example, in St. John's, Newfoundland, client.geo.utc_offset may be -230 or -330 (depending on daylight savings time).

The following subroutine produces a value in units of hours:

sub client_geo_offset_by_hour FLOAT {
declare local var.n FLOAT;
set var.n = client.geo.gmt_offset;
set var.n %= 100;
set var.n /= 60; # minutes
set var.n += std.atoi(regsub(client.geo.gmt_offset, "..$", "")); # truncate
return var.n;
}

Here, increments of 0.5 correspond to half hours. For example, an offset of 930 will produce a floating point value of 9.5.

Try it out

client.geo.utc_offset is used in the following solution recipes, which show real world use cases. Click RUN to provision a Fastly service, execute the code on Fastly, and see how the function behaves.

Add time zone offset to requests

Divide the world into time bands of custom size and forward time zone data to your origin server.

User contributed notes

We welcome comments that add use cases, ideas, tips, and caveats. All comments will be moderated before publication. To post support questions, visit our support center and we'll find you the help you need.