--- /dev/null
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved. |
+ | |
+ | This work is published under the GNU AGPLv3 license with some |
+ | permitted exceptions and without any warranty. For full license |
+ | and copyright information, see https://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+ */
+
+namespace Civi\Api4\Query;
+
+/**
+ * Sql function
+ */
+class SqlFunctionDAYOFWEEK extends SqlFunction {
+
+ protected static $category = self::CATEGORY_DATE;
+
+ protected static $dataType = 'Integer';
+
+ protected static function params(): array {
+ return [
+ [
+ 'max_expr' => 1,
+ 'optional' => FALSE,
+ ],
+ ];
+ }
+
+ /**
+ * @return string
+ */
+ public static function getTitle(): string {
+ return ts('Day of Week');
+ }
+
+ /**
+ * @return string
+ */
+ public static function getDescription(): string {
+ return ts('The day of the week of a date.');
+ }
+
+ /**
+ * @return array
+ */
+ public static function getOptions(): ?array {
+ return [
+ 1 => ts('Sunday'),
+ 2 => ts('Monday'),
+ 3 => ts('Tuesday'),
+ 4 => ts('Wednesday'),
+ 5 => ts('Thursday'),
+ 6 => ts('Friday'),
+ 7 => ts('Saturday'),
+ ];
+ }
+
+}
->addSelect('MONTH(birth_date):label AS month_name')
->addSelect('MONTH(birth_date):label')
->addSelect('EXTRACT(YEAR_MONTH FROM birth_date) AS year_month')
+ ->addSelect('DAYOFWEEK(birth_date) AS day_number')
+ ->addSelect('DAYOFWEEK(birth_date):label AS day_name')
->addWhere('last_name', '=', $lastName)
->addOrderBy('id')
->execute();
$this->assertEquals('November', $result[0]['month_name']);
$this->assertEquals('November', $result[0]['MONTH:birth_date:label']);
$this->assertEquals('200911', $result[0]['year_month']);
+ $this->assertEquals(4, $result[0]['day_number']);
+ $this->assertEquals('Wednesday', $result[0]['day_name']);
$this->assertEquals(0, $result[1]['diff']);
$this->assertEquals(2010, $result[1]['year']);
$this->assertEquals('January', $result[1]['month_name']);
$this->assertEquals('January', $result[1]['MONTH:birth_date:label']);
$this->assertEquals('201001', $result[1]['year_month']);
+ $this->assertEquals(6, $result[1]['day_number']);
+ $this->assertEquals('Friday', $result[1]['day_name']);
}
public function testIncorrectNumberOfArguments() {