cancel
Showing results for 
Search instead for 
Did you mean: 

Activiti to Use UTC date time

dineshnk1
Champ in-the-making
Champ in-the-making
Hello,

Can we store using UTC time zone in activiti tables?

My problem is that User should fetch and see the data in their local time zone. If it will be in UTC format in tables, then it can change it to user's timezone before displaying.

Is there any way to use UTC Date time in activiti tables.

-

4 REPLIES 4

dineshnk1
Champ in-the-making
Champ in-the-making
I have checked in my activiti tables, On starting a process instance and creating tasks, It used current time zone. But I need to store in UTC time zone.

Can somebody help me on this?

_

jbarrez
Star Contributor
Star Contributor
Which database? For example on mysql, dates are generally stored in UTC.

dineshnk1
Champ in-the-making
Champ in-the-making
I am using Oracle Database.
I did some operations on Task and checked in the Activiti tables. It is storing in local time zone on which server is running.

-
Dinesh

dineshnk1
Champ in-the-making
Champ in-the-making
I got a solution cause of activiti workflow, it is very much extendible almost all points in API. Thanks to activiti developers.

I have extended DefaultClockImpl class of activiti and override the required method to use Calendar for my purpose. Activti uses Clock to get and set Time in their entities, wherever required.

My Project is using Spring framework and did Java configuration for workflow project, So I did below changes to register my class, while doing Process engine configuration:
Override DefaultClockImpl Class
<java>public class CustomDefaultClockImpl extends DefaultClockImpl {

  private static volatile Calendar CURRENT_TIME = null;

  @Override
  public void setCurrentTime(Date currentTime) {
    Calendar time = null;

    if (currentTime != null) {
      time = new GregorianCalendar();
      time.setTimeZone(TimeZone.getTimeZone("UTC"));
      time.setTime(currentTime);
    }

    setCurrentCalendar(time);
  }

  @Override
  public Calendar getCurrentCalendar() {
    Calendar calendar = new GregorianCalendar();
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    return CURRENT_TIME == null ? calendar : (Calendar) CURRENT_TIME.clone();
  }
}</java>
Create a Spring bean  of Clock:
<java>
@Bean
  public Clock clock(){
// CustomDefaultClockImpl is class which extends DefaultClockImpl
    Clock clock = new CustomDefaultClockImpl();
    return clock;
  }
</java>
and While doing process engine configuration :
<java>
SpringProcessEngineConfiguration processEngineConfiguration =
        new SpringProcessEngineConfiguration();
// Calling above method to register spring bean in activiti configuration
processEngineConfiguration.setClock(clock());
</java>
Now it will store using UTC time zone in all activiti tables, wherever date time is present in tables.