function fieldChanged (context, fieldId: string, isDate?: boolean): boolean {
  let oldValue, newValue;

  // If the field contains a date, use a date comparison
  if (isDate){
    oldValue = (context.oldRecord) ? context.oldRecord.getValue({ fieldId }) as Date : null;
    newValue = context.newRecord.getValue({ fieldId }) as Date;
    return (dateValue(oldValue) !== dateValue(newValue));
  } else if (context.oldRecord) {
    oldValue = context.oldRecord.getValue({ fieldId });
  } else {
    oldValue = null;
  }

  // Otherwise compare directly
  return (oldValue != context.newRecord.getValue({ fieldId }));
}

function dateValue(date: Date): number {
  if (isValidDate(date)){
    return date.getTime();
  } else {
    return Number(date);
  }
}

function isValidDate(date: Date): boolean {
  return date && Object.prototype.toString.call(date) === "[object Date]" && !isNaN(Number(date));
}