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

Comments

tehmilcho created an issue. See original summary.

tehmilcho’s picture

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.

tehmilcho’s picture

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?!

levmyshkin’s picture

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.

tehmilcho’s picture

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;
}
levmyshkin’s picture

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. Also it's possible to extend Field Formatter settings and add setting for timezone in it.

Another option, we need to select in field formatter Start or End date to display countdown. And maybe to add setting to display Countdown for both Start and End date.

  • levmyshkin committed 730b931f on 1.0.x
    Issue #3538453 by tehmilcho: No Field-Format in Drupal 11.1.4
    
levmyshkin’s picture

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
Timezones

/user/1/edit
timezones

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.

levmyshkin’s picture

Status: Active » Fixed
levmyshkin’s picture

Status: Fixed » Closed (fixed)