- 使用 Spring Initializr 创建 Spring Boot 应用程序
- 在Spring Boot中配置Cassandra
- 在 Spring Boot 上配置 Tomcat 连接池
- 将Camel消息路由到嵌入WildFly的Artemis上
本文整理了Java中java.time.YearMonth.until()
方法的一些代码示例,展示了YearMonth.until()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YearMonth.until()
方法的具体详情如下:
包路径:java.time.YearMonth
类名称:YearMonth
方法名:until
[英]Calculates the period between this year-month and another year-month in terms of the specified unit.
This calculates the period between two year-months in terms of a single unit. The start and end points are this and the specified year-month. The result will be negative if the end is before the start. The Temporal passed to this method must be a YearMonth. For example, the period in years between two year-months can be calculated using startYearMonth.until(endYearMonth, YEARS).
The calculation returns a whole number, representing the number of complete units between the two year-months. For example, the period in decades between 2012-06 and 2032-05 will only be one decade as it is one month short of two decades.
This method operates in association with TemporalUnit#between. The result of this method is a long representing the amount of the specified unit. By contrast, the result of between is an object that can be used directly in addition/subtraction:
long period = start.until(end, YEARS); // this method
dateTime.plus(YEARS.between(start, end)); // use in plus/minus
The calculation is implemented in this method for ChronoUnit. The units MONTHS, YEARS, DECADES, CENTURIES, MILLENNIA and ERAS are supported. Other ChronoUnit values will throw an exception.
If the unit is not a ChronoUnit, then the result of this method is obtained by invoking TemporalUnit.between(Temporal, Temporal)passing this as the first argument and the input temporal as the second argument.
This instance is immutable and unaffected by this method call.
[中]根据指定的单位计算本年月份和另一年月份之间的期间。
这将根据单个单元计算两个月之间的时间。开始点和结束点为本月和指定的年-月。如果结束早于开始,结果将为负值。传递给此方法的时间必须为一年一个月。例如,可以使用startYearMonth计算两个年月之间的年周期。直到(年底月,年)。
计算结果返回一个整数,表示两年内的完整单元数。例如,从2012-06年到2032-05年的几十年期间将只有十年,因为距离二十年只差一个月。
该方法与TemporalUnit#between结合使用。此方法的结果是一个长的字符,表示指定单位的数量。相比之下,between的结果是一个可以直接用于加法/减法的对象:
long period = start.until(end, YEARS); // this method
dateTime.plus(YEARS.between(start, end)); // use in plus/minus
该计算是在ChronoUnit的这种方法中实现的。支持单位月、年、数十年、世纪、千年和年代。其他ChronoUnit值将引发异常。
如果该单元不是ChronoUnit,则通过调用TemporalUnit获得该方法的结果。(时态,时态)将其作为第一个参数传递,将输入时态作为第二个参数传递。
此实例是不可变的,不受此方法调用的影响。
代码示例来源:origin: stackoverflow.com
public static final long getMonthsDifference(Date date1, Date date2) {
YearMonth m1 = YearMonth.from(date1.toInstant());
YearMonth m2 = YearMonth.from(date2.toInstant());
return m1.until(m2, ChronoUnit.MONTHS) + 1;
}
代码示例来源:origin: owlike/genson
private static long getEpochMonth(YearMonth yearMonth){
return EPOCH_YEAR_MONTH.until(yearMonth, ChronoUnit.MONTHS);
}
代码示例来源:origin: stackoverflow.com
public static void main(String[] args) {
test("June, 1999", "April, 2002");
}
private static void test(String fromMonthYear, String toMonthYear) {
DateTimeFormatter monthYearFormat = DateTimeFormatter.ofPattern("MMMM, uuuu");
YearMonth from = YearMonth.parse(fromMonthYear, monthYearFormat);
YearMonth to = YearMonth.parse(toMonthYear , monthYearFormat);
long months = from.until(to, ChronoUnit.MONTHS);
System.out.printf("%d years and %d months%n", months / 12, months % 12);
}
代码示例来源:origin: OpenGamma/Strata
private double numberOfMonths(YearMonth month) {
return YearMonth.from(valuationDate).until(month, MONTHS);
}
代码示例来源:origin: OpenGamma/Strata
private DoubleArray buildNodeTimes(LocalDate valuationDate, CurveMetadata metadata) {
if (metadata.getXValueType().equals(ValueType.YEAR_FRACTION)) {
return DoubleArray.of(getParameterCount(), i -> {
LocalDate nodeDate = ((DatedParameterMetadata) metadata.getParameterMetadata().get().get(i)).getDate();
return getDayCount().get().yearFraction(valuationDate, nodeDate);
});
} else if (metadata.getXValueType().equals(ValueType.MONTHS)) {
return DoubleArray.of(getParameterCount(), i -> {
LocalDate nodeDate = ((DatedParameterMetadata) metadata.getParameterMetadata().get().get(i)).getDate();
return YearMonth.from(valuationDate).until(YearMonth.from(nodeDate), MONTHS);
});
} else {
throw new IllegalArgumentException("Metadata XValueType should be YearFraction or Months in curve definition");
}
}
代码示例来源:origin: OpenGamma/Strata
public void value_multiplicative() {
InflationNodalCurve curveComputed = InflationNodalCurve.of(CURVE_NOFIX, VAL_DATE_2, LAST_FIX_MONTH_2, LAST_FIX_VALUE,
SEASONALITY_MULTIPLICATIVE_DEF);
for (int i = 1; i < TEST_MONTHS.length; i++) {
double nbMonths = YearMonth.from(VAL_DATE_2).until(TEST_MONTHS[i], MONTHS);
double valueComputed = curveComputed.yValue(nbMonths);
int x = (int) ((nbMonths + 12) % 12);
double valueNoAdj = EXTENDED_CURVE_2.yValue(nbMonths);
double adj = SEASONALITY_MULTIPLICATIVE_COMP_2.get(x);
double valueExpected = valueNoAdj * adj;
assertEquals(valueExpected, valueComputed, TOLERANCE_VALUE);
}
}
代码示例来源:origin: OpenGamma/Strata
public void test_value() {
for (int i = 0; i < TEST_MONTHS.length; i++) {
double valueComputed = INSTANCE.value(TEST_OBS[i]);
YearMonth fixingMonth = TEST_OBS[i].getFixingMonth();
double valueExpected;
if (USCPI_TS.containsDate(fixingMonth.atEndOfMonth())) {
valueExpected = USCPI_TS.get(fixingMonth.atEndOfMonth()).getAsDouble();
} else {
double x = YearMonth.from(VAL_DATE).until(fixingMonth, MONTHS);
valueExpected = CURVE_INFL.yValue(x);
}
assertEquals(valueComputed, valueExpected, TOLERANCE_VALUE, "test " + i);
}
}
代码示例来源:origin: OpenGamma/Strata
public void value_additive() {
InflationNodalCurve curveComputed = InflationNodalCurve.of(CURVE_NOFIX, VAL_DATE_2, LAST_FIX_MONTH_2, LAST_FIX_VALUE,
SEASONALITY_ADDITIVE_DEF);
for (int i = 1; i < TEST_MONTHS.length; i++) {
double nbMonths = YearMonth.from(VAL_DATE_2).until(TEST_MONTHS[i], MONTHS);
double valueComputed = curveComputed.yValue(nbMonths);
int x = (int) ((nbMonths + 12) % 12);
double valueNoAdj = EXTENDED_CURVE_2.yValue(nbMonths);
DoubleArray seasonalityAdditiveCompounded =
seasonalityCompounded(VAL_DATE_2, LAST_FIX_MONTH_2, SEASONALITY_ADDITIVE, (v, a) -> v + a);
double adj = seasonalityAdditiveCompounded.get(x);
double valueExpected = valueNoAdj + adj;
assertEquals(valueExpected, valueComputed, TOLERANCE_VALUE);
}
}
代码示例来源:origin: OpenGamma/Strata
public void test_value_futfixing() {
for (int i = 0; i < TEST_MONTHS.length; i++) {
double valueComputed = INSTANCE_WITH_FUTFIXING.value(TEST_OBS[i]);
YearMonth fixingMonth = TEST_OBS[i].getFixingMonth();
double valueExpected;
if (fixingMonth.isBefore(YearMonth.from(VAL_DATE_2)) && USCPI_TS.containsDate(fixingMonth.atEndOfMonth())) {
valueExpected = USCPI_TS.get(fixingMonth.atEndOfMonth()).getAsDouble();
} else {
double x = YearMonth.from(VAL_DATE_2).until(fixingMonth, MONTHS);
valueExpected = CURVE_INFL2.yValue(x);
}
assertEquals(valueComputed, valueExpected, TOLERANCE_VALUE, "test " + i);
}
}
代码示例来源:origin: OpenGamma/Strata
private static DoubleArray seasonalityCompounded(
LocalDate valDate, YearMonth fixingMonth, DoubleArray seasonality,
DoubleBinaryOperator adjustmentFunction) {
double nbMonths = YearMonth.from(valDate).until(fixingMonth, MONTHS);
double[] seasonalityCompoundedArray = new double[12];
int lastMonthIndex = fixingMonth.getMonth().getValue() - 2;
seasonalityCompoundedArray[(int) ((nbMonths + 12 + 1) % 12)] =
seasonality.get((lastMonthIndex + 1) % 12);
for (int i = 1; i < 12; i++) {
int j = (int) ((nbMonths + 12 + 1 + i) % 12);
seasonalityCompoundedArray[j] = adjustmentFunction.applyAsDouble(
seasonalityCompoundedArray[(j - 1 + 12) % 12], seasonality.get((lastMonthIndex + 1 + i) % 12));
}
return DoubleArray.ofUnsafe(seasonalityCompoundedArray);
}
代码示例来源:origin: OpenGamma/Strata
public void test_value_parameter_sensitivity() {
for (int i = 0; i < TEST_MONTHS.length; i++) {
YearMonth fixingMonth = TEST_OBS[i].getFixingMonth();
if (!USCPI_TS.containsDate(fixingMonth.atEndOfMonth())) {
InflationRateSensitivity ptsExpected = (InflationRateSensitivity) InflationRateSensitivity.of(TEST_OBS[i], 1d);
CurrencyParameterSensitivities psComputed = INSTANCE.parameterSensitivity(ptsExpected);
double x = YearMonth.from(VAL_DATE).until(fixingMonth, MONTHS);
UnitParameterSensitivities sens1 = UnitParameterSensitivities.of(CURVE_INFL.yValueParameterSensitivity(x));
CurrencyParameterSensitivities psExpected =
sens1.multipliedBy(ptsExpected.getCurrency(), ptsExpected.getSensitivity());
assertTrue(psComputed.equalWithTolerance(psExpected, TOLERANCE_DELTA), "test " + i);
}
}
}
代码示例来源:origin: OpenGamma/Strata
public void parameter_sensitivity_additive() {
InflationNodalCurve curve = InflationNodalCurve.of(CURVE_NOFIX, VAL_DATE_2, LAST_FIX_MONTH_2, LAST_FIX_VALUE,
SEASONALITY_ADDITIVE_DEF);
double shift = 1.0E-2;
for (int i = 1; i < TEST_MONTHS.length; i++) {
double nbMonths = YearMonth.from(VAL_DATE_2).until(TEST_MONTHS[i], MONTHS);
UnitParameterSensitivity psComputed = curve.yValueParameterSensitivity(nbMonths);
for (int j = 0; j < TIMES.size(); j++) {
double[] valuePM = new double[2];
for (int pm = 0; pm < 2; pm++) {
DoubleArray shiftedValues = VALUES.with(j, VALUES.get(j) + (1 - 2 * pm) * shift);
InterpolatedNodalCurve intCurveShifted = InterpolatedNodalCurve.of(METADATA, TIMES, shiftedValues, INTERPOLATOR);
InflationNodalCurve seaCurveShifted =
InflationNodalCurve.of(intCurveShifted, VAL_DATE_2, LAST_FIX_MONTH_2, LAST_FIX_VALUE,
SEASONALITY_ADDITIVE_DEF);
valuePM[pm] = seaCurveShifted.yValue(nbMonths);
}
assertEquals(psComputed.getSensitivity().get(j), (valuePM[0] - valuePM[1]) / (2 * shift), TOLERANCE_DELTA);
}
}
}
代码示例来源:origin: OpenGamma/Strata
public void test_value_parameter_sensitivity_futfixing() {
for (int i = 0; i < TEST_MONTHS.length; i++) {
YearMonth fixingMonth = TEST_OBS[i].getFixingMonth();
if (!fixingMonth.isBefore(YearMonth.from(VAL_DATE_2)) && !USCPI_TS.containsDate(fixingMonth.atEndOfMonth())) {
InflationRateSensitivity ptsExpected = (InflationRateSensitivity) InflationRateSensitivity.of(TEST_OBS[i], 1d);
CurrencyParameterSensitivities psComputed = INSTANCE_WITH_FUTFIXING.parameterSensitivity(ptsExpected);
double x = YearMonth.from(VAL_DATE_2).until(fixingMonth, MONTHS);
UnitParameterSensitivities sens1 = UnitParameterSensitivities.of(CURVE_INFL2.yValueParameterSensitivity(x));
CurrencyParameterSensitivities psExpected =
sens1.multipliedBy(ptsExpected.getCurrency(), ptsExpected.getSensitivity());
assertTrue(psComputed.equalWithTolerance(psExpected, TOLERANCE_DELTA), "test " + i);
}
}
}
代码示例来源:origin: OpenGamma/Strata
public void parameter_sensitivity_multiplicative() {
InflationNodalCurve curve = InflationNodalCurve.of(CURVE_NOFIX, VAL_DATE_2, LAST_FIX_MONTH_2, LAST_FIX_VALUE,
SEASONALITY_MULTIPLICATIVE_DEF);
double shift = 1.0E-2;
for (int i = 1; i < TEST_MONTHS.length; i++) {
double nbMonths = YearMonth.from(VAL_DATE_2).until(TEST_MONTHS[i], MONTHS);
UnitParameterSensitivity psComputed = curve.yValueParameterSensitivity(nbMonths);
for (int j = 0; j < TIMES.size(); j++) {
double[] valuePM = new double[2];
for (int pm = 0; pm < 2; pm++) {
DoubleArray shiftedValues = VALUES.with(j, VALUES.get(j) + (1 - 2 * pm) * shift);
InterpolatedNodalCurve intCurveShifted = InterpolatedNodalCurve.of(METADATA, TIMES, shiftedValues, INTERPOLATOR);
InflationNodalCurve seaCurveShifted =
InflationNodalCurve.of(intCurveShifted, VAL_DATE_2, LAST_FIX_MONTH_2, LAST_FIX_VALUE,
SEASONALITY_MULTIPLICATIVE_DEF);
valuePM[pm] = seaCurveShifted.yValue(nbMonths);
}
assertEquals(psComputed.getSensitivity().get(j), (valuePM[0] - valuePM[1]) / (2 * shift), TOLERANCE_DELTA);
}
}
}
代码示例来源:origin: OpenGamma/Strata
double nbMonth = valuationMonth.until(lastMonth, MONTHS);
DoubleArray x = curveWithoutFixing.getXValues();
ArgChecker.isTrue(nbMonth < x.get(0), "The first estimation month should be after the last known index fixing");
我尝试理解[c代码 -> 汇编]代码 void node::Check( data & _data1, vector& _data2) { -> push ebp -> mov ebp,esp ->
我需要在当前表单(代码)的上下文中运行文本文件中的代码。其中一项要求是让代码创建新控件并将其添加到当前窗体。 例如,在Form1.cs中: using System.Windows.Forms; ..
我有此 C++ 代码并将其转换为 C# (.net Framework 4) 代码。有没有人给我一些关于 malloc、free 和 sprintf 方法的提示? int monate = ee; d
我的网络服务器代码有问题 #include #include #include #include #include #include #include int
给定以下 html 代码,将列表中的第三个元素(即“美丽”一词)以斜体显示的 CSS 代码是什么?当然,我可以给这个元素一个 id 或一个 class,但 html 代码必须保持不变。谢谢
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
我试图制作一个宏来避免重复代码和注释。 我试过这个: #define GrowOnPage(any Page, any Component) Component.Width := Page.Surfa
我正在尝试将我的旧 C++ 代码“翻译”成头条新闻所暗示的 C# 代码。问题是我是 C# 中的新手,并不是所有的东西都像 C++ 中那样。在 C++ 中这些解决方案运行良好,但在 C# 中只是不能。我
在 Windows 10 上工作,R 语言的格式化程序似乎没有在 Visual Studio Code 中完成它的工作。我试过R support for Visual Studio Code和 R-T
我正在处理一些报告(计数),我必须获取不同参数的计数。非常简单但乏味。 一个参数的示例查询: qCountsEmployee = ( "select count(*) from %s wher
最近几天我尝试从 d00m 调试网络错误。我开始用尽想法/线索,我希望其他 SO 用户拥有可能有用的宝贵经验。我希望能够提供所有相关信息,但我个人无法控制服务器环境。 整个事情始于用户注意到我们应用程
我有一个 app.js 文件,其中包含如下 dojo amd 模式代码: require(["dojo/dom", ..], function(dom){ dom.byId('someId').i
我对“-gencode”语句中的“code=sm_X”选项有点困惑。 一个例子:NVCC 编译器选项有什么作用 -gencode arch=compute_13,code=sm_13 嵌入库中? 只有
我为我的表格使用 X-editable 框架。 但是我有一些问题。 $(document).ready(function() { $('.access').editable({
我一直在通过本教程学习 flask/python http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-wo
我想将 Vim 和 EMACS 用于 CNC、G 代码和 M 代码。 Vim 或 EMACS 是否有任何语法或模式来处理这种类型的代码? 最佳答案 一些快速搜索使我找到了 this vim 和 thi
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?更新问题,使其成为 on-topic对于堆栈溢出。 7年前关闭。 Improve this
这个问题在这里已经有了答案: Enabling markdown highlighting in Vim (5 个回答) 6年前关闭。 当我在 Vim 中编辑包含 Markdown 代码的 READM
我正在 Swift3 iOS 中开发视频应用程序。基本上我必须将视频 Assets 和音频与淡入淡出效果合并为一个并将其保存到 iPhone 画廊。为此,我使用以下方法: private func d
pipeline { agent any stages { stage('Build') { steps { e
我是一名优秀的程序员,十分优秀!