import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.Duration;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.ZoneOffset;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
return now;
}
+ @Override
+ public Instant now() {
+ return Instant.ofEpochMilli(now);
+ }
+
@Override
public MonotonicClock getClock() {
return () -> {
return getTimeZone().getOffset(when) / (60 * 1000);
}
+ @Override
+ public ZoneOffset getTimeZoneAt(Instant when) {
+ return getTimeZoneId().getRules().getOffset(when);
+ }
+
@Override
public TimeZone getTimeZone() {
return TimeZone.getTimeZone("GMT-03:30");
}
+ @Override
+ public ZoneId getTimeZoneId() {
+ return ZoneOffset.ofHoursMinutes(-3, 30);
+ }
+
@Override
public Locale getLocale() {
return Locale.US;
import java.nio.file.Paths;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.ZoneOffset;
import java.util.Locale;
import java.util.TimeZone;
import java.util.concurrent.atomic.AtomicReference;
return System.currentTimeMillis();
}
+ @Override
+ public Instant now() {
+ return Instant.now();
+ }
+
@Override
public int getTimezone(long when) {
return getTimeZone().getOffset(when) / (60 * 1000);
}
+
+ @Override
+ public ZoneOffset getTimeZoneAt(Instant when) {
+ return getTimeZoneId().getRules().getOffset(when);
+ }
}
/**
return delegate.getCurrentTime();
}
+ @Override
+ public Instant now() {
+ return delegate.now();
+ }
+
@Override
public int getTimezone(long when) {
return delegate.getTimezone(when);
}
+
+ @Override
+ public ZoneOffset getTimeZoneAt(Instant when) {
+ return delegate.getTimeZoneAt(when);
+ }
}
private static volatile SystemReader INSTANCE = DEFAULT;
* Get the current system time
*
* @return the current system time
+ *
+ * @deprecated Use {@link #now()}
*/
+ @Deprecated
public abstract long getCurrentTime();
+ /**
+ * Get the current system time
+ *
+ * @return the current system time
+ *
+ * @since 7.1
+ */
+ public abstract Instant now();
+
/**
* Get clock instance preferred by this system.
*
* @param when
* a system timestamp
* @return the local time zone
+ *
+ * @deprecated Use {@link #getTimeZoneAt(Instant)} instead.
*/
+ @Deprecated
public abstract int getTimezone(long when);
+ /**
+ * Get the local time zone offset at "when" time
+ *
+ * @param when
+ * a system timestamp
+ * @return the local time zone
+ * @since 7.1
+ */
+ public abstract ZoneOffset getTimeZoneAt(Instant when);
+
/**
* Get system time zone, possibly mocked for testing
*
* @return system time zone, possibly mocked for testing
* @since 1.2
+ *
+ * @deprecated Use {@link #getTimeZoneId()}
*/
+ @Deprecated
public TimeZone getTimeZone() {
return TimeZone.getDefault();
}
+ /**
+ * Get system time zone, possibly mocked for testing
+ *
+ * @return system time zone, possibly mocked for testing
+ * @since 7.1
+ */
+ public ZoneId getTimeZoneId() {
+ return ZoneId.systemDefault();
+ }
+
/**
* Get the locale to use
*