Sub topic 12
Time zones and daylight saving time
This chapter assumes you can write cron entries and systemd timer units, and that you have read the earlier chapters on schedules and on missed runs. It covers what the clock means to a scheduler, what happens when daylight saving time (DST) shifts that clock, and how to choose schedules that do not depend on it.
Why the clock is a failure source
A schedule such as 30 2 * * * says "at 02:30", but it does not say in which time zone. The scheduler answers that question for you, and the answer changes twice a year in many regions.
DST causes two kinds of failure:
- A skipped hour. In spring, clocks jump forward, for example from 02:00 to 03:00. Local times between 02:00 and 02:59 do not exist on that day. A job set for 02:30 may run late, or not run at all.
- A repeated hour. In autumn, clocks jump back, for example from 03:00 to 02:00. Local times between 02:00 and 02:59 occur twice. A job set for 02:30 may run twice, or once.
A run that is skipped or doubled produces no error. This is the "fails without anyone noticing" pattern from the first chapter. Nightly backups scheduled in the 01:00 to 03:00 window are the usual victims, because many regions change their clocks in that window.
Find out which zone your scheduler uses
Start by checking what the machine believes:
timedatectl
date
date -utimedatectl prints the local time, the UTC time, and the configured zone (the Time zone: line). Comparing date and date -u shows the current offset from UTC.
Cron and systemd both default to the system's local time zone. The system zone is set with timedatectl set-timezone. Some cron implementations read the zone once at startup, so after changing it, restart the cron service (cron on Debian and Ubuntu, crond on RHEL-family systems). Otherwise the daemon may keep using the old zone.
Cron and time zones
Classic cron has no per-job time zone. Every entry runs in the daemon's zone. Some implementations add a CRON_TZ variable that applies to the entries after it:
# Supported by cronie; check `man 5 crontab` on your system first
CRON_TZ=Europe/Berlin
30 8 * * 1-5 /usr/local/bin/morning-report.shSupport varies. If your cron does not understand CRON_TZ, it treats the line as an ordinary environment variable and ignores it for scheduling. The job then runs in the system zone without any warning. Test it on the actual host rather than trusting the syntax.
How cron handles the DST changes
Documented behavior differs between implementations. The crontab(5) man pages for cronie and for Debian's cron both describe special handling of small clock changes. In general:
- After a short forward jump, jobs with a fixed time that fell in the skipped hour are run soon after the change.
- After a short backward jump, jobs with a fixed time run once, not twice.
- Jobs with a wildcard in the hour or minute field, such as
*/15 * * * *, are not adjusted. They run on every matching minute, including during the repeated hour.
Do not depend on this. Read the man page for the version you run, and treat the rules as a safety net.
systemd timers and time zones
An OnCalendar= expression is also interpreted in the system's local zone by default. You can add a zone to the expression:
# /etc/systemd/system/backup.timer
[Unit]
Description=Run the nightly backup
[Timer]
OnCalendar=*-*-* 02:30:00 UTC
Persistent=true
RandomizedDelaySec=5min
[Install]
WantedBy=timers.targetThe trailing UTC pins the schedule to UTC, so the job is unaffected by local DST. You can also write an IANA zone name, such as Europe/Berlin. Support for zone names depends on the systemd version, and systemd-analyze calendar will tell you whether yours accepts them.
Always check an expression before enabling it:
systemd-analyze calendar --iterations=5 "*-*-* 02:30:00 UTC"
systemd-analyze calendar --iterations=5 "*-*-* 02:30:00 Europe/Berlin"The output shows the normalized expression, the next time the timer would elapse in UTC, and the same time in your local zone. With --iterations, it lists several future runs. Running this for a date range that includes a DST change shows how the timer behaves at the transition. This is more reliable than reasoning about it.
To see what the system has actually scheduled:
systemctl list-timers backup.timer
journalctl -u backup.service --utc --since "2026-03-01"The --utc option prints log timestamps in UTC. That removes the ambiguity when you read logs from the repeated hour, where two different events can carry the same local time.
Choose schedules that avoid the problem
You have three practical options, in order of preference.
- Run the server in UTC. UTC has no DST. Every schedule means the same thing all year, logs from different servers line up, and there is no skipped or repeated hour. This is the simplest fix and the usual choice for servers. The cost is that "02:30" means a different local hour in summer and winter for the people who read the reports.
- Pin each job to UTC or a named zone. Use the zone suffix in
OnCalendar=. Use this when the server's zone must stay local, for example because other software depends on it. - Avoid the transition window. If a job must follow local time, schedule it outside the hours where your region changes the clock. Pick 04:30 instead of 02:30. This costs nothing and works with any scheduler.
Jobs defined by an interval do not need any of this. */15 * * * * and a systemd timer using OnUnitActiveSec=15min fire at an interval and do not care what the wall clock says. Systemd's monotonic timers (OnBootSec=, OnUnitActiveSec=) count elapsed time and are not affected by DST at all.
| Schedule type | Example | Affected by DST? |
|---|---|---|
| Fixed local time | `30 2 * * *` | Yes, in the 01:00 to 03:00 window |
| Fixed time pinned to UTC | `OnCalendar=*-*-* 02:30:00 UTC` | No |
| Wildcard interval in cron | `*/15 * * * *` | Not skipped, but runs in the repeated hour |
| Monotonic interval in systemd | `OnUnitActiveSec=15min` | No |
Make the job itself safe
Even with a good schedule, assume a job can run twice or be missed around a transition.
- Be idempotent. A double run must produce the same result as a single run. The earlier chapter on idempotent jobs and atomic writes applies directly here.
- Use a lock. If the repeated hour starts a second run while the first is still going,
flock -nmakes the second one exit. - Do not build file names from local time without a zone. A backup named
db-0230.sql.gzcan be overwritten in the repeated hour. Use UTC in names:date -u +%Y%m%dT%H%M%SZ. - Compute date ranges in UTC. A report for "yesterday" covers 23 or 25 hours on a DST day if it uses local midnight. Use UTC boundaries, or state clearly which zone defines the day.
- Set
TZexplicitly in scripts that parse or print times. Cron's minimal environment may not carry the sameTZas your login shell, so a script that behaves one way in your terminal can behave another way under cron.
Heartbeat monitoring catches what is left. If a job is skipped on the spring night, the monitor reports a missing ping. Give the monitor a grace period of at least an hour on jobs that run in local time, or the monitor itself will raise a false alarm when a run arrives late.
Common errors
- Assuming
CRON_TZworks because the line is accepted. Unsupported variables are silently ignored. Confirm with a test entry that runs within a few minutes and logs its owndate. - Changing the system zone without restarting cron. The daemon keeps its old view of local time until restarted.
- Mixing zones in one log. Some jobs log UTC and others log local time, so incident timelines do not line up. Pick one zone for logs.
- Testing in summer only. A schedule that looks correct today can fail in March or October. Use
systemd-analyze calendarwith a date near the transition, or run the job by hand withfaketimeif it is installed. - Trusting that Persistent=true fixes DST.
Persistent=truecatches up runs missed while the machine was off. It does not repair a calendar expression that points at a non-existent local time.
Exercise
A server runs in Europe/Berlin. A backup timer uses OnCalendar=*-*-* 02:30:00. On the night clocks move from 02:00 to 03:00, the backup does not run as expected. Name two different changes that would prevent this, and say which command you would use to verify the new schedule.
Show answer
Either pin the timer to UTC by writing OnCalendar=*-*-* 02:30:00 UTC (or move the whole server to UTC), or move the job outside the transition window, for example to 04:30:00. Verify with systemd-analyze calendar --iterations=5 "<expression>", which prints the next elapse times in UTC and local time, and check that the dates around the DST change come out as intended. Running systemctl list-timers backup.timer after enabling confirms what the system scheduled.