Converting to a specific timezone


#1

I have some time fields indexed with UTC format. As I could notice, the data is automatically converted to local time. Let’s say I open my app in a different time zone. Would this be the same? How can I set a dashboard to a different timezone?


#2

For your first question the answer is yes. ChartFactor will use the local timezone if none is provided, that’s why we strongly recommend everyone to use UTC as the format to store dates.

You can apply any timezone to your dashboard through the custom metadata as specified in the timezone documentation. Notice that timezones can be specified at field level (it will just affect that field) or at source level.


#3

Hi @eduardo, thanks for pointing me to the documentation. I was able to play with it and it’s pretty straightforward. As you mentioned, I saw that is possible to specify a timezone for a given field and my next question will be: How could I specify multiple timezones for the same field, so I can show several visualizations with the same data but different timezones?


#4

Well, ChartFactor allows only one timezone configuration by field since it is the most common case. However there are a couple things you can do:

1- The first one is to have a field by timezone (or at least a couple extra) in your data source, so you can apply a timezone for each one of then individually. This is only recommended of course if your data sets are small.

2 - The second one is to manipulate your provider configuration for each visualization in order to add the timezone for that specific visualization. You will have to unregister and register the provider to make it work like this.

So let’s say that you have configured a field to use “America/New_york” as a timezone:

const providers = [{
      ...
      metadata: {
         "datasource_name": {
             "fields":  {   
                   "your_field": { "tz":  "America/New_york" }
              }
          }
   }
}]

To change it for a given visual you can do:

providers[0].metadata.datasource_name.fields.your_field.tz = 'Asia/Tokyo';
cf.unregisterProvider({ name: 'elasticsearch' });
cf.registerProvider(providers[0]);

Hope it helps


#5

Modifying the metadata per visualization trick did it. Thanks @eduardo