Skip to content

Bug: DateTimeUtils.UTCDateTimeToString month is off-by-one #424

@kevinelliott

Description

@kevinelliott

Summary

In lib/DateTimeUtils.ts, UTCDateTimeToString(dateString, timeString) parses a DDMMYY date string and passes the month directly to Date.prototype.setUTCMonth. JavaScript months are 0-indexed (January = 0, December = 11), but ACARS date strings use the conventional 1-12 numbering, so every decoded date is shifted forward by one month.

Affected code

lib/DateTimeUtils.ts:11-15

public static UTCDateTimeToString(dateString: string, timeString: string) {
  let utcDate = new Date();
  utcDate.setUTCDate(+dateString.substr(0, 2));
  utcDate.setUTCMonth(+dateString.substr(2, 2));   // <-- 1-12 passed where 0-11 expected
  if (dateString.length === 6) {
    utcDate.setUTCFullYear(2000 + +dateString.substr(4, 2));
  }
  ...
}

Reproduction

DateTimeUtils.UTCDateTimeToString('150226', '1230');
// Returns "..., 15 Mar 2026 12:30:00 GMT"  <-- should be 15 Feb 2026

Suggested fix

utcDate.setUTCMonth(+dateString.substr(2, 2) - 1);

Order of setUTCDate / setUTCMonth / setUTCFullYear is also fragile when the current real-world date is e.g. the 31st (setting month to a 30-day month rolls the day forward). Constructing the date in one shot via Date.UTC(year, month-1, day, ...) would be safer.

Likely related decoders affected: any plugin that calls UTCDateTimeToString for OOOI (OUT/OFF/ON/IN) or POSRPT messages.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions