Sub topic 12
Time Zones and Daylight Saving Time
Assume you are comfortable with cron, systemd timers, shell scripts, and reading logs. The key decision is whether a job follows elapsed time or local wall-clock time.
- An elapsed-time job runs at a fixed interval, such as every 15 minutes.
- A wall-clock job runs at a named local time, such as 09:00 in Berlin.
- UTC is a global time standard with no daylight saving changes.
- A time zone converts UTC into local clock time.
For backups, synchronization, and expiry checks, UTC is usually simpler. For jobs tied to people or business hours, use the business location's time zone explicitly.
The daylight saving time problem
Daylight saving time (DST) changes the local clock twice a year in some regions:
- In spring, the clock jumps forward. A local time such as 02:30 might not exist.
- In autumn, the clock moves backward. A local time such as 02:30 might occur twice.
A schedule that says “run at 02:30” is therefore incomplete unless it also names a time zone and defines what should happen during these transitions.
Many cron implementations skip a job scheduled during a nonexistent time and run a repeated time twice. Details vary by cron implementation and configuration. A duplicate run can be dangerous if the job sends email, charges an account, or modifies external data.
Inspecting and choosing the server time zone
Check the server's configured zone and current clock:
timedatectl
date --iso-8601=seconds
timedatectl list-timezones | grep -E '^(UTC|Europe/Berlin|America/New_York)$'Use an IANA time-zone name, such as UTC, Europe/Berlin, or America/New_York. Do not use an abbreviation such as CST; abbreviations can be ambiguous.
For a server-wide setting, configure the operating system deliberately:
sudo timedatectl set-timezone UTC
timedatectl show --property=Timezone --valueChanging the server zone affects every process that uses local time. Prefer setting a server to UTC and giving a particular job its own explicit zone when needed.
Make the schedule's policy explicit
A cron entry can set TZ for the command environment on implementations that support this feature. Verify the behavior on your distribution before relying on it:
# Run at 09:00 in New York local time
CRON_TZ=America/New_York
0 9 * * * /usr/local/bin/report.sh >> /var/log/report.log 2>&1A safer design is to schedule in UTC and convert times inside the application. For a systemd timer, an explicit zone can be used in the calendar expression on systems whose systemd version supports it:
[Timer]
OnCalendar=*-*-* 09:00:00 America/New_York
Persistent=trueTest the expression before enabling it:
systemd-analyze calendar '*-*-* 09:00:00 America/New_York'If the job must run exactly once per day, make it idempotent. Record the intended local date or event identifier, then ignore a second attempt for the same date. This protects the job even when the scheduler repeats a wall-clock time.
Operating policy
Document these choices for every recurring job:
- The scheduler's time zone.
- Whether a missing local time is skipped, shifted, or retried.
- Whether a repeated local time may run twice.
- Whether the job uses UTC timestamps for logs and stored data.
- How operators will test the next DST transition.
Exercise
A report must run once each business day at 09:00 in New York, while the server runs in UTC. What should you document and protect against?
Show answer
Document the America/New_York time zone, define behavior for skipped and repeated local times, and make the report idempotent so a duplicate scheduler activation cannot produce duplicate results.