Show 2 Times from Different Time Zones in Week and Day View in Thunderbird Lightning Extension

1.2k views Asked by At

The Thunderbird Lightning extension shows the time on the left side of the Week and Day views as shown here...

Screenshot

I would like the time to show 2 different time zones (e.g. local time and Pacific Time) as shown here...

Modified

Is there a configuration parameter to do this? Is there another extension which can tweak this? If not, how do I hack the Thunderbird extension to do this?

For reference, Outlook has this functionality. Also, this answer shows how to hack the Lightning extension.

2

There are 2 answers

0
Nathan On BEST ANSWER

I didn't solve the problem for the general case. I simply caused the time to be displayed in the current time zone and the previous hour to be displayed. In my case, the current time zone is USA Mountain time and the previous hour ends up being USA Pacific time.

Screenshot

The file calendar-multiday-view.xml in the following jar file must be edited while Thunderbird is not running.

C:\Users\nreynold.ORADEV\AppData\Roaming\Thunderbird\Profiles\profile\extensions\{e2fda1a4-762b-4020-b5ad-a41df1933103}\chrome.jar

The method makeTimeBox() must be changed as indicated by comments:

function makeTimeBox(timestr, time2str, size) {             // Add time2str parameter
   var box = createXULElement("box");
   box.setAttribute("orient", orient);
   box.setAttribute("align", "left");                       // Add

   if (orient == "horizontal") {
      box.setAttribute("width", size);
   } else {
      box.setAttribute("height", size);
   }

   var label = createXULElement("label");
   label.setAttribute("class", "calendar-time-bar-label");
   label.setAttribute("value", timestr);
   label.setAttribute("style", "color: #4080C0; font-weight: bold;");   // Replace "align"

   box.appendChild(label);

   var label = createXULElement("label");                   // Add
   label.setAttribute("class", "calendar-time-bar-label");  // Add
   label.setAttribute("value", time2str);                   // Add

   box.appendChild(label);                                  // Add

   return box;
}

Add the following method after makeTimeBox().

function makeTime(hour) {
   var h = hour % 12;

   if (h == 0)
      h = 12;

   var s = hour >= 12 ? " pm" : " am";
   var result = h + s;

   return result;
}

Remove the following line which appears a few lines below makeTimeBox()

var formatter = Components.classes["@mozilla.org/intl/scriptabledateformat;1"].
                getService(Components.interfaces.nsIScriptableDateFormat);

Change the following line...

var timeString;

... to be ...

var timeString, time2String;

About 25 lines lower, replace the following lines...

timeString = formatter.FormatTime("",
                                  Components.interfaces.nsIScriptableDateFormat.timeFormatNoSeconds,
                                  theHour, 0, 0);
box = makeTimeBox(timeString, durPix);

... to be ...

timeString = makeTime(theHour) + " MT";

ptHour  = theHour - 1;
ptHour += 23;
ptHour %= 24;
ptHour += 1;

time2String = makeTime(ptHour) + " PT";
box = makeTimeBox(timeString, time2String, durPix);
0
Philipp Kewisch On

I am not aware of any existing add-ons that do this, but I can tell you how it is done. First of all create a typical skeleton Thunderbird extension, in the Firefox world this is called a "legacy" extension in case you are searching for docs. It should contain an install.rdf and a chrome.manifest. I'm assuming you choose view-zones as the identifier in chrome.manifest.

Next you need to create a CSS file that will allow you to override the calendar-time-bar binding. Note that with this method there can only be one extension that overrides the binding. The contents will look like this:

calendar-time-bar { 
    -moz-binding: url(chrome://view-zones/content/bindings.xml#calendar-time-bar) !important;
}

This will override the time bar with your binding, which you will create in the bindings.xml file. It extends the builtin time bar, but adds some code after the relayout to add those extra labels. The CSS file needs to be referenced in the chrome.manifest file with a style directive and can extend chrome://calendar/skin/calendar-views.css. Then you will have to create the xml file for chrome://view-zones/content/bindings.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
   - License, v. 2.0. If a copy of the MPL was not distributed with this
   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

<bindings id="calendar-multiday-view-bindings"
          xmlns="http://www.mozilla.org/xbl"
          xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
          xmlns:xbl="http://www.mozilla.org/xbl">
  <binding id="calendar-time-bar" 
           extends="chrome://calendar/content/calendar-multiday-view.xml#calendar-time-bar">
    <implementation>
      <method name="relayout">
        <body><![CDATA[
          this.__proto__.__proto__.relayout.call(this);
          let XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
          let topbox = document.getAnonymousElementByAttribute(this, "anonid", "topbox");
          for (let box of topbox.childNodes) {
            let timelabel = box.appendChild(document.createElementNS(XUL_NS, "label"));
            timelabel.setAttribute("value", "10:00 PT");
          }
        ]]></body>
      </method>
    </implementation>
  </binding>
</bindings>

I've left the label static for now, but you can think of some logic that would change the "10:00 PT" to the actual time based on the other label or the same algorithm used in the actual method. You can also add classes and styling to make it look different.

That said, maybe you'd be interested in adding this feature to core Lightning instead? I think it would be a nice addition. I'm pretty sure we had a bug open for this but I can't find it at the moment, so if you are interested maybe you could file a bug and I can give you more information on how to get set up. In that case it would be a matter of changing the binding to show more than one label and adding user-visible preferences to be able to chose the timezone.