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

Method timeBucket

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

Source from the content-addressed store, hash-verified

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

Callers 1

applyTimeAggregationMethod · 0.95

Calls 1

formatMethod · 0.45

Tested by

no test coverage detected