use of java.time.ZoneOffset in project jdk8u_jdk by JetBrains.
the class ZoneInfoOld method transToString.
private int transToString(long val, int off_old, int[] offsets, StringBuilder sb) {
int dst = (int) ((val >>> DST_NSHIFT) & 0xfL);
int save = (dst == 0) ? 0 : offsets[dst] / 1000;
int off = offsets[(int) (val & OFFSET_MASK)] / 1000;
long second = (val >> TRANSITION_NSHIFT) / 1000;
ZoneOffset offset_old = ZoneOffset.ofTotalSeconds(off_old);
ZoneOffset offset = ZoneOffset.ofTotalSeconds(off);
sb.append(" " + LocalDateTime.ofEpochSecond(second, 0, offset_old));
sb.append(" [utc=" + second + " raw=" + Long.toHexString(val >> TRANSITION_NSHIFT) + ", offset=" + off + "/" + offset + ", saving=" + save + "]");
return off;
}
use of java.time.ZoneOffset in project jmeter by apache.
the class TimeShift method execute.
/** {@inheritDoc} */
@Override
public String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException {
String dateString;
LocalDateTime localDateTimeToShift = LocalDateTime.now(systemDefaultZoneID);
DateTimeFormatter formatter = null;
if (!StringUtils.isEmpty(format)) {
try {
formatter = dateTimeFormatterCache.get(format, key -> createFormatter((String) key));
} catch (IllegalArgumentException ex) {
// $NON-NLS-1$
log.error("Format date pattern '{}' is invalid (see https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html)", format, ex);
return "";
}
}
if (!dateToShift.isEmpty()) {
try {
if (formatter != null) {
localDateTimeToShift = LocalDateTime.parse(dateToShift, formatter);
} else {
localDateTimeToShift = LocalDateTime.ofInstant(Instant.ofEpochMilli(Long.parseLong(dateToShift)), ZoneId.systemDefault());
}
} catch (DateTimeParseException | NumberFormatException ex) {
// $NON-NLS-1$
log.error("Failed to parse the date '{}' to shift", dateToShift, ex);
}
}
// Check amount value to shift
if (!StringUtils.isEmpty(amountToShift)) {
try {
Duration duration = Duration.parse(amountToShift);
localDateTimeToShift = localDateTimeToShift.plus(duration);
} catch (DateTimeParseException ex) {
// $NON-NLS-1$
log.error("Failed to parse the amount duration '{}' to shift (see https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html#parse-java.lang.CharSequence-) ", amountToShift, ex);
}
}
if (formatter != null) {
dateString = localDateTimeToShift.format(formatter);
} else {
ZoneOffset offset = ZoneOffset.systemDefault().getRules().getOffset(localDateTimeToShift);
dateString = String.valueOf(localDateTimeToShift.toInstant(offset).toEpochMilli());
}
if (!StringUtils.isEmpty(variableName)) {
JMeterVariables vars = getVariables();
if (vars != null) {
// vars will be null on TestPlan
vars.put(variableName, dateString);
}
}
return dateString;
}
Aggregations