当前位置: 首页>>代码示例>>Java>>正文


Java Period.ofWeeks方法代码示例

本文整理汇总了Java中java.time.Period.ofWeeks方法的典型用法代码示例。如果您正苦于以下问题:Java Period.ofWeeks方法的具体用法?Java Period.ofWeeks怎么用?Java Period.ofWeeks使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.time.Period的用法示例。


在下文中一共展示了Period.ofWeeks方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: apply

import java.time.Period; //导入方法依赖的package包/类
@Override
public final Period apply(String value) {
    try {
        if (getNullChecker().applyAsBoolean(value)) {
            return null;
        } else {
            final Matcher matcher = pattern.matcher(value);
            if (matcher.matches()) {
                final int digits = Integer.parseInt(matcher.group(1));
                final char code = matcher.group(2).toUpperCase().charAt(0);
                switch (code) {
                    case 'D':   return Period.ofDays(digits);
                    case 'W':   return Period.ofWeeks(digits);
                    case 'M':   return Period.ofMonths(digits);
                    case 'Y':   return Period.ofYears(digits);
                    default:    throw new IllegalArgumentException("Unsupported period type: " + code);
                }
            } else {
                throw new IllegalArgumentException("Cannot parse value into an Period: " + value + " pattern: " + pattern.pattern());
            }
        }
    } catch (Exception ex) {
        throw new FormatException("Failed to parse value into Period: " + value, ex);
    }
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:26,代码来源:ParserOfPeriod.java

示例2: singleRule

import java.time.Period; //导入方法依赖的package包/类
@Test
public void singleRule() {
    final Builder<RuleSetBuilder, DecisionTreeRuleSet> ruleSetBuilder = ruleSetBuilder();
    final Instant now = Instant.now();
    final Period period = Period.ofWeeks(4);

    CommisionRuleSetSupplier.addRule(ruleSetBuilder, "*", "CME", "*", "*", "INDEX", now.minus(period),
            now.plus(period), 1L, "1.1");
    final DecisionTreeRuleSet ruleSet = ruleSetBuilder.build();
    final TreeNode node = constructTree(ruleSet);
    Assert.assertNotNull(node);

    checkMatch(inputC, now, node, 1L);

    checkNoMatch(inputC, now.plus(Period.ofWeeks(8)), node);
    checkNoMatch(inputC, now.minus(Period.ofWeeks(8)), node);

    checkMatch(inputC, now.plus(Period.ofDays(2)), node, 1L);

    checkNoMatch(inputA, now, node);
    checkNoMatch(inputB, now, node);
    checkNoMatch(inputD, now, node);
    checkNoMatch(inputE, now, node);
    checkNoMatch(inputF, now, node);
}
 
开发者ID:jpmorganchase,项目名称:swblocks-decisiontree,代码行数:26,代码来源:DatedEvaluatorTest.java

示例3: main

import java.time.Period; //导入方法依赖的package包/类
public static void main(String[] args) {
    Period period = Period.of(1, 2, 7);
    Period period2 = Period.ofYears(2);
    Period period3 = Period.ofMonths(5);
    Period period4 = Period.ofWeeks(10);
    Period period5 = Period.ofDays(15);

    Period period6 = Period.ofDays(15);

    Period p5Yrs1 = Period.parse("P5y");
    Period p5Yrs2 = Period.parse("p5y");
    Period p5Yrs3 = Period.parse("P5Y");
    Period p5Yrs4 = Period.parse("+P5Y");
    Period p5Yrs5 = Period.parse("P+5Y");
    Period p5Yrs6 = Period.parse("-P-5Y");

    System.out.printf("%s : %s", p5Yrs1, p5Yrs2);
    System.out.println();
    System.out.printf("-P-5Y: %s", p5Yrs6);
    System.out.println();

    Period p5Yrs7 = Period.parse("P5y1m2d");
    Period p5Yrs8 = Period.parse("p9m");
    Period p5Yrs9 = Period.parse("P60d");

    // For the string form PnW, the count of weeks is multiplied by 7 to
    // get the number of days
    Period p5Yrs10 = Period.parse("-P5Y5W");

    System.out.printf("p5Yrs7: %s,  p5Yrs8: %s, p5Yrs9: %s, p5Yrs10: %s",
            p5Yrs7,
            p5Yrs8,
            p5Yrs9,
            p5Yrs10);
    System.out.println();

    // static method between
    LocalDate carnivalStart = LocalDate.of(2050, 12, 31);
    LocalDate carnivalEnd = LocalDate.of(2051, 1, 2);

    // period = endDate - startDate
    Period periodBetween = Period.between(carnivalEnd, carnivalStart);
    System.out.println(periodBetween );

}
 
开发者ID:huby,项目名称:java-se8-oca-study-guide,代码行数:46,代码来源:Main.java


注:本文中的java.time.Period.ofWeeks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。