No Field-Format in Drupal 11.1.4

Created on 28 July 2025, 5 days ago

Problem/Motivation

I installed the Module and activate it but when check my Date-Field in my view there is no new option
by the Displayformat

Steps to reproduce

Install and activate Module, create new View with a date-field

💬 Support request
Status

Active

Version

1.0

Component

Documentation

Created by

🇩🇪Germany tehmilcho

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @tehmilcho
  • 🇩🇪Germany tehmilcho

    Hey... I played bit more around so it seems to work with plane datefield but not when i wanna use a timespan filed with start / end time and date and time.

  • 🇩🇪Germany tehmilcho

    hey i changed now:

    in FlipDownFormatter.php

    /**
     * @FieldFormatter(
     *   id = "flipdown",
     *   label = @Translation("FlipDown countdown"),
     *   field_types = {
     *     "datetime",
     *     "timestamp",
     *     "daterange"
     *   }
     * )
     */

    and added "Datarange" and also added "Datarange" in flipdown.views.inc .. now i pick the format in my View it also will show kind of correct .. so JS script is loaded the counter counts etc but the time is off by 2 Hours .. my Server, PHP, Durpal all is set to "Berlin" as timezone but the Module gives back:

    UTC Timestamp: 1753822800 (2025-07-29T23:00:00+02:00)

    Instead of "2025-07-30T01:00:00+02:00". Unfortunately i dont have real clue about Drupal DEV or PHP .. i just messaround with AI and good luck. Maybe some else can give a hint what is going with the Timezone here?!

  • 🇷🇸Serbia levmyshkin Novi Sad, Serbia

    I need to investigate this situation with Timezone, it's not clear for me now where is source of truth for timezone. It can be changed on Server, Sitewide, User specific, Field Storage/Instance/Formatter specific.

  • 🇩🇪Germany tehmilcho

    Hey,

    first thank you for looking in to it, i really appreciate it :)

    I messed bit more around with AI and found a Soultion?!... its just code from ChatGPT but it seems to work now.

    Change:
    File: FlipDownFormatter.php

    Original Code:

          // Convert stored value to Unix seconds.
          if (is_numeric($item->value)) {
            $target_ts = (int) $item->value;
          }
          else {
            try {
             $target_ts = (new DrupalDateTime($item->value))->getTimestamp();
            } catch (\Exception $e) {
              continue;
            }
         } 

    Replacement:

          try {
      $timezone = new \DateTimeZone(\Drupal::config('system.date')->get('timezone.default'));
    
      if (is_numeric($item->value)) {
        // Timestamp in seconds → treat as UTC
        $date = new \DateTime('@' . $item->value);
      } else {
        // ISO string or date as string → first interpret in UTC
        $date = new \DateTime($item->value, new \DateTimeZone('UTC'));
      }
    
      $date->setTimezone($timezone);
      $target_ts = $date->getTimestamp();
    
    } catch (\Exception $e) {
      continue;
    }
Production build 0.71.5 2024