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);
}
}