Dates Shown As A Dash Or Server Time - edmozley/freeitsm GitHub Wiki

Dates shown as a dash, or in server time

Fixed in 3.0.0. Found while making Assets → Users work on a phone - not reported, but present since the date sweep of #1195 (before 1.0.0).

What you saw

  • Assets → Users: open anybody holding equipment and the Assigned column said — on every row, for every person. The dates were stored all along.
  • CMDB → an object's page and Knowledge → Assistant: dates and times were shown as the server stores them - 2026-10-02 10:00:00, in UTC - rather than in your own date format and time zone like the rest of the app.

What was wrong

FreeITSM formats every date in the browser with one shared set of functions in assets/js/tz.js: fmtDate(), fmtTime() and fmtDateTime(). They read the stored UTC value and show it in the analyst's own zone and format.

All three pages defined a helper with the same name at the top level of their own script:

function fmtDate(d) {             // Assets → Users
    ...
    return isNaN(dt) ? '—' : fmtDate(dt);     // meant: the shared one
}

A top-level function declaration in a browser script becomes a property of window - so it replaces the shared function of the same name for the whole page. The last line, written to hand over to the shared formatter, called the page's own function instead:

Page What the self-call did What you saw
Assets → Users (fmtDate) called itself with a Date object, which its own parser cannot read —
CMDB object (fmtDateTime) called itself with the same string, over and over, until the browser's stack overflowed; the catch then returned the input the raw UTC string
Knowledge assistant (fmtDate) the same the raw UTC string

The commit that introduced them (#1195, the sweep that moved every date onto the shared formatters) renamed a fourth copy on Tickets → Triage for exactly this reason and missed these three.

The fix

Each page's helper now has its own name - fmtAssigned, fmtWhen, kaFmtDate - so it no longer replaces the shared function, and it calls window.fmtDate / window.fmtDateTime explicitly.

File Change
asset-management/users.php fmtDate → fmtAssigned
cmdb/object.js (and its ?v= in cmdb/object.php) fmtDateTime → fmtWhen
knowledge/assistant/index.php fmtDate → kaFmtDate

How it was verified

  • Assets → Users, a person holding four items, at desktop width: the Assigned column read — | — | — | — before and 13.08.2026 | 13.08.2026 | 13.08.2026 | 13.08.2026 after.
  • On the real CMDB object and knowledge assistant pages, each renamed helper and the shared formatter were handed the same stored value, 2026-10-02 10:00:00, and returned the same converted result (02.10.2026 12:00 / 02.10.2026) - and the shared function on the page is tz.js's, not a replacement.
  • A sweep for any other top-level fmtDate / fmtTime / fmtDateTime found one more, in the rota, which formats a plain HH:MM:SS string and never calls the shared function - harmless, left alone.

For developers

🔴 Never declare a top-level function called fmtDate, fmtTime, fmtDateTime or parseUTCDate in a page script. It does not sit beside tz.js's - it replaces it for everything on the page. Inside an IIFE or a module it is fine. See Timezones and Time Handling.

Related