Simile Bug Resolved!

Simile is a browser app with a great presentation for displaying timelines. See the Simile timeline examples. I first tried Simile at version 1.0 but got frustrated with the many defects it still contained. It’s now at version 2.3 so I thought I would try again but was still stopped by a major defect – it can’t handle BC dates correctly!!

I looked into it and found the issue. Here is an example of what fails:

var objDate = new Date(“Mar 10, 600 BC 01:00:00”);

That’s a major flaw for a timeline app!! The built-in JavaScript date creation fails on BC and negative year dates for Firefox & Chrome but not Internet Explorer (at least IE versions 8 and 9 are OK).

The fix is to first create the desired date object as a non-BC date, then extract the year, make it negative, and finally set the date object to the negative year. I wrote a new function “getDatesBC” to it this way.

Simile coders put in a terrible hack that only allowed BC dates if provided in whole years in the format “yyyy BC”. My fix allows any valid format, including optional month, day, and time and should work for any browser since the exception code is only executed if the date creation fails (therefore IE works just as it did before). The fix is made to the simile-ajax-bundle.js file and is shown below. The parseGregorianDateTime function is re-written and the getDatesBC function is new.

FINAL NOTE: To use BC dates with this fix, specify all dates (including Timeline.createBandInfo dates) in the format MMM DD YYYY BC. Example: Apr 06 0600 BC  or  Apr 6 600 BC. If you leave out the month and day it may still fail.

The compressed code is the original and the non-compressed indented code is the new code for the fix.

SimileAjax.DateTime.parseIso8601DateTime=function(A){try{return SimileAjax.DateTime.setIso8601(new Date(0),A);
}catch(B){return null;
// start of patch
function getDatesBC(myDate) {
  var orig = myDate;
  var isGood;
  try {
    isGood = !isNaN(myDate.getUTCFullYear()); // BC dates may return NaN on getUTC, if non-IE browser.
  } catch (BBB) {
    isGood = false; // BC dates may fail totally on getUTC, if non-IE browser.
  if (isGood) {
    return myDate; // BC date succeeded. Probably IE browser.
  } else {
    var isBC = false;
    orig = orig.replace("B.C.","BC");
    if (orig.indexOf(" BC") != -1) {
      isBC = true;
      orig = orig.replace(" BC","");
    if (orig.indexOf(" -") != -1) {
      isBC = true;
      orig = orig.replace(" -","");
    if (isBC) {
      // BC date failure so special handling here
      if (orig.indexOf(":") == -1) {
        orig = orig + " 00:00:00";
      myDate = new Date(orig);  // Create the date as non-BC date. Should always work.
      BCyear = myDate.getUTCFullYear();
      BCYear = (1 - parseInt(BCyear)); // set the year to negative
      myDate.setUTCFullYear(BCYear); // assign the neg year to the already created date object (this works)
      return myDate; // return the valid BC date object
    } else {
      return myDate; // Date failed for non BC reason so just returned failed date
  if (F==null) {
    return null;
  } else {
    if (F instanceof Date) {
      return F;
    } else {
      F = getDatesBC(F);
      return F;
// end of patch
SimileAjax.DateTime.roundDownToInterval=function(E,B,I,K,A){var F=I*SimileAjax.DateTime.gregorianUnitLengths[SimileAjax.DateTime.HOUR];
var J=new Date(E.getTime()+F);
var C=function(L){L.setUTCMilliseconds(0);

Leave a Reply

Your email address will not be published. Required fields are marked *