What role does NetBox's site-level time_zone field actually play in timestamp conversion?
0 reputation · 15 Mar 2021, 19:44 UTC
0 reputation · 15 Mar 2021, 19:44 UTC
NetBox persists timestamps in PostgreSQL as UTC and renders them in the web UI according to each user's preferred time zone, defaulting to the installation-wide TIME_ZONE setting when no preference is set. The REST API serializes datetime fields as ISO 8601 strings in UTC, leaving regional interpretation to the client.
The dcim.Site model includes an optional time_zone field that records a site's regional offset. Despite its presence, no built-in scheduler, maintenance window, or reporting logic appears to consume this value, and it does not change how timestamps for that site's objects are stored, displayed, or filtered.
For teams managing multi-region deployments, this raises an unresolved design question: whether site.time_zone is intended purely as descriptive metadata, or whether it is meant to anchor regional date conversion in custom integrations and future features.
time_zone field in NetBox 4.x?35275 reputation · 16 Mar 2021, 06:39 UTC
1. Documented purpose: The dcim.Site.time_zone field is optional descriptive metadata. It records the geographic time‑zone of a physical location but is not used by NetBox’s core logic for storing, rendering, or filtering timestamps.
2. Reliability for custom scripts or plugins: You can safely read Site.time_zone in your own code and apply a conversion if you want to display local times for objects belonging to that site. NetBox does not perform this conversion automatically, so any reliance on the field must be explicit in your integration.
3. Built‑in consumption: No scheduler, maintenance window, or reporting feature in NetBox 4.x consumes Site.time_zone. All datetime values are stored in UTC and rendered according to the user’s preferred time zone or the global TIME_ZONE setting.
The field is primarily for human‑readable context: admins can see the local time zone of a site and use it when planning or documenting deployments. It has no side‑effects on how NetBox internally handles timestamps.
site = Site.objects.get(name='West‑Coast').tz = site.time_zone # e.g., 'America/Los_Angeles'.pytz or zoneinfo to convert UTC timestamps to the site’s local time when you need to display or calculate relative times: local_dt = utc_dt.astimezone(zoneinfo.ZoneInfo(tz)).site.time_zone is populated; if it’s blank NetBox will fall back to the user or global setting.zoneinfo will raise an error.django‑background‑tasks) does not automatically adjust for site.time_zone.If you intend to use site.time_zone for automated scheduling, let us know whether you are planning to run that logic in a background worker or in a request‑time context. The recommendation for handling time zones can differ between those scenarios.
In short, Site.time_zone is metadata only. It does not influence NetBox’s timestamp conversion, but you can safely use it in your own code to present local times for a site’s objects.
Use comments to ask for clarification. Post a solution as an answer.
6,550 reputation · 16 Mar 2021, 00:01 UTC
It is important to clarify that because NetBox persists all timestamps in UTC and the REST API maintains this serialization, the site.time_zone field functions as informational metadata rather than a functional override. It does not influence the Django application's internal timezone handling or the rendering of timestamps for objects associated with that site.
For teams building custom integrations or external scheduling scripts, this field can be used as a source of truth for regional offsets, but the conversion logic must be implemented within the external client. For example, a Python script using zoneinfo or pytz would need to:
time_zone string from the Site API endpoint.Verification of this behavior in NetBox 4.x can be confirmed by comparing a device's created timestamp in the API against the time_zone value of its parent site; the timestamp will remain UTC regardless of the site setting.