Open to work

Why My Demo Apps Are Tested on 31 December and 1 April

A fixed clock means your test decides what "now" is instead of letting the computer's real date leak in. I use it because apps that read the date often work fine on an ordinary Tuesday and break on a Sunday night, the first of a month or 1 April. Running the same test on awkward dates found real bugs in my demo apps that normal testing missed.

What is wrong with testing only on today's date?

Today is a random day. Most days look alike, so a test run on any of them passes through the same paths. The awkward days are rare, which is exactly why bugs hide there.

I build web app demos for Indian small businesses. They show dashboards with "this week", orders with a delivery window, invoices by financial year. Every one of those features reads the clock. If I never change the clock, I am testing a tiny slice of how the app can behave.

How were the 25 apps tested?

Each app has a scripted end-to-end test using Playwright in a headless browser. The script clicks every button and checks that the screen responds. That already catches broken buttons.

Pitchsparrow builds its slot grid from today's date: exactly the kind of screen I check on fixed dates like 31 December and 1 April.

The apps were built with AI coding assistants, which I directed and reviewed. That makes tests more important, not less: generated code can look right and still be wrong in a corner. So I added what I call a date audit. I run each test several times with the page clock fixed at different moments:

  • Sunday at 23:30
  • The 1st of a month at 06:10
  • 31 December
  • 28 February
  • 1 April

These are the days where week boundaries, month boundaries, year boundaries, short months and the Indian financial year start all show up.

Which real bugs did it find?

Four, and all were real.

  • A dashboard alert broke in the first weeks of a month. It only showed up in the first weeks, so a test run mid-month never saw it.
  • An order stopped being trackable after 6:30 PM. A normal daytime test would never see it.
  • A "this week" interview list was empty on weekends. The list only made sense on weekdays. In a hiring pipeline app, that is a very visible failure.
  • A financial-year filter hid old invoices on 1 April. On the first day of the new financial year, older invoices vanished from view.

None of these were exotic. They are the kind of bug a real user hits on their first Monday, and a recruiter or client trying a demo might hit too.

How do you make the clock injectable?

The idea is simple: do not call new Date() deep inside your logic. Pass the date in, or pass a function that gives it. Then a test can pass any date it likes.

// A tiny injectable clock
function createClock(fixedIso) {
  return {
    now() {
      return fixedIso ? new Date(fixedIso) : new Date();
    }
  };
}

// Business logic takes the clock as an argument
function financialYearStart(clock) {
  const d = clock.now();
  const year = d.getMonth() >= 3 ? d.getFullYear() : d.getFullYear() - 1;
  return new Date(year, 3, 1); // 1 April
}

// In tests
const clock = createClock("2027-04-01T06:10:00");
console.log(financialYearStart(clock).toDateString()); // Thu Apr 01 2027

const lateMarch = createClock("2027-03-31T23:30:00");
console.log(financialYearStart(lateMarch).toDateString()); // Wed Apr 01 2026

In the real app, you create the clock with no argument and it uses the real time. In a test, you give it a date. The logic never knows the difference.

The same function shows the 1 April problem clearly. One minute before midnight on 31 March belongs to the old year; one minute after belongs to the new one. That edge is where filters misbehave.

What about fixing the clock in the browser?

The injectable clock works when you control the code. For a finished app, or for an end-to-end test, you can also fix the clock in the browser. Playwright can set the page clock, so the app's own calls to the current time return the date you chose. That is how my date audit runs each scripted test on each date without changing the app.

The same trick helps in video work. When I record walkthrough videos of the apps frame by frame, I control the page clock so the recording is steady. I wrote about that in the post on creative automation.

Why should designers care?

Designers hand over states: empty, loading, error. Time-based states belong on that list. What does the "this week" screen look like on Sunday? What does the order tracker show at 7 PM? If you do not design these, the developer, or an AI assistant, will guess.

I like asking one question in every review: what does this screen show at midnight, on the first of the month, and on the last day of the year?

What are the trade-offs?

A date audit multiplies test time by the number of dates. For 25 apps that is noticeable, so I keep the list short and choose dates for a reason. Injecting a clock also takes a bit of discipline, because one stray new Date() in a corner can undo it. And time zones and daylight saving add more edge cases; my apps target one region, which keeps things simpler.

Key takeaways

  • A fixed clock lets tests choose "now" instead of inheriting today's date.
  • Awkward dates reveal bugs ordinary days hide: week ends, month starts, year ends, short months, the 1 April financial year.
  • Pass the clock into your logic rather than calling new Date() everywhere.
  • Design time-based states, not just empty and error ones.
  • Keep the list of test dates short and deliberate.

See the apps that were tested this way on the work page, and read what I learned designing them.

Questions

Questions

What is a fixed clock in testing?

It is a way to make your code or test see a chosen date and time instead of the real one. That lets you test how an app behaves on a Sunday night, on 31 December or on 1 April, any day of the year.

Why test on 1 April in an Indian app?

The Indian financial year starts on 1 April. Filters, reports and invoice lists that depend on the financial year can behave differently on that exact day, and a normal test run in the middle of the year never shows it.

Do I need a library to fix the clock?

Not always. You can pass a clock function into your code, as in the example below. Test tools such as Playwright can also fix the page clock for a browser test.

Nikhil Dadhich

Nikhil Dadhich is an AI Creative Technologist in Jaipur, India. He designs and builds AI image and video production workflows, creative automation and web apps, with a background in graphic design, UI/UX and motion since 2017. More about me.