2023-03-29 22:53:40 +02:00
|
|
|
import { SHOW_DICE, SYSTEM_RDD } from "../constants.js";
|
|
|
|
import { Grammar } from "../grammar.js";
|
|
|
|
import { Misc } from "../misc.js";
|
|
|
|
import { RdDDice } from "../rdd-dice.js";
|
2023-01-05 00:55:04 +01:00
|
|
|
|
2023-01-07 20:06:04 +01:00
|
|
|
export const WORLD_TIMESTAMP_SETTING = "calendrier";
|
|
|
|
|
2023-01-05 00:55:04 +01:00
|
|
|
const RDD_JOURS_PAR_AN = 336; //RDD_JOURS_PAR_MOIS * RDD_MOIS_PAR_AN;
|
2023-03-08 02:02:40 +01:00
|
|
|
const RDD_MOIS_PAR_AN = 12;
|
|
|
|
export const RDD_JOURS_PAR_MOIS = 28;
|
|
|
|
export const RDD_HEURES_PAR_JOUR = 12;
|
|
|
|
export const MAX_NOMBRE_ASTRAL = 12;
|
2023-03-09 23:49:37 +01:00
|
|
|
export const RDD_MINUTES_PAR_HEURES = 120;
|
|
|
|
export const RDD_MINUTES_PAR_JOUR = 1440; //RDD_HEURES_PAR_JOUR * RDD_MINUTES_PAR_HEURES;
|
2023-01-05 00:55:04 +01:00
|
|
|
const ROUNDS_PAR_MINUTE = 10;
|
|
|
|
|
|
|
|
const DEFINITION_HEURES = [
|
2024-09-25 23:03:05 +02:00
|
|
|
{ key: "vaisseau", article: "du ", label: "Vaisseau", lettreFont: 'v', saison: "Printemps", darkness: 0.9 },
|
|
|
|
{ key: "sirene", article: "de la ", label: "Sirène", lettreFont: 'i', saison: "Printemps", darkness: 0.1 },
|
|
|
|
{ key: "faucon", article: "du ", label: "Faucon", lettreFont: 'f', saison: "Printemps", darkness: 0 },
|
|
|
|
{ key: "couronne", article: "de la ", label: "Couronne", lettreFont: '', saison: "Eté", darkness: 0 },
|
|
|
|
{ key: "dragon", article: "du ", label: "Dragon", lettreFont: 'd', saison: "Eté", darkness: 0 },
|
|
|
|
{ key: "epees", article: "des ", label: "Epées", lettreFont: 'e', saison: "Eté", darkness: 0 },
|
|
|
|
{ key: "lyre", article: "de la ", label: "Lyre", lettreFont: 'l', saison: "Automne", darkness: 0.1 },
|
|
|
|
{ key: "serpent", article: "du ", label: "Serpent", lettreFont: 's', saison: "Automne", darkness: 0.9 },
|
|
|
|
{ key: "poissonacrobate", article: "du ", label: "Poisson Acrobate", lettreFont: 'p', saison: "Automne", darkness: 1 },
|
|
|
|
{ key: "araignee", article: "de l'", label: "Araignée", lettreFont: 'a', saison: "Hiver", darkness: 1 },
|
|
|
|
{ key: "roseau", article: "du ", label: "Roseau", lettreFont: 'r', saison: "Hiver", darkness: 1 },
|
|
|
|
{ key: "chateaudormant", article: "du ", label: "Château Dormant", lettreFont: 'c', saison: "Hiver", darkness: 1 },
|
2023-01-05 00:55:04 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
const FORMULES_DUREE = [
|
|
|
|
{ code: "", label: "", calcul: async (t, actor) => t.addJours(100 * RDD_JOURS_PAR_AN) },
|
|
|
|
{ code: "jour", label: "1 jour", calcul: async (t, actor) => t.nouveauJour().addJours(1) },
|
|
|
|
{ code: "1d7jours", label: "1d7 jour", calcul: async (t, actor) => t.nouveauJour().addJours(await RdDDice.rollTotal('1d7', { showDice: SHOW_DICE })) },
|
|
|
|
{ code: "1ddr", label: "Un dé draconique jours", calcul: async (t, actor) => t.nouveauJour().addJours(await RdDDice.rollTotal('1dr+7', { showDice: SHOW_DICE })) },
|
|
|
|
{ code: "hn", label: "Fin de l'Heure de Naissance", calcul: async (t, actor) => t.finHeure(actor.getHeureNaissance()) },
|
|
|
|
// { code: "1h", label: "Une heure", calcul: async (t, actor) => t.nouvelleHeure().addHeures(1) },
|
|
|
|
// { code: "12h", label: "12 heures", calcul: async (t, actor) => t.nouvelleHeure().addHeures(12) },
|
|
|
|
// { code: "chateaudormant", label: "Fin Chateau dormant", calcul: async (t, actor) => t.nouveauJour() },
|
|
|
|
// { code: "special", label: "Spéciale", calcul: async (t, actor) => t.addJours(100 * RDD_JOURS_PAR_AN) },
|
|
|
|
]
|
2023-01-07 23:28:30 +01:00
|
|
|
const FORMULES_PERIODE = [
|
2023-01-08 00:57:05 +01:00
|
|
|
{ code: 'round', label: "Rounds", calcul: async (t, nombre) => t.addMinutes(nombre / 10) },
|
|
|
|
{ code: 'minute', label: "Minutes", calcul: async (t, nombre) => t.addMinutes(nombre) },
|
|
|
|
{ code: 'heure', label: "Heures", calcul: async (t, nombre) => t.addHeures(nombre) },
|
|
|
|
{ code: 'jour', label: "Jours", calcul: async (t, nombre) => t.addJours(nombre) },
|
2023-01-07 23:28:30 +01:00
|
|
|
]
|
2023-01-05 00:55:04 +01:00
|
|
|
|
2023-03-08 02:02:40 +01:00
|
|
|
export class RdDTimestamp {
|
2023-01-05 00:55:04 +01:00
|
|
|
|
|
|
|
static init() {
|
2023-01-07 20:06:04 +01:00
|
|
|
game.settings.register(SYSTEM_RDD, WORLD_TIMESTAMP_SETTING, {
|
|
|
|
name: WORLD_TIMESTAMP_SETTING,
|
2023-01-05 00:55:04 +01:00
|
|
|
scope: "world",
|
|
|
|
config: false,
|
2023-01-07 20:06:04 +01:00
|
|
|
default: { indexDate: 0, indexMinute: 0 },
|
2023-01-05 00:55:04 +01:00
|
|
|
type: Object
|
|
|
|
});
|
|
|
|
|
2023-10-20 02:34:07 +02:00
|
|
|
|
2023-01-05 00:55:04 +01:00
|
|
|
for (let i = 0; i < DEFINITION_HEURES.length; i++) {
|
|
|
|
DEFINITION_HEURES[i].heure = i;
|
2023-03-07 02:28:10 +01:00
|
|
|
DEFINITION_HEURES[i].hh = RdDTimestamp.hh(i);
|
2023-01-05 00:55:04 +01:00
|
|
|
DEFINITION_HEURES[i].icon = RdDTimestamp.iconeHeure(i);
|
|
|
|
DEFINITION_HEURES[i].webp = DEFINITION_HEURES[i].icon.replace(".svg", ".webp");
|
2024-09-25 23:03:05 +02:00
|
|
|
DEFINITION_HEURES[i].avecArticle = DEFINITION_HEURES[i].article + DEFINITION_HEURES[i].label
|
2023-01-05 00:55:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-08 02:02:40 +01:00
|
|
|
static hh(heure) {
|
|
|
|
return heure < 9 ? `0${heure + 1}` : `${heure + 1}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
static iconeHeure(heure) {
|
|
|
|
return `systems/foundryvtt-reve-de-dragon/icons/heures/hd${RdDTimestamp.hh(heure)}.svg`;
|
|
|
|
}
|
|
|
|
|
|
|
|
static definitions() {
|
|
|
|
return DEFINITION_HEURES
|
|
|
|
}
|
|
|
|
|
|
|
|
static formulesDuree() {
|
|
|
|
return FORMULES_DUREE
|
|
|
|
}
|
|
|
|
|
|
|
|
static formulesPeriode() {
|
|
|
|
return FORMULES_PERIODE
|
|
|
|
}
|
|
|
|
|
|
|
|
static heures() {
|
|
|
|
return Misc.intArray(0, RDD_HEURES_PAR_JOUR)
|
|
|
|
}
|
|
|
|
|
2023-01-05 00:55:04 +01:00
|
|
|
/**
|
2023-03-08 02:02:40 +01:00
|
|
|
* @param signe
|
2023-01-05 00:55:04 +01:00
|
|
|
* @returns L'entrée de DEFINITION_HEURES correspondant au signe
|
2023-03-08 02:02:40 +01:00
|
|
|
*/
|
2023-01-05 00:55:04 +01:00
|
|
|
static definition(signe) {
|
2023-01-19 01:43:52 +01:00
|
|
|
if (signe == undefined) {
|
2023-12-08 04:00:17 +01:00
|
|
|
signe = 0
|
2023-01-19 01:43:52 +01:00
|
|
|
}
|
2023-01-05 00:55:04 +01:00
|
|
|
if (Number.isInteger(signe)) {
|
2023-12-08 04:00:17 +01:00
|
|
|
return DEFINITION_HEURES[Misc.modulo(signe, RDD_HEURES_PAR_JOUR)]
|
2023-01-05 00:55:04 +01:00
|
|
|
}
|
|
|
|
let definition = DEFINITION_HEURES.find(it => it.key == signe);
|
|
|
|
if (!definition) {
|
|
|
|
definition = Misc.findFirstLike(signe, DEFINITION_HEURES, { mapper: it => it.label, description: 'signe' });
|
|
|
|
}
|
|
|
|
return definition
|
|
|
|
}
|
|
|
|
|
|
|
|
static imgSigneHeure(heure) {
|
|
|
|
return RdDTimestamp.imgSigne(RdDTimestamp.definition(heure));
|
|
|
|
}
|
|
|
|
|
|
|
|
static imgSigne(signe) {
|
2023-12-04 01:21:05 +01:00
|
|
|
return signe == undefined ? '' : `<img class="img-signe-heure" src="${signe.webp}" data-tooltip="${signe.label}"/>`
|
2023-03-08 02:02:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ajustementAstrologiqueHeure(hn, nbAstral, heure) {
|
2023-12-08 04:00:17 +01:00
|
|
|
let ecart = Misc.modulo(hn + nbAstral - heure, RDD_HEURES_PAR_JOUR);
|
2023-03-08 02:02:40 +01:00
|
|
|
switch (ecart) {
|
|
|
|
case 0: return 4;
|
|
|
|
case 4: case 8: return 2;
|
|
|
|
case 6: return -4;
|
|
|
|
case 3: case 9: return -2;
|
|
|
|
}
|
|
|
|
return 0;
|
2023-01-05 00:55:04 +01:00
|
|
|
}
|
|
|
|
|
2023-01-08 16:36:48 +01:00
|
|
|
static handleTimestampEditor(html, path, consumeTimestamp = async (path, timestamp) => { }) {
|
2023-01-07 23:58:33 +01:00
|
|
|
const fields = {
|
|
|
|
annee: html.find(`input[name="${path}.annee"]`),
|
|
|
|
mois: html.find(`select[name="${path}.mois"]`),
|
|
|
|
jourDuMois: html.find(`input[name="${path}.jourDuMois"]`),
|
|
|
|
heure: html.find(`select[name="${path}.heure"]`),
|
|
|
|
minute: html.find(`input[name="${path}.minute"]`)
|
|
|
|
};
|
|
|
|
|
|
|
|
async function onChangeTimestamp(fields, path) {
|
|
|
|
const annee = Number(fields.annee.val());
|
|
|
|
const mois = fields.mois.val();
|
|
|
|
const jour = Number(fields.jourDuMois.val());
|
|
|
|
const heure = fields.heure.val();
|
|
|
|
const minute = Number(fields.minute.val());
|
|
|
|
await consumeTimestamp(path, RdDTimestamp.timestamp(annee, mois, jour, heure, minute));
|
|
|
|
}
|
|
|
|
|
|
|
|
fields.annee.change(async (event) => await onChangeTimestamp(fields, path));
|
|
|
|
fields.mois.change(async (event) => await onChangeTimestamp(fields, path));
|
|
|
|
fields.jourDuMois.change(async (event) => await onChangeTimestamp(fields, path));
|
|
|
|
fields.heure.change(async (event) => await onChangeTimestamp(fields, path));
|
|
|
|
fields.minute.change(async (event) => await onChangeTimestamp(fields, path));
|
|
|
|
}
|
|
|
|
|
2023-06-20 23:20:44 +02:00
|
|
|
static defHeure(heure) {
|
2023-12-08 04:00:17 +01:00
|
|
|
heure = Misc.modulo(heure, RDD_HEURES_PAR_JOUR);
|
|
|
|
return DEFINITION_HEURES.find(it => it.heure == heure)
|
2023-06-20 23:20:44 +02:00
|
|
|
}
|
2023-12-08 04:00:17 +01:00
|
|
|
|
2023-01-05 00:55:04 +01:00
|
|
|
static findHeure(heure) {
|
|
|
|
heure = Grammar.toLowerCaseNoAccentNoSpace(heure);
|
2023-12-08 04:00:17 +01:00
|
|
|
let parHeureOuLabel = DEFINITION_HEURES.filter(it => Grammar.toLowerCaseNoAccentNoSpace(it.label) == heure || it.heure == Misc.modulo(parseInt(heure), RDD_HEURES_PAR_JOUR));
|
2023-01-05 00:55:04 +01:00
|
|
|
if (parHeureOuLabel.length == 1) {
|
|
|
|
return parHeureOuLabel[0];
|
|
|
|
}
|
|
|
|
let parLabelPartiel = DEFINITION_HEURES.filter(it => Grammar.toLowerCaseNoAccentNoSpace(it.label).includes(heure));
|
|
|
|
if (parLabelPartiel.length > 0) {
|
|
|
|
parLabelPartiel.sort(Misc.ascending(h => h.label.length));
|
|
|
|
return parLabelPartiel[0];
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-01-07 23:28:30 +01:00
|
|
|
* @param indexDate: la date (depuis le jour 0)
|
|
|
|
* @return la version formattée de la date
|
2023-01-05 00:55:04 +01:00
|
|
|
*/
|
|
|
|
static formatIndexDate(indexDate) {
|
|
|
|
return new RdDTimestamp({ indexDate }).formatDate()
|
|
|
|
}
|
2023-01-07 20:06:04 +01:00
|
|
|
|
2023-01-05 00:55:04 +01:00
|
|
|
static splitIndexDate(indexDate) {
|
|
|
|
const timestamp = new RdDTimestamp({ indexDate });
|
|
|
|
return {
|
|
|
|
jour: timestamp.jour + 1,
|
|
|
|
mois: RdDTimestamp.definition(timestamp.mois).key
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static getWorldTime() {
|
2023-01-07 20:06:04 +01:00
|
|
|
let worldTime = game.settings.get(SYSTEM_RDD, WORLD_TIMESTAMP_SETTING);
|
2023-01-08 16:36:48 +01:00
|
|
|
if (worldTime.indexJour != undefined && worldTime.heureRdD != undefined) {
|
2023-01-07 20:06:04 +01:00
|
|
|
// Migration
|
|
|
|
worldTime = {
|
|
|
|
indexDate: worldTime.indexJour,
|
|
|
|
indexMinute: worldTime.heureRdD * 120 + worldTime.minutesRelative
|
|
|
|
};
|
|
|
|
RdDTimestamp.setWorldTime(new RdDTimestamp(worldTime))
|
|
|
|
}
|
2023-01-07 23:28:30 +01:00
|
|
|
return new RdDTimestamp(worldTime);
|
2023-01-05 00:55:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static setWorldTime(timestamp) {
|
2024-05-02 14:08:02 +02:00
|
|
|
game.settings.set(SYSTEM_RDD, WORLD_TIMESTAMP_SETTING, foundry.utils.duplicate(timestamp));
|
2023-01-05 00:55:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** construit un RdDTimestamp à partir de l'année/mois/jour/heure?/minute? */
|
|
|
|
static timestamp(annee, mois, jour, heure = 0, minute = 0) {
|
|
|
|
mois = this.definition(mois)?.heure
|
|
|
|
heure = this.definition(heure)?.heure
|
|
|
|
return new RdDTimestamp({
|
|
|
|
indexDate: (jour - 1) + (mois + annee * RDD_MOIS_PAR_AN) * RDD_JOURS_PAR_MOIS,
|
|
|
|
indexMinute: heure * RDD_MINUTES_PAR_HEURES + minute
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructeur d'un timestamp.
|
|
|
|
* Selon les paramètres, l'objet construit se base su:
|
|
|
|
* - le timestamp
|
|
|
|
* - la date numérique + minute (dans la journée)
|
|
|
|
* @param indexDate: la date à utiliser pour ce timestamp
|
|
|
|
* @param indexMinute: la minute de la journée à utiliser pour ce timestamp
|
|
|
|
*
|
|
|
|
*/
|
2023-01-07 20:06:04 +01:00
|
|
|
constructor({ indexDate, indexMinute = undefined }) {
|
|
|
|
this.indexDate = indexDate
|
|
|
|
this.indexMinute = indexMinute ?? 0
|
2023-01-05 00:55:04 +01:00
|
|
|
}
|
|
|
|
|
2023-03-30 00:19:12 +02:00
|
|
|
get annee() { return Math.floor(this.indexDate / RDD_JOURS_PAR_AN) }
|
2023-12-08 04:00:17 +01:00
|
|
|
get mois() { return Math.floor(Misc.modulo(this.indexDate, RDD_JOURS_PAR_AN) / RDD_JOURS_PAR_MOIS) }
|
2024-05-27 00:37:19 +02:00
|
|
|
get nomMois() { return Math.floor(Misc.modulo(this.indexDate, RDD_JOURS_PAR_AN) / RDD_JOURS_PAR_MOIS) }
|
2023-12-08 04:00:17 +01:00
|
|
|
get jour() { return Misc.modulo(Misc.modulo(this.indexDate, RDD_JOURS_PAR_AN), RDD_JOURS_PAR_MOIS) }
|
2023-03-30 00:19:12 +02:00
|
|
|
get heure() { return Math.floor(this.indexMinute / RDD_MINUTES_PAR_HEURES) }
|
2023-12-08 04:00:17 +01:00
|
|
|
get minute() { return Misc.modulo(this.indexMinute, RDD_MINUTES_PAR_HEURES) }
|
2023-03-30 00:19:12 +02:00
|
|
|
get round() { return ROUNDS_PAR_MINUTE * (this.indexMinute - Math.floor(this.indexMinute)) }
|
|
|
|
get angleHeure() { return this.indexMinute / RDD_MINUTES_PAR_JOUR * 360 - 45 }
|
|
|
|
get angleMinute() { return this.indexMinute / RDD_MINUTES_PAR_HEURES * 360 + 45 }
|
|
|
|
|
2023-10-20 02:34:07 +02:00
|
|
|
get darkness() {
|
2023-12-08 04:00:17 +01:00
|
|
|
const darknessDebut = 100 * RdDTimestamp.definition(this.heure).darkness
|
2024-09-25 23:03:05 +02:00
|
|
|
const darknessFin = 100 * RdDTimestamp.definition(this.heure + 1).darkness
|
2023-10-20 02:34:07 +02:00
|
|
|
const darknessMinute = Math.round((darknessFin - darknessDebut) * this.minute / RDD_MINUTES_PAR_HEURES);
|
2023-12-08 04:00:17 +01:00
|
|
|
return (darknessDebut + darknessMinute) / 100
|
2023-10-20 02:34:07 +02:00
|
|
|
}
|
|
|
|
|
2023-01-07 23:28:30 +01:00
|
|
|
/**
|
|
|
|
* Convertit le timestamp en une structure avec les informations utiles
|
|
|
|
* pour afficher la date et l'heure
|
|
|
|
*/
|
2023-01-05 00:55:04 +01:00
|
|
|
toCalendrier() {
|
|
|
|
return {
|
|
|
|
timestamp: this,
|
|
|
|
annee: this.annee,
|
|
|
|
mois: RdDTimestamp.definition(this.mois),
|
|
|
|
jour: this.jour,
|
2023-01-07 20:06:04 +01:00
|
|
|
jourDuMois: this.jour + 1,
|
2023-01-05 00:55:04 +01:00
|
|
|
heure: RdDTimestamp.definition(this.heure),
|
|
|
|
minute: this.minute
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
formatDate() {
|
|
|
|
const jour = this.jour + 1;
|
|
|
|
const mois = RdDTimestamp.definition(this.mois).label;
|
|
|
|
const annee = this.annee ?? '';
|
|
|
|
return `${jour} ${mois}` + (annee ? ' ' + annee : '');
|
|
|
|
}
|
|
|
|
|
2023-03-30 00:19:12 +02:00
|
|
|
formatDateHeure() {
|
|
|
|
return `${RdDTimestamp.definition(this.heure).label}, ${this.formatDate()}`;
|
|
|
|
}
|
|
|
|
|
2023-01-05 00:55:04 +01:00
|
|
|
nouveauJour() { return new RdDTimestamp({ indexDate: this.indexDate + 1, indexMinute: 0 }) }
|
|
|
|
|
|
|
|
nouvelleHeure() {
|
|
|
|
return this.heure >= RDD_HEURES_PAR_JOUR ? this.nouveauJour() : new RdDTimestamp({
|
|
|
|
indexDate: this.indexDate,
|
|
|
|
indexMinute: (this.heure + 1) * RDD_MINUTES_PAR_HEURES
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
addJours(jours) {
|
|
|
|
return jours == 0 ? this : new RdDTimestamp({
|
|
|
|
indexDate: this.indexDate + jours,
|
|
|
|
indexMinute: this.indexMinute
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
addHeures(heures) {
|
|
|
|
if (heures == 0) {
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
const heure = this.heure + heures;
|
|
|
|
return new RdDTimestamp({
|
|
|
|
indexDate: this.indexDate + Math.floor(heure / RDD_HEURES_PAR_JOUR),
|
2023-12-08 04:00:17 +01:00
|
|
|
indexMinute: this.indexMinute + Misc.modulo(heure, RDD_HEURES_PAR_JOUR) * RDD_MINUTES_PAR_HEURES
|
2023-01-05 00:55:04 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
addMinutes(minutes) {
|
|
|
|
if (minutes == 0) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
const indexMinute = this.indexMinute + minutes;
|
|
|
|
const jours = Math.floor(indexMinute / RDD_MINUTES_PAR_JOUR)
|
|
|
|
return new RdDTimestamp({
|
|
|
|
indexDate: this.indexDate + jours,
|
|
|
|
indexMinute: indexMinute - (jours * RDD_MINUTES_PAR_JOUR)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
addPeriode(nombre, unite) {
|
2023-01-07 23:28:30 +01:00
|
|
|
const formule = FORMULES_PERIODE.find(it => it.code == unite);
|
|
|
|
if (formule) {
|
|
|
|
return formule.calcul(this, nombre);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ui.notifications.info(`Pas de période pour ${unite ?? 'Aucune uinité définie'}`)
|
2023-01-05 00:55:04 +01:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
finHeure(heure) {
|
|
|
|
return this.nouvelleHeure().addHeures((12 + heure - this.heure) % 12);
|
|
|
|
}
|
|
|
|
|
|
|
|
async appliquerDuree(duree, actor) {
|
|
|
|
const formule = FORMULES_DUREE.find(it => it.code == duree) ?? FORMULES_DUREE.find(it => it.code == "");
|
|
|
|
return await formule.calcul(this, actor);
|
|
|
|
}
|
|
|
|
|
|
|
|
compare(timestamp) {
|
2023-01-07 23:28:30 +01:00
|
|
|
let diff = this.indexDate - timestamp.indexDate
|
|
|
|
if (diff == 0) {
|
|
|
|
diff = this.indexMinute - timestamp.indexMinute
|
|
|
|
}
|
2023-01-05 00:55:04 +01:00
|
|
|
return diff < 0 ? -1 : diff > 0 ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
difference(timestamp) {
|
|
|
|
const jours = this.indexDate - timestamp.indexDate;
|
|
|
|
const minutes = this.indexMinute - timestamp.indexMinute;
|
|
|
|
return {
|
|
|
|
jours: jours,
|
|
|
|
heures: Math.floor(minutes / RDD_MINUTES_PAR_HEURES),
|
2023-12-08 04:00:17 +01:00
|
|
|
minutes: Misc.modulo(minutes, RDD_MINUTES_PAR_HEURES)
|
2023-01-05 00:55:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|