js method chaining tests - d+df
by toubia95
JavaScript
(function (bms, undefined) {
"use strict";
bms.constantes = {
m: ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"]
};
bms.id = function (a) {
return a instanceof Date;
};
bms.gy = function (d) {
return d.getFullYear();
};
bms.gm = function (d) {
return d.getMonth();
};
bms.gd = function (d) {
return d.getDate();
};
bms.d = function (dd, mm, yyyy) {
return new Date(yyyy, mm - 1, dd);
};
bms.jour = function (jour) {
var splitter = jour.split(/\D/);
this.date = new Date(splitter[2], splitter[1] - 1, splitter[0]);
return this;
};
bms.format = function (sep) {
if (this.date) {
return (sep === undefined) ? this.gd(this.date) + " " + this.constantes.m[this.gm(this.date)] + " " + (this.gy(this.date)) : this.gd(this.date) + sep + (this.gm(this.date) + 1) + sep + (this.gy(this.date));
}
};
})(typeof exports === 'undefined' ? this.bms = this.bms || {} : exports);
console.log(bms.d(8, 5, 1972));
console.log(bms.jour('8/5/1972'));
console.log(bms.jour('8/5/1972').date);
console.log(bms.jour('8/5/1972').format());