MCPcopy Create free account
hub / github.com/Rello/analytics / timeBucket

Method timeBucket

lib/Service/FlexibleStorageService.php:887–901  ·  view source on GitHub ↗
(string $value, string $type, string $grouping)

Source from the content-addressed store, hash-verified

885 }
886
887 private function timeBucket(string $value, string $type, string $grouping): string {
888 try {
889 $date = new \DateTimeImmutable($value, new \DateTimeZone('UTC'));
890 } catch (\Throwable $e) {
891 throw new FlexibleStorageException('invalid_time_value', 'A stored date value cannot be aggregated.', ['value' => $value], 500, $e);
892 }
893 $date = match ($grouping) {
894 'day' => $date->setTime(0, 0),
895 'week' => $date->modify('monday this week')->setTime(0, 0),
896 'month' => $date->modify('first day of this month')->setTime(0, 0),
897 'quarter' => $date->setDate((int)$date->format('Y'), intdiv((int)$date->format('n') - 1, 3) * 3 + 1, 1)->setTime(0, 0),
898 'year' => $date->setDate((int)$date->format('Y'), 1, 1)->setTime(0, 0),
899 };
900 return $type === 'date' ? $date->format('Y-m-d') : $date->format('Y-m-d\TH:i:s\Z');
901 }
902
903 /**
904 * @param list<list<mixed>> $data

Callers 1

applyTimeAggregationMethod · 0.95

Calls 1

formatMethod · 0.45

Tested by

no test coverage detected