dolibarr-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dolibarr-dev] Question and bug about num_between_day in date.lib.php


From: Florian Henry
Subject: [Dolibarr-dev] Question and bug about num_between_day in date.lib.php
Date: Wed, 05 Mar 2014 12:21:43 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0

Hi all,

I've got a problem into Holiday module, but also can give some strange result to other part of code that use function num_between_day of date.lib.php

    My case :
Find number of day betwenn 21-March-2014 and 24-March-2014 Result is 4 => OK (Friday,Saturday,Sunday,Monday) Find number of day betwenn 28-March-2014 and 31-March-2014 Result is 3 => KO. (Friday,Saturday,Sunday,Monday)

If I look into code of this function we have a basic timestamp substraction, that should give a good result, but in fact not. Is it the only case ? I don't know.

    I put some trace and there is the result :

            21-24 :
                $timestampStart=1395356400
                $timestampEnd  =1395615600
                $bit=0
                ($timestampEnd - $timestampStart)/(60*60*24) +1 - $bits = 4
                floor(4) = 4

            28-31 :
                $timestampStart=1395961200
                $timestampEnd  =1396216800
                $bit=0
($timestampEnd - $timestampStart)/(60*60*24) + 1 - $bits = 3.9583333333333
                floor(3.9583333333333) = 3


As we do a floor on this ($timestampEnd - $timestampStart)/(60*60*24) the second result is KO

If I use the DateTime php object method the result is correct. But this core php object exists only for php version 5.3 and more. So more than the minimum version 5.2.1 describe into the wiki.

As patch for now I use round instead of floor but all php code line I can found on internet use floor for this type of calculation, so what is the good option ?

I've create a bug into DoliForge : https://doliforge.org/tracker/?func=detail&aid=1287&atid=246&group_id=144 but still do not have a clue about why the strong calculation rule do not work in this specifics case.

Regards

--
Florian HENRY
address@hidden
+33 6 03 76 48 07
http://www.open-concept.pro
Twitter : @_Open_Concept_




reply via email to

[Prev in Thread] Current Thread [Next in Thread]