All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.approvaltests.utils.WithTimeZone Maven / Gradle / Ivy

There is a newer version: 24.9.0
Show newest version
package org.approvaltests.utils;

import java.util.TimeZone;
import java.util.concurrent.locks.ReentrantLock;

public class WithTimeZone implements AutoCloseable
{
  private static final ReentrantLock defaultTimeZoneLock = new ReentrantLock();
  private final TimeZone             tz;
  public WithTimeZone()
  {
    this("UTC");
  }
  public WithTimeZone(String zoneId)
  {
    tz = TimeZone.getDefault();
    defaultTimeZoneLock.lock();
    TimeZone.setDefault(TimeZone.getTimeZone(zoneId));
  }
  @Override
  public void close()
  {
    TimeZone.setDefault(tz);
    defaultTimeZoneLock.unlock();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy