hebcal / hebcal-js

⛔️ DEPRECATED - a perpetual Jewish Calendar (JavaScript)
GNU General Public License v3.0
123 stars 40 forks source link

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

Closed lexich closed 8 years ago

lexich commented 9 years ago

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

lexich commented 9 years ago

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]);
  }
};