本文整理汇总了Java中org.threeten.bp.ZonedDateTime.ofInstant方法的典型用法代码示例。如果您正苦于以下问题:Java ZonedDateTime.ofInstant方法的具体用法?Java ZonedDateTime.ofInstant怎么用?Java ZonedDateTime.ofInstant使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.threeten.bp.ZonedDateTime
的用法示例。
在下文中一共展示了ZonedDateTime.ofInstant方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compile
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Override
public CompiledFunctionDefinition compile(final FunctionCompilationContext context, final Instant atInstant) {
final ZonedDateTime atZDT = ZonedDateTime.ofInstant(atInstant, ZoneOffset.UTC);
//TODO work out a way to use dependency graph to get curve information for this config
final CurveConstructionConfiguration curveConstructionConfiguration = _curveConstructionConfigurationSource.getCurveConstructionConfiguration(_configurationName);
if (curveConstructionConfiguration == null) {
throw new OpenGammaRuntimeException("Could not get curve construction configuration called " + _configurationName);
}
final ConventionSource conventionSource = OpenGammaCompilationContext.getConventionSource(context);
final SecuritySource securitySource = OpenGammaCompilationContext.getSecuritySource(context);
final ConfigSource configSource = OpenGammaCompilationContext.getConfigSource(context);
try {
final CurveNodeVisitor<Set<Currency>> visitor = new CurveNodeCurrencyVisitor(conventionSource, securitySource, configSource);
final Set<Currency> currencies = CurveUtils.getCurrencies(curveConstructionConfiguration, _curveDefinitionSource, _curveConstructionConfigurationSource, visitor);
final ValueProperties properties = createValueProperties().with(CURVE_CONSTRUCTION_CONFIG, _configurationName).get();
final ValueSpecification spec = new ValueSpecification(ValueRequirementNames.FX_MATRIX, ComputationTargetSpecification.NULL, properties);
return new MyCompiledFunction(atZDT.with(LocalTime.MIDNIGHT), atZDT.plusDays(1).with(LocalTime.MIDNIGHT).minusNanos(1000000), spec, currencies);
} catch (final Throwable e) {
s_logger.error("{}: problem in CurveConstructionConfiguration called {}", e.getMessage(), _configurationName);
s_logger.error("Full stack trace", e);
throw new OpenGammaRuntimeException(e.getMessage() + ": problem in CurveConstructionConfiguration called " + _configurationName);
}
}
示例2: dateTimeToExpiry
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
protected static Expiry dateTimeToExpiry(final FudgeDateTime datetime, final String timezone) {
switch (datetime.getAccuracy()) {
case NANOSECOND:
case MILLISECOND:
case MICROSECOND:
case SECOND:
case MINUTE:
return new Expiry(ZonedDateTime.ofInstant(datetime.toInstant(), ZoneId.of(timezone)), ExpiryAccuracy.MIN_HOUR_DAY_MONTH_YEAR);
case HOUR:
return new Expiry(ZonedDateTime.ofInstant(datetime.toInstant(), ZoneId.of(timezone)), ExpiryAccuracy.HOUR_DAY_MONTH_YEAR);
case DAY:
return new Expiry(datetime.getDate().toLocalDate().atStartOfDay(ZoneId.of(timezone)), ExpiryAccuracy.DAY_MONTH_YEAR);
case MONTH:
return new Expiry(datetime.getDate().toLocalDate().atStartOfDay(ZoneId.of(timezone)), ExpiryAccuracy.MONTH_YEAR);
case YEAR:
return new Expiry(datetime.getDate().toLocalDate().atStartOfDay(ZoneId.of(timezone)), ExpiryAccuracy.YEAR);
default:
throw new IllegalArgumentException("Invalid accuracy value on " + datetime);
}
}
示例3: expiryBeanToExpiry
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
public static Expiry expiryBeanToExpiry(final ExpiryBean bean) {
if (bean == null) {
return null;
}
final ZonedDateTimeBean zonedDateTimeBean = bean.getExpiry();
final long epochSeconds = zonedDateTimeBean.getDate().getTime() / 1000;
ZonedDateTime zdt = null;
if (zonedDateTimeBean.getZone() == null) {
zdt = ZonedDateTime.ofInstant(Instant.ofEpochSecond(epochSeconds), ZoneOffset.UTC);
} else {
zdt = ZonedDateTime.ofInstant(Instant.ofEpochSecond(epochSeconds), ZoneId.of(zonedDateTimeBean.getZone()));
}
return new Expiry(zdt, bean.getAccuracy());
}
示例4: buildSecurityDirectory
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
/**
* @param buid
* @param tickMsgList
* @return
*/
private File buildSecurityDirectory(String buid, long receivedTS) {
Instant instant = Instant.ofEpochMilli(receivedTS);
ZonedDateTime dateTime = ZonedDateTime.ofInstant(instant, ZoneOffset.UTC);
LocalDate today = dateTime.toLocalDate();
StringBuilder buf = new StringBuilder();
buf.append(_rootDir).append(File.separator);
buf.append(buid).append(File.separator).append(today.getYear()).append(File.separator);
int month = today.getMonthValue();
if (month < 10) {
buf.append("0").append(month);
} else {
buf.append(month);
}
buf.append(File.separator);
int dayOfMonth = today.getDayOfMonth();
if (dayOfMonth < 10) {
buf.append("0").append(dayOfMonth);
} else {
buf.append(dayOfMonth);
}
buf.append(File.separator);
return new File(buf.toString());
}
示例5: compile
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Override
public CompiledFunctionDefinition compile(final FunctionCompilationContext context, final Instant atInstant) {
final ZonedDateTime atZDT = ZonedDateTime.ofInstant(atInstant, ZoneOffset.UTC);
try {
final AbstractCurveSpecification curveSpecification = CurveUtils.getSpecification(atInstant, _curveDefinitionSource, _curveSpecificationBuilder, atZDT.toLocalDate(), _curveName);
final ValueProperties properties = createValueProperties().with(ValuePropertyNames.CURVE, _curveName).get();
final ValueSpecification spec = new ValueSpecification(ValueRequirementNames.CURVE_SPECIFICATION, ComputationTargetSpecification.NULL, properties);
return new MyCompiledFunction(atZDT.with(LocalTime.MIDNIGHT), atZDT.plusDays(1).with(LocalTime.MIDNIGHT).minusNanos(1000000), curveSpecification, spec);
} catch (final Exception e) {
throw new OpenGammaRuntimeException(e.getMessage() + ": problem in CurveSpecification called " + _curveName);
}
}
示例6: compile
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Override
public CompiledFunctionDefinition compile(final FunctionCompilationContext context, final Instant atInstant) {
final ZonedDateTime atZDT = ZonedDateTime.ofInstant(atInstant, ZoneOffset.UTC);
final ValueProperties properties = createValueProperties().with(ValuePropertyNames.CURVE, _curveName).get();
final ValueSpecification spec = new ValueSpecification(ValueRequirementNames.CURVE_MARKET_DATA, ComputationTargetSpecification.NULL, properties);
try {
final AbstractCurveSpecification specification = CurveUtils.getSpecification(atInstant, _curveDefinitionSource, _curveSpecificationBuilder, atZDT.toLocalDate(), _curveName);
return new MyCompiledFunction(atZDT.with(LocalTime.MIDNIGHT), atZDT.plusDays(1).with(LocalTime.MIDNIGHT).minusNanos(1000000), specification, spec);
} catch (final Exception e) {
throw new OpenGammaRuntimeException(e.getMessage() + ": problem in CurveDefinition called " + _curveName);
}
}
示例7: compile
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@SuppressWarnings("synthetic-access")
@Override
public CompiledFunctionDefinition compile(final FunctionCompilationContext context, final Instant atInstant) {
final ZonedDateTime atInstantZDT = ZonedDateTime.ofInstant(atInstant, ZoneOffset.UTC);
final LocalDate curveDate = atInstantZDT.toLocalDate();
final InterpolatedYieldCurveSpecificationBuilder curveSpecificationBuilder = OpenGammaCompilationContext.getInterpolatedYieldCurveSpecificationBuilder(context);
final YieldCurveDefinition definition = _yieldCurveDefinition.get(_curveName + "_" + _currency.getCode());
final InterpolatedYieldCurveSpecification curveSpecification = buildDummyCurve(curveDate, definition);
return new CompiledImpl(atInstantZDT.with(LocalTime.MIDNIGHT).toInstant(), atInstantZDT.plusDays(1).with(LocalTime.MIDNIGHT).minusNanos(1000000).toInstant(), curveSpecification);
}
示例8: compile
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
public Triple<Instant, Instant, InterpolatedYieldCurveSpecification> compile(final FunctionCompilationContext context, final Instant atInstant, final FunctionDefinition functionDefinition) {
init(context, functionDefinition);
//TODO: avoid doing this compile twice all the time
final ZonedDateTime atInstantZDT = ZonedDateTime.ofInstant(atInstant, ZoneOffset.UTC);
final LocalDate curveDate = atInstantZDT.toLocalDate();
final InterpolatedYieldCurveSpecification specification = buildCurve(curveDate);
final Instant expiry = findCurveExpiryDate(context.getSecuritySource(), atInstant, specification, atInstantZDT.with(LocalTime.MIDNIGHT).plusDays(1).minusNanos(1000000).toInstant());
return new Triple<>((expiry != null) ? atInstantZDT.with(LocalTime.MIDNIGHT).toInstant() : null, expiry, specification);
}
示例9: zonedDateTimeBeanToDateTimeWithZone
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
public static ZonedDateTime zonedDateTimeBeanToDateTimeWithZone(final ZonedDateTimeBean date) {
if ((date == null) || (date.getDate() == null)) {
return null;
}
final long epochSeconds = date.getDate().getTime() / 1000;
if (date.getZone() == null) {
return ZonedDateTime.ofInstant(Instant.ofEpochSecond(epochSeconds), ZoneOffset.UTC);
} else {
return ZonedDateTime.ofInstant(Instant.ofEpochSecond(epochSeconds), ZoneId.of(date.getZone()));
}
}
示例10: makeFileNameFromReceivedTimeStamp
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
/**
* @param tickMsg
* @return
*/
private String makeFileNameFromReceivedTimeStamp(FudgeMsg tickMsg) {
String result = null;
//s_logger.warn("cannot determine event time in msg {}, using received timestamp", tickMsg); // Andrew - uncomment before checking back in
Long epochMillis = tickMsg.getLong(RECEIVED_TS_KEY);
Instant instant = Instant.ofEpochMilli(epochMillis);
ZonedDateTime dateTime = ZonedDateTime.ofInstant(instant, ZoneOffset.UTC);
int hourOfDay = dateTime.getHour();
if (hourOfDay < 10) {
result = new StringBuilder("0").append(hourOfDay).toString();
} else {
result = String.valueOf(hourOfDay);
}
return result;
}
示例11: apply
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Override
public ZonedDateTime apply(FromIntegerArguments a) {
return ZonedDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId);
}
示例12: convertJavaDate
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
protected ZonedDateTime convertJavaDate(Date d) {
return ZonedDateTime.ofInstant(Instant.ofEpochMilli(d.getTime()), ZoneId.systemDefault());
}
示例13: compile
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Override
public CompiledFunctionDefinition compile(final FunctionCompilationContext myContext, final Instant atInstant) {
final ZonedDateTime atZDT = ZonedDateTime.ofInstant(atInstant, ZoneOffset.UTC);
return new CompiledFunction(atZDT.with(LocalTime.MIDNIGHT), atZDT.plusDays(1).with(LocalTime.MIDNIGHT).minusNanos(1000000), atZDT, _volatilitySurfaceDefinitionSource,
_volatilitySurfaceSpecificationSource);
}
示例14: compile
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Override
public CompiledFunctionDefinition compile(final FunctionCompilationContext context, final Instant atInstant) {
final ZonedDateTime atZDT = ZonedDateTime.ofInstant(atInstant, ZoneOffset.UTC);
//TODO work out a way to use dependency graph to get curve information for this config
final CurveConstructionConfiguration curveConstructionConfiguration = _curveConstructionConfigurationSource.getCurveConstructionConfiguration(_configurationName);
if (curveConstructionConfiguration == null) {
throw new OpenGammaRuntimeException("Could not get curve construction configuration called " + _configurationName);
}
final Set<ValueRequirement> exogenousRequirements = new HashSet<>();
if (curveConstructionConfiguration.getExogenousConfigurations() != null) {
final List<String> exogenousConfigurations = curveConstructionConfiguration.getExogenousConfigurations();
for (final String name : exogenousConfigurations) {
//TODO deal with arbitrary depth
final ValueProperties properties = ValueProperties.builder()
.with(CURVE_CONSTRUCTION_CONFIG, name)
.with(CURVE_CALCULATION_METHOD, ROOT_FINDING)
.get();
exogenousRequirements.add(new ValueRequirement(CURVE_BUNDLE, ComputationTargetSpecification.NULL, properties));
exogenousRequirements.add(new ValueRequirement(JACOBIAN_BUNDLE, ComputationTargetSpecification.NULL, properties));
}
}
final String[] curveNames = CurveUtils.getCurveNamesForConstructionConfiguration(curveConstructionConfiguration);
final ConventionSource conventionSource = OpenGammaCompilationContext.getConventionSource(context);
final SecuritySource securitySource = OpenGammaCompilationContext.getSecuritySource(context);
final ConfigSource configSource = OpenGammaCompilationContext.getConfigSource(context);
try {
final CurveNodeVisitor<Set<Currency>> visitor = new CurveNodeCurrencyVisitor(conventionSource, securitySource, configSource);
final Set<Currency> currencies = CurveUtils.getCurrencies(curveConstructionConfiguration, _curveDefinitionSource, _curveConstructionConfigurationSource,
visitor);
final String[] currencyStrings = new String[currencies.size()];
int i = 0;
for (final Currency currency : currencies) {
currencyStrings[i++] = currency.getCode();
}
return getCompiledFunction(atZDT.with(LocalTime.MIDNIGHT), atZDT.plusDays(1).with(LocalTime.MIDNIGHT).minusNanos(1000000), curveNames, exogenousRequirements,
curveConstructionConfiguration, currencyStrings);
} catch (final Throwable e) {
s_logger.error("{}: problem in CurveConstructionConfiguration called {}", e.getMessage(), _configurationName);
s_logger.error("Full stack trace", e);
throw new OpenGammaRuntimeException(e.getMessage() + ": problem in CurveConstructionConfiguration called " + _configurationName);
}
}
示例15: compile
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Override
public CompiledFunctionDefinition compile(final FunctionCompilationContext context, final Instant atInstant) {
final MultiCurveCalculationConfig impliedConfiguration = _multiCurveCalculationConfig.get(_impliedCurveCalculationConfig);
if (impliedConfiguration == null) {
throw new OpenGammaRuntimeException("Multi-curve calculation called " + _impliedCurveCalculationConfig + " was null");
}
ComputationTarget target = context.getComputationTargetResolver().resolve(impliedConfiguration.getTarget());
if (!(target.getValue() instanceof Currency)) {
throw new OpenGammaRuntimeException("Target of curve calculation configuration was not a currency");
}
final Currency impliedCurrency = (Currency) target.getValue();
if (!IMPLIED_DEPOSIT.equals(impliedConfiguration.getCalculationMethod())) {
throw new OpenGammaRuntimeException("Curve calculation method was not " + IMPLIED_DEPOSIT + " for configuration called " + _impliedCurveCalculationConfig);
}
final String[] impliedCurveNames = impliedConfiguration.getYieldCurveNames();
if (impliedCurveNames.length != 1) {
throw new OpenGammaRuntimeException("Can only handle configurations with a single implied curve");
}
final LinkedHashMap<String, String[]> originalConfigurationName = impliedConfiguration.getExogenousConfigData();
if (originalConfigurationName == null || originalConfigurationName.size() != 1) {
throw new OpenGammaRuntimeException("Need a configuration with one exogenous configuration");
}
final Map.Entry<String, String[]> entry = Iterables.getOnlyElement(originalConfigurationName.entrySet());
final String[] originalCurveNames = entry.getValue();
if (originalCurveNames.length != 1) {
s_logger.warn("Found more than one exogenous configuration name; using only the first");
}
final MultiCurveCalculationConfig originalConfiguration = _multiCurveCalculationConfig.get(entry.getKey());
if (originalConfiguration == null) {
throw new OpenGammaRuntimeException("Multi-curve calculation called " + entry.getKey() + " was null");
}
target = context.getComputationTargetResolver().resolve(originalConfiguration.getTarget());
if (!(target.getValue() instanceof Currency)) {
throw new OpenGammaRuntimeException("Target of curve calculation configuration was not a currency");
}
final Currency originalCurrency = (Currency) target.getValue();
if (!originalCurrency.equals(impliedCurrency)) {
throw new OpenGammaRuntimeException("Currency targets for configurations " + _impliedCurveCalculationConfig + " and " + entry.getKey() + " did not match");
}
final YieldCurveDefinition impliedDefinition = _yieldCurveDefinition.get(impliedCurveNames[0] + "_" + impliedCurrency.getCode());
if (impliedDefinition == null) {
throw new OpenGammaRuntimeException("Could not get implied definition called " + impliedCurveNames[0] + "_" + impliedCurrency.getCode());
}
final Set<FixedIncomeStrip> strips = impliedDefinition.getStrips();
for (final FixedIncomeStrip strip : strips) {
if (strip.getInstrumentType() != StripInstrumentType.CASH) {
throw new OpenGammaRuntimeException("Can only handle yield curve definitions with CASH strips");
}
}
final ZonedDateTime atZDT = ZonedDateTime.ofInstant(atInstant, ZoneOffset.UTC);
return new MyCompiledFunction(atZDT.with(LocalTime.MIDNIGHT), atZDT.plusDays(1).with(LocalTime.MIDNIGHT).minusNanos(1000000), impliedDefinition, originalConfiguration,
originalCurveNames[0]);
}