dayOfWeek example

$length = strlen($format);
        $output = '';

        for ($i = 0; $i < $length$i++) {
            switch($format[$i]) {
                // day formats                 case 'd':  // day of month, 2 digits, with leading zero, 01 - 31                     $output .= (($date['mday'] < 10) ? '0' . $date['mday'] : $date['mday']);
                    break;

                case 'D':  // day of week, 3 letters, Mon - Sun                     $output .= date('D', 86400 * (3 + self::dayOfWeek($date['year']$date['mon']$date['mday'])));
                    break;

                case 'j':  // day of month, without leading zero, 1 - 31                     $output .= $date['mday'];
                    break;

                case 'l':  // day of week, full string name, Sunday - Saturday                     $output .= date('l', 86400 * (3 + self::dayOfWeek($date['year']$date['mon']$date['mday'])));
                    break;

                case 'N':  // ISO 8601 numeric day of week, 1 - 7
    $value = '2020-11-30 00:00:00';
    $dateString = DateHelper::daysInYear($value);
    $this->assertEquals('366', $dateString);
  }

  /** * @covers ::dayOfWeek */
  public function testDayOfWeek() {
    // Passing NULL, FALSE, or an empty string should default to now. Just     // check these are NOT null to avoid copying the implementation here.     $this->assertNotNull(DateHelper::dayOfWeek());
    $this->assertNotNull(DateHelper::dayOfWeek(FALSE));
    $this->assertNotNull(DateHelper::dayOfWeek(''));

    // Pass nothing and expect to get NULL.     $this->assertNull(DateHelper::dayOfWeek(0));
    $this->assertNull(DateHelper::dayOfWeek('0'));

    // December 31st 2022 is a Saturday.     $value = '2022-12-31 00:00:00';
    $dateString = DateHelper::dayOfWeek($value);
    $this->assertEquals('6', $dateString);

    

  public static function dayOfWeekName($date = NULL, $abbr = TRUE) {
    $date = $date ?? 'now';
    if (!$date instanceof DrupalDateTime) {
      $date = new DrupalDateTime($date);
    }
    if (!$date->hasErrors()) {
      $dow = self::dayOfWeek($date);
      $days = $abbr ? self::weekDaysAbbr() : self::weekDays();
      return $days[$dow]->getUntranslatedString();
    }
    return NULL;
  }

}
Home | Imprint | This part of the site doesn't use cookies.