/* Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.flowable.engine.common.impl.util;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;

/**
 * @author Joram Barrez
 */
public class DefaultClockImpl implements org.flowable.engine.common.runtime.Clock {

    private static volatile Calendar CURRENT_TIME;

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

        if (currentTime != null) {
            time = new GregorianCalendar();
            time.setTime(currentTime);
        }

        setCurrentCalendar(time);
    }

    @Override
    public void setCurrentCalendar(Calendar currentTime) {
        CURRENT_TIME = currentTime;
    }

    @Override
    public void reset() {
        CURRENT_TIME = null;
    }

    @Override
    public Date getCurrentTime() {
        return CURRENT_TIME == null ? new Date() : CURRENT_TIME.getTime();
    }

    @Override
    public Calendar getCurrentCalendar() {
        return CURRENT_TIME == null ? new GregorianCalendar() : (Calendar) CURRENT_TIME.clone();
    }

    @Override
    public Calendar getCurrentCalendar(TimeZone timeZone) {
        return TimeZoneUtil.convertToTimeZone(getCurrentCalendar(), timeZone);
    }

    @Override
    public TimeZone getCurrentTimeZone() {
        return getCurrentCalendar().getTimeZone();
    }

}

@@ -832,17 +832,16 @@
 Clock %7B%0A
-%0A
     priv
@@ -844,16 +844,49 @@
 private 
+TimeZone timeZone;%0A    protected 
 static v
@@ -917,16 +917,145 @@
 _TIME;%0A%0A
+    public DefaultClockImpl() %7B%0A    %7D%0A%0A    public DefaultClockImpl(TimeZone timeZone) %7B%0A        this.timeZone = timeZone;%0A    %7D%0A%0A
     @Ove
@@ -1196,38 +1196,94 @@
  time = 
-new GregorianCalendar(
+(null == timeZone ) ? new GregorianCalendar() : new GregorianCalendar(timeZone
 );%0A     
@@ -1615,32 +1615,40 @@
 %7B%0A        return
+ null ==
  CURRENT_TIME ==
@@ -1641,32 +1641,24 @@
 URRENT_TIME 
-== null 
 ? new Date()
@@ -1756,22 +1756,27 @@
         
-return
+if (null ==
  CURRENT
@@ -1784,44 +1784,136 @@
 TIME
- == null ? new GregorianCalendar() :
+) %7B%0A            return (null == timeZone) ? new GregorianCalendar() : new GregorianCalendar(timeZone);%0A        %7D%0A%0A        return
  (Ca

Update DefaultClockImpl to support specified timezone