server/src/app/Libraries/Utils.php
changeset 20 a9b98b16b053
parent 19 eadaf0b8f02e
child 130 fac22d8c2df8
equal deleted inserted replaced
19:eadaf0b8f02e 20:a9b98b16b053
    13      * @param \DateInterval $di the date interval
    13      * @param \DateInterval $di the date interval
    14      * @return the number of milliseconds or 0 if $di is null
    14      * @return the number of milliseconds or 0 if $di is null
    15      */
    15      */
    16     public static function dateIntervalToMillis(\DateInterval $di) {
    16     public static function dateIntervalToMillis(\DateInterval $di) {
    17         if(is_null($di)) {
    17         if(is_null($di)) {
    18             return 0;
    18             return null;
    19         }
    19         }
    20         $seconds = ($di->s)
    20         $seconds = ($di->s)
    21          + ($di->i * 60)
    21          + ($di->i * 60)
    22          + ($di->h * 60 * 60)
    22          + ($di->h * 60 * 60)
    23          + ($di->d * 60 * 60 * 24)
    23          + ($di->d * 60 * 60 * 24)
    33      *
    33      *
    34      * @param str iso8601 string
    34      * @param str iso8601 string
    35      * @return the number of milliseconds or 0 if $str is null
    35      * @return the number of milliseconds or 0 if $str is null
    36      */
    36      */
    37     public static function iso8601IntervalToMillis($str) {
    37     public static function iso8601IntervalToMillis($str) {
    38         if(is_null($str) || $str === '') {
    38         if(is_null($str)) {
       
    39             return null;
       
    40         }
       
    41         elseif( $str === '') {
    39             return 0;
    42             return 0;
    40         }
    43         }
       
    44 
    41         $di = new \DateInterval($str);
    45         $di = new \DateInterval($str);
    42         return self::dateIntervalToMillis($di);
    46         return self::dateIntervalToMillis($di);
    43     }
    47     }
    44 
    48 
    45     /*
    49     /*