Add time zone offset to requests
Divide the world into time bands of custom size and forward time zone data to your origin server.
VCL
Use this solution in your VCL service (click RUN below to test this solution or clone it to make changes):
Compute@Edge
Use this solution in your Compute@Edge service:
- Rust
let geo = req.get_client_ip_addr().and_then(geo_lookup).unwrap();
// setting date/time variables let utc_dt = Utc::now(); let local_dt = utc_dt.with_timezone(&geo.utc_offset()); let offset = fastly::geo::FixedOffset::local_minus_utc(&local_dt.offset());
// Add TZ in ISO8601 format req.set_header("tz-offset-iso8601", local_dt.format("%z").to_string()); // Parse the time offset into a decimal number of hours req.set_header("tz-offset-hours", format!("{:.3}", (offset / HOUR))); // Round to a whole hour req.set_header("tz-hour", (offset / HOUR).to_string()); // Round to nearest even hour req.set_header( "tz-evenhour", ((offset as f32 / HOUR as f32 / 2.0).round() as i32 * 2).to_string(), );