client.geo.utc_offset

INTEGER, read-only.

Available inall 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 code examples. Examples apply VCL to real-world use cases and can be deployed as they are, or adapted for your own service. See the full list of code examples for more inspiration.

Click RUN on a sample below 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.