How to test dates and time zones in an API

Date bugs are the ones that pass every test in October and break on the last Sunday of March. An order placed at 23:30 in Kyiv lands on the next day in UTC reports. A "due tomorrow" filter runs on the server's time zone. A timestamp without an offset is read as local time by one client and UTC by another. A few targeted tests catch most of them, and you can run them any day of the year.

Check the format of every timestamp

JavaScript
const moment = require('moment');
const order = pm.response.json();

pm.test('createdAt is ISO 8601 with an offset', () => {
  pm.expect(order.createdAt).to.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$/);
  pm.expect(moment(order.createdAt, moment.ISO_8601, true).isValid()).to.be.true;
});

The regular expression rejects 2026-11-22 10:00:00 (no T, no offset) and 1763805600 (a number where a string was promised). Strict parsing with moment rejects impossible values like 2026-02-30.

Same moment, different offsets

These three are the same instant:

Output
2026-11-22T10:00:00Z
2026-11-22T12:00:00+02:00
2026-11-22T05:00:00-05:00

Create a record with each (a CSV with one column and --data works well) and read it back. The API should store and return the same instant every time, whatever offset it uses in the response:

JavaScript
const moment = require('moment');
const sent = pm.iterationData.get('startsAt');
const stored = pm.response.json().startsAt;
pm.test('same instant', () => pm.expect(moment(stored).valueOf()).to.equal(moment(sent).valueOf()));

A timestamp sent without any offset should get a 400, unless your API documents which zone it assumes.

Inputs worth a request each

InputWhat it catches
2026-11-22T23:30:00+02:00"today" computed in UTC is already tomorrow
2026-11-30T23:59:59Z and 2026-12-01T00:00:00Zmonth boundaries in reports and filters
2026-12-31T23:30:00-05:00the year changes in UTC but not locally
2028-02-29leap day; and 2027-02-29 must be rejected
2026-03-29T03:30:00 in Europe/Kyiva local time that doesn't exist (DST gap)
2026-10-25T03:30:00 in Europe/Kyiva local time that happens twice
1970-01-01T00:00:00Z, 9999-12-31zero values and "never expires" sentinels

Filters with dates

Range filters are where off-by-one bugs hide. For ?from=2026-11-01&to=2026-11-30:

  • Is to inclusive? An order at 2026-11-30T15:00:00Z should be in the November report. If to is parsed as midnight at the start of the 30th, it isn't.
  • Whose midnight? For a user in New York, November starts five hours after it does in UTC.
JavaScript
const items = pm.response.json().items;
pm.test('includes the last day of the month', () => {
  pm.expect(items.some((order) => order.createdAt.startsWith('2026-11-30'))).to.be.true;
});

Seed one record late on the last day of the range, and one just after it, and check one is in and the other isn't.

Date-only fields

A birthday or an invoice due date is a calendar date, not an instant. It should come back as 2026-11-22, not as 2026-11-21T22:00:00.000Z because the server converted local midnight to UTC. That bug makes dates move by a day for half the world.

JavaScript
pm.test('dueDate is a plain date', () => {
  pm.expect(pm.response.json().dueDate).to.match(/^\d{4}-\d{2}-\d{2}$/);
});

Make "now" testable

Tests that depend on the current time ("expires in 7 days") should compute expectations at run time, not hard-code them:

JavaScript
const moment = require('moment');
const expires = moment(pm.response.json().expiresAt);
pm.test('expires in about 7 days', () => {
  pm.expect(expires.diff(moment(), 'hours')).to.be.within(167, 168);
});