Score:-1

Add Semester Timeformat

tc flag

I'm trying to add a timeformat to show in which academic semester the date is in, we have the Winter Semester from 1st of October to the last day of march, the rest of the year is summer semester. It should be shown like this:

WiSe 22/23 or SoSe 21 or SoSe 20

I've tried adding a new module which overrides the time.formatter service but it doesn't work at produces error pages. Here is my code:

semester.info.yml

name: Semester
description: Adds Semester Timestamp Format
type: module
core_version_requirement: ^10
package: Custom

semester.module

<?php

/**
 * @file
 * Semester module file.
 */

use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function semester_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.semester':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('This is an module providing Semester Timestamp format.') . '</p>';
      return $output;

    default:
  }
}

semester.services.yml

services:
  date.formatter:
    class: Drupal\semester\SemesterDateFormatter
    arguments: ['@entity_type.manager', '@language_manager', '@string_translation', '@config.factory', '@request_stack']

src/SemesterDateFormatter.php

<?php

namespace Drupal\semester;

use Drupal\Core\Datetime\DateFormatter;


class SemesterDateFormatter extends DateFormatter
{
  public function format($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL)
    {
      return $this->DateFormatter::format($timetamp, $type, $format, $timezone, $langcode);
    }
}
id flag
What are the error pages that it produces? How are you applying the formatter to fields? SemesterDateFormatter seems not to do anything and may have syntax errors. Is the help you need with that?
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.