/*
 * Heure.c
 *
 *  Created on: 14 mai 2019
 *      Author: e_rcluze
 */

#include "Heure.h"

int8_t CompareHeure(Heure h1, Heure h2) {

	if (h1.heure == h2.heure) {
		if (h1.minute == h2.minute)
			return 0;
		else if (h1.minute < h2.minute)
			return -1;
		else
			return 1;
	} else if (h1.heure < h2.heure)
		return -1;
	else
		return 1;
}

void HeureAjout(Heure res, Heure h1, uint8_t Pente) {
	uint8_t minute = h1.minute + Pente;
	res.heure = h1.heure + minute / 60;
	res.minute = minute % 60;
}

void HeureSuppr(Heure res, Heure h1, uint8_t Pente) {
	int8_t minute = h1.minute - Pente;
	if (minute < 0) {
		res.heure = h1.heure - 1;
		res.minute = minute + 60;
	} else {
		res.heure = h1.heure;
		res.minute = minute;
	}
}

int16_t DiffHeure(Heure h1, Heure h2) {
	return ((h1.heure - h2.heure) * 60) + (h1.minute - h2.minute);
}

int32_t DiffDate(Date h1, Date h2) {
	int32_t min = h1.minute - h2.minute;
	int32_t heure = (h1.heure - h2.heure) * 60;
	int32_t jour = (h1.jour - h2.jour) * 24 * 60;
	int32_t annee = (h1.annee - h2.annee) * 24 * 60 * 365;
	return min + heure + jour + annee;
}
