Skip to main content

D9 - UTC Timezone Testing

Test One uses the site-wide setting of UTC.
"Display Mode" settings per-node are setup on individual testing fields. 
 

Regional Display Settings

System Timezone setting are set here /admin/config/regional/settings
These setting can be opened for User Level change. 

Image
Timezone Settings

Times Set on a Content Field's "Display Tab":

Image
Times Set on a Content Field's "Display Tab"
Timezone Testing; UTC and EST Testing Fields
Image
Testing Date Fields
Testing One - EST Database Storage

EST Date Field Database Value: 2023-04-04T09:00:00 

Image
DB Storage

EST Date Range Database Value: 2023-04-04T09:00:00 - 2023-04-04T10:00:00

Image
DB Value

EST Timestamp Database Value: 1680598800 

Image
DST Value
Testing One - UTC Database Storage

UTC Date Field Database Value: 2023-04-04T09:00:00

Image
UTC - DB VAlue

UTC Date Range Database Value: 2023-04-04T09:00:00
2023-04-04T10:00:00

Image
UTC Database Value

UTC Timestamp Database Value: 1680598800

Image
UTC DB Value

Test One Results:

Image
Test One Results


 

Test Two Setup Changes

The System time is set to a Timezone of New_York. The Display Modes setting for the field vvalues are not changed.

Image
Setup Changes


 

consider importing the DateTime class and working with its timezone features.

php
namespace Drupal\tamper\Plugin\Tamper;
use DateTime
use DateTimeZone
use Drupal\Core\Form\FormStateInterface
use Drupal\tamper\Exception\TamperException; use Drupal\tamper\TamperableItemInterface
use Drupal\tamper\TamperBase;

use the DateTime class to create new datetime objects with specific timezones, and manipulate them as needed within your tamper.

drupal_get_user_timezone(). It returns the timezone object based on the user's timezone preference in their account settings, or the site's timezone if the user is not logged in or has not set a preference. You can use this function to get the timezone object and then pass it to the DateTime constructor. Here's an example:

EST Timestamp
UTC Timestamp