Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 148 Revision 399
Zeile 296... Zeile 296...
296
     *
296
     *
297
     * @return array
297
     * @return array
298
     */
298
     */
299
    public static function getCascadeFactors()
299
    public static function getCascadeFactors()
300
    {
300
    {
301
        return static::$cascadeFactors ?: [
301
        return static::$cascadeFactors ?: static::getDefaultCascadeFactors();
-
 
302
    }
-
 
303
 
-
 
304
    protected static function getDefaultCascadeFactors(): array
-
 
305
    {
-
 
306
        return [
302
            'milliseconds' => [Carbon::MICROSECONDS_PER_MILLISECOND, 'microseconds'],
307
            'milliseconds' => [Carbon::MICROSECONDS_PER_MILLISECOND, 'microseconds'],
303
            'seconds' => [Carbon::MILLISECONDS_PER_SECOND, 'milliseconds'],
308
            'seconds' => [Carbon::MILLISECONDS_PER_SECOND, 'milliseconds'],
304
            'minutes' => [Carbon::SECONDS_PER_MINUTE, 'seconds'],
309
            'minutes' => [Carbon::SECONDS_PER_MINUTE, 'seconds'],
305
            'hours' => [Carbon::MINUTES_PER_HOUR, 'minutes'],
310
            'hours' => [Carbon::MINUTES_PER_HOUR, 'minutes'],
306
            'dayz' => [Carbon::HOURS_PER_DAY, 'hours'],
311
            'dayz' => [Carbon::HOURS_PER_DAY, 'hours'],
Zeile 1881... Zeile 1886...
1881
    }
1886
    }
Zeile 1882... Zeile 1887...
1882
 
1887
 
1883
    /**
1888
    /**
1884
     * Invert the interval.
1889
     * Invert the interval.
1885
     *
1890
     *
1886
     * @param bool|int $inverted if a parameter is passed, the passed value casted as 1 or 0 is used
1891
     * @param bool|int $inverted if a parameter is passed, the passed value cast as 1 or 0 is used
1887
     *                           as the new value of the ->invert property.
1892
     *                           as the new value of the ->invert property.
1888
     *
1893
     *
1889
     * @return $this
1894
     * @return $this
1890
     */
1895
     */
Zeile 2718... Zeile 2723...
2718
     *
2723
     *
2719
     * @return $this
2724
     * @return $this
2720
     */
2725
     */
2721
    public function roundUnit($unit, $precision = 1, $function = 'round')
2726
    public function roundUnit($unit, $precision = 1, $function = 'round')
2722
    {
2727
    {
-
 
2728
        if (static::getCascadeFactors() !== static::getDefaultCascadeFactors()) {
-
 
2729
            $value = $function($this->total($unit) / $precision) * $precision;
-
 
2730
            $inverted = $value < 0;
-
 
2731
 
-
 
2732
            return $this->copyProperties(self::fromString(
-
 
2733
                number_format(abs($value), 12, '.', '').' '.$unit
-
 
2734
            )->invert($inverted)->cascade());
-
 
2735
        }
-
 
2736
 
2723
        $base = CarbonImmutable::parse('2000-01-01 00:00:00', 'UTC')
2737
        $base = CarbonImmutable::parse('2000-01-01 00:00:00', 'UTC')
2724
            ->roundUnit($unit, $precision, $function);
2738
            ->roundUnit($unit, $precision, $function);
2725
        $next = $base->add($this);
2739
        $next = $base->add($this);
2726
        $inverted = $next < $base;
2740
        $inverted = $next < $base;