protected function time_array($timestamp) { $time = array_combine(array('month', 'day', 'year', 'hour', 'minute', 'am_pm'), explode('--', date('n--j--Y--g--i--A', $timestamp))); // Minutes should always be in 5 minute increments $time['minute'] = num::round($time['minute'], current($this->parts['minute'])); return $time; }
public static function hsb2rgb($hue, $saturation, $brightness) { $hue = num::round($hue, 3); $saturation = num::round($saturation, 3); $brightness = num::round($brightness, 3); $hexBrightness = (int) round($brightness * 2.55); if ($saturation == 0) { return array('red' => $hexBrightness, 'green' => $hexBrightness, 'blue' => $hexBrightness); } $Hi = floor($hue / 60); $f = $hue / 60 - $Hi; $p = (int) round($brightness * (100 - $saturation) * 0.0255); $q = (int) round($brightness * (100 - $f * $saturation) * 0.0255); $t = (int) round($brightness * (100 - (1 - $f) * $saturation) * 0.0255); switch ($Hi) { case 0: return array('red' => $hexBrightness, 'green' => $t, 'blue' => $p); case 1: return array('red' => $q, 'green' => $hexBrightness, 'blue' => $p); case 2: return array('red' => $p, 'green' => $hexBrightness, 'blue' => $t); case 3: return array('red' => $p, 'green' => $q, 'blue' => $hexBrightness); case 4: return array('red' => $t, 'green' => $p, 'blue' => $hexBrightness); case 5: return array('red' => $hexBrightness, 'green' => $p, 'blue' => $q); } return false; }
/** * Tests the num::round() function. * @dataProvider round_provider * @group core.helpers.num.round * @test */ public function round($input_number, $input_nearest, $expected_result) { $result = num::round($input_number, $input_nearest); $this->assertEquals($expected_result, $result); }
/** * Calculates the font size of a tag cloud item */ private function _calculate_font_size($cur_frequency, $max_frequency, $min_frequency) { if ($max_frequency - $min_frequency === 0) { return $this->min_font_size; } // Calculate the weight using a power law - consider switching to a logarithmic one $weight = ($cur_frequency - $min_frequency) / ($max_frequency - $min_frequency); return $this->min_font_size + num::round(($this->max_font_size - $this->min_font_size) * $weight); }