No Field-Format in Drupal 11.1.4

Created on 28 July 2025, 3 months 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;
    }
  • 🇷🇸Serbia levmyshkin Novi Sad, Serbia

    I thought about different cases. If you are only one editor on the site, than Sitewide timezone will work fine. But if you have events in different cities and users will add own events, when it will be needed to get timezone from User settings. I will try to add your snippet and add User specific timezone first.

  • 🇷🇸Serbia levmyshkin Novi Sad, Serbia

    Hi tehmilcho, thank you for your research, I added your snippets in 1.0.1 release. Dates are stored as UTC in Drupal database, but it doesn't use Sitewide timezone to bring it in UTC. It uses User timezone:

    /admin/config/regional/settings

    /user/1/edit

    And I think it's OK for count down functionality when User and Sitewide timezone are the same. But I still need to investigate how to display it right for the case when User have different timezone, than Sitewide. Maybe it's already OK for this case too. I close this ticket for now and continue investigation by myself.

  • 🇷🇸Serbia levmyshkin Novi Sad, Serbia
  • 🇷🇸Serbia levmyshkin Novi Sad, Serbia
Production build 0.71.5 2024