gtoubiana / acte

Une librairie JavaScript qui simplifie la recherche généalogique.
http://gtoubiana.github.io/acte/
MIT License
0 stars 0 forks source link

Exemples de code pour .variable() #243

Closed gtoubiana closed 4 years ago

gtoubiana commented 7 years ago
    acte.Jour.prototype.variable = function () {
      function variable(v) {
        const vari = this.variables[v].od;
        return new acte.Jour(vari);
      }

      return variable;
    }();

console.log(new acte.Jour('9/5/1846',false).variable('julien').gregorien());

et

var obj = {
  a: 1,
  ab: {
    b: 2,
    c: 3,
    cd: {
      d: new Date(),
      e: 5,
    },
  },
};

var variable = function(a) {
  var ar = a.split(".");
  var al = ar.length;
  var that = obj,
    i = 0;
        /*
  for (i ; i < al; i++) {
    that = that[ar[i]];
  }
    */
    while (al--) {
    that = that[ar[i]];
        i++;
  }
  if (that instanceof Date && typeof that.getMonth === 'function') {
    alert(a + " = " + that);
  } else {
    alert(a + " ("+that + ") n'est pas une date !");
  }
};

variable("ab.cd.d");
variable("ab.c");
gtoubiana commented 7 years ago

ce qui donne:

    acte.Jour.prototype.variable = function () {
      function variable(a) {
        var that = this.variables, i = 0, result;
        var ar = a.split(".");
        var al = ar.length;
        while (al--) {
          that = that[ar[i]];
          i++;
        }
        if (that instanceof Date && typeof that.getMonth === 'function') {
          result = that;
        } else {
          result = '';
        }
        return new acte.Jour(result);
      }
      return variable;
    }();
    return acte;
  }

  return umdCallback;
}());

console.log(new acte.Jour('9/5/1846',false).variable('julien.od').gregorien());
gtoubiana commented 7 years ago

Comment préserver les données issues de age() ou periode(), si je fais un new acte.Jour() ???

gtoubiana commented 7 years ago

Changer gregorien.od => gregorien.date, julien.od => julien.date. Ajouter age.min, age.moyen, age.max, (ou naissance.min, naissance.moyenne, naissance.max), periode.debut, periode.fin, periode.duree ?

gtoubiana commented 7 years ago
    acte.Jour.prototype.variable = function () {
      function variable(a) {
        var that = this.variables;
        var i = 0;
        var ar = a.split(".");
        var al = ar.length;
        while (al--) {that = that[ar[i]]; i++;}
        var result = (that instanceof Date && typeof that.getMonth === 'function') ? that : '';
        return new acte.Jour(result);
      }
      return variable;
    }();