hebcal/hebcal-js

HDate.prototype.next and HDate.prototype.prev don't copy lat and long properties

lexich opened this issue · 1 comments

Main problem is in computing candleLighting

Event.prototype.candleLighting = function() {
    var date = this.date.next();
    if (this.LIGHT_CANDLES) {
        return new Date(date.sunset() - (Event.candleLighting * 60 * 1000));
    } else if (this.LIGHT_CANDLES_TZEIS) {
        return date.getZemanim().tzeit;
    }
    return null;
};

date has lat and long equals 0; and computing executes independs of locations

Quick monkey patch decision.

var methods = ["next", "prev"];

function patch(func) {
  return function() {
    var result = func.apply(this, arguments);
    result.lat = this.lat;
    result.long = this.long;
    return result;
  };
}

function patchHebcal(Hebcal) {
  for (var i = 0; i < methods.length; ++i) {
    var name = methods[i];
    Hebcal.HDate.prototype[name] = patch(Hebcal.HDate.prototype[name]);
  }
};