Date and time testing: time zones, DST, midnight
Most date and time bugs stay hidden when the tester and the server share one time zone and the test runs in the middle of an ordinary day. This guide lists the conditions that bring them out, with dates for 2027 you can use as test data.
For the rules of a single date input (today or later, impossible dates, formats) see date field test cases. This page covers what happens to a date or a time after it is entered.
Set up before you test
Write down three things about the system: which time zone the server works in, which one each test user is in, and what the stored value is (a moment with an offset, or a bare date and a wall-clock time). The third one decides which of the cases below apply. If nobody on the team knows, the request body in the browser's Network tab shows what the page sends.
Ways to move the clock without waiting for midnight:
- Change the time zone of the operating system and reload the page.
- In Chrome developer tools, open the Sensors panel and override the location. The time zone of the page changes with it, the rest of the computer stays as it was.
- For a script or an API client, set the
TZvariable:TZ=America/New_York node test.js. - Change the system date to reach a daylight saving day or a month end. Sites over HTTPS may refuse to load when the clock is far off, so move it by days, not years.
Which day is "today"?
A user in Los Angeles opens a form at 23:30 on March 1, 2027. In UTC that moment is 07:30 on March 2. A server that works in UTC already counts March 2 as today, so a rule such as "not in the past" gives different answers on the page and on the server. In winter the two dates differ for 8 hours of every day in Los Angeles, from 16:00 to midnight. In Tokyo they differ for 9 hours, from midnight to 09:00, and there the server is a day behind.
| Test | Expected | What it catches |
|---|---|---|
| User's zone behind UTC, local evening, pick today's local date | The page and the server agree | The server rejects "today" because its own day has already changed |
| User's zone ahead of UTC, local morning, pick today's local date | The same | The server accepts yesterday, or shows the record under the previous day |
| Save a date, read it back in a zone behind UTC | The same date | A date stored as midnight UTC and shown in local time moves one day back |
| Two users in different zones open the same record | Each sees the same moment in local time, or one clearly labelled zone | A time shown with no zone that each reader takes for their own |
The third row comes from one line of code. A date with no time, such as
2027-03-14, is read by JavaScript as midnight UTC. In New York that moment is 19:00 on
March 13, so a birthday or a deadline is displayed a day early for everyone west of Greenwich and
correctly for everyone east of it. A team in Europe or Asia will not see it on their own machines.
Daylight saving time
Twice a year a day in a zone with daylight saving time is 23 or 25 hours long. The 2027 dates:
| Zone | Clocks go forward | Clocks go back |
|---|---|---|
New York (America/New_York) | March 14: 02:00 becomes 03:00 | November 7: 02:00 becomes 01:00 |
Berlin (Europe/Berlin) | March 28: 02:00 becomes 03:00 | October 31: 03:00 becomes 02:00 |
Between March 14 and March 28 New York and Berlin are 5 hours apart instead of the usual 6. Schedule a meeting between the two inside those two weeks and compare the time each side sees.
| Test (New York, 2027) | Expected | What it catches |
|---|---|---|
| Create something at 02:30 on March 14 | Rejected, or moved to 03:30 with a notice | A time that does not exist is stored and later displayed as something else |
| Create something at 01:30 on November 7 | The app asks which 01:30, or documents which one it takes | The time occurs twice; reminders fire an hour early or late |
| Duration from 01:00 to 03:00 on March 14 | 1 hour | Subtracting clock readings gives 2 |
| Duration from 01:00 to 03:00 on November 7, starting at the first 01:00 | 3 hours | The same subtraction gives 2 |
| Daily event at 09:00, created March 13, viewed March 14 | 09:00 | "Next day" computed as plus 24 hours lands on 10:00 |
| Daily totals or a per-day limit on March 14 and November 7 | The day covers 23 and 25 hours | A day assumed to be 24 hours drops an hour or counts it twice |
Add one zone with no daylight saving time (Tokyo, or Phoenix inside the United States) to check that the app does not shift its times along with the others.
Offsets that are not whole hours
India is at UTC+5:30 and Nepal at UTC+5:45. Code that stores the offset as a whole number of hours shows users there a time 30 or 45 minutes off. Kiritimati is at UTC+14 and Honolulu at UTC−10: the clocks show the same time and the calendar date differs by one. A zone picker limited to −12…+12 cannot represent the first of them.
Date arithmetic
| Operation | Question to ask | What code often does |
|---|---|---|
| January 31, 2027 plus one month | February 28, or an error? | JavaScript's setMonth returns March 3 |
| February 29, 2028 plus one year | February 28, 2029? | March 1, 2029 |
| Monthly subscription started on the 31st | Which day in a 30-day month, and does it return to the 31st afterwards? | Drifts to the 28th and stays there |
| Age or "N days left" | Counted in calendar days of which zone? | Milliseconds divided by 86,400,000, off by one near midnight and on daylight saving days |
The expected result in the first three rows is a product decision. If the specification does not answer the question, the missing answer goes into the report along with what the code does now.
Ranges, filters and sorting
- A filter "from March 1 to March 31" should include records made on March 31. When the end date is turned into midnight at the start of that day, the whole last day drops out. Create a record at 23:00 on the last day and run the filter.
- The same record near a month end can belong to different months for different readers: 23:00 on March 31 in New York is 03:00 on April 1 in UTC. Check which month a report puts it in, and whether the on-screen list and the exported file agree.
- Sorting by a time stored as text breaks when formats are mixed:
9:00sorts after10:00, and values with different offsets sort by their digits, not by the moment. - For two ranges that touch (one ends at 10:00, the next starts at 10:00) the rule has to say whether that is an overlap. Test the exact touch and one minute to each side of it.
Formats in requests and responses
A time with no offset, such as 2027-03-14T09:00:00, does not say whose 09:00 it is.
Send the same moment three ways (with Z, with an offset such as -05:00, and
with nothing) and compare what is stored. Read the value back: if the API accepts an offset and
returns the time without one, the client can no longer tell which moment was stored.
Edge values to send where the format allows them: 24:00, 00:00 as an end
time, 12:00 AM and 12:00 PM in a 12-hour field (the first is midnight), seconds and milliseconds when
the rule speaks only of minutes, and a date in another calendar order.
The device clock
Set the clock on the test device ten minutes fast, then ten minutes slow. Countdown timers and session timeouts that rely on the device show wrong values or log the user out early. Anything with a deadline, such as a sale end or a password reset link, should be decided by the server's clock: move the device clock past the deadline and try the action. Expected: the server's answer does not change.
Open the API exercise
More guides: date field test cases · REST API test cases · all guides