• # En passant par les julian dates...

    Posté par (site web personnel) . En réponse au message Algorithmes calculs de date. Évalué à 3.

    C'est un peu différent, mais cela marchera bien pour ton cas: j'ai des implémentation d'algo standards pour le calcul de "julian date", c'est à dire de nombre de jours depuis une date de référence (en l'occurance, 1er janvier -4713). Donc tu calcul le julian date du premier dimanche suivant ta date de départ, puis le dernier dimanche avant ta date d'arrivée, tu divise cela par 7 et tu as le nombre de semaines (donc de jours ouvrés) plus les offsets du départ et de l'arrivée.

    L'algo:

    long Date::getJulianDayNumber(const int& _year, const int& _month, const int& _day) const
    622 { //given year, month, day, calculate the matching julian day
    623 //see Fliegel, H. F. and van Flandern, T. C. 1968. Letters to the editor: a machine algorithm for processing calendar dates. Commun. ACM 11, 10 (Oct. 1968), 657. DOI= http://doi.acm.org/10.1145/364096.364097
    624 const long lmonth = (long) _month, lday = (long) _day;
    625 long lyear = (long) _year;
    626
    627 // Correct for BC years -> astronomical year, that is from year -1 to year 0
    628 if ( lyear < 0 ) {
    629 lyear++;
    630 }
    631
    632 const long jdn = lday - 32075L +
    633 1461L * ( lyear + 4800L + ( lmonth - 14L ) / 12L ) / 4L +
    634 367L * ( lmonth - 2L - ( lmonth - 14L ) / 12L * 12L ) / 12L -
    635 3L * ( ( lyear + 4900L + ( lmonth - 14L ) / 12L ) / 100L ) / 4L;
    636
    637 return jdn;
    638 }


    Pour plus de détails, regarde dans mes sources:
    https://slfsmm.indefero.net/p/meteoio/source/tree/HEAD/trunk(...)
    (il y a aussi la méthode inverse, à partir d'une julian date trouver jours, mois, annés)

    Mathias