本文整理汇总了Java中java.time.temporal.IsoFields类的典型用法代码示例。如果您正苦于以下问题:Java IsoFields类的具体用法?Java IsoFields怎么用?Java IsoFields使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IsoFields类属于java.time.temporal包,在下文中一共展示了IsoFields类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPreviousPeriod
import java.time.temporal.IsoFields; //导入依赖的package包/类
private long getPreviousPeriod(Tick tick, int indexOfPreviousTick) {
switch (timeLevel) {
case DAY: // return previous day
int prevCalendarDay = tick.getEndTime().minusDays(1).getDayOfYear();
// skip weekend and holidays:
while (getTimeSeries().getTick(indexOfPreviousTick).getEndTime().getDayOfYear() != prevCalendarDay && indexOfPreviousTick > 0) {
prevCalendarDay--;
}
return prevCalendarDay;
case WEEK: // return previous week
return tick.getEndTime().minusWeeks(1).get(IsoFields.WEEK_OF_WEEK_BASED_YEAR);
case MONTH: // return previous month
return tick.getEndTime().minusMonths(1).getMonthValue();
default: // return previous year
return tick.getEndTime().minusYears(1).getYear();
}
}
示例2: test_parse_parseLenientQuarter_SMART
import java.time.temporal.IsoFields; //导入依赖的package包/类
@Test(dataProvider = "parseLenientQuarter")
public void test_parse_parseLenientQuarter_SMART(String str, LocalDate expected, boolean smart) {
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(YEAR).appendLiteral(':')
.appendValue(IsoFields.QUARTER_OF_YEAR).appendLiteral(':')
.appendValue(IsoFields.DAY_OF_QUARTER)
.toFormatter().withResolverStyle(ResolverStyle.SMART);
if (smart) {
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, expected);
} else {
try {
LocalDate.parse(str, f);
fail("Should have failed");
} catch (DateTimeParseException ex) {
// expected
}
}
}
示例3: test_parse_parseLenientWeek_SMART
import java.time.temporal.IsoFields; //导入依赖的package包/类
@Test(dataProvider = "parseLenientWeek")
public void test_parse_parseLenientWeek_SMART(String str, LocalDate expected, boolean smart) {
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(IsoFields.WEEK_BASED_YEAR).appendLiteral(':')
.appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR).appendLiteral(':')
.appendValue(DAY_OF_WEEK)
.toFormatter().withResolverStyle(ResolverStyle.SMART);
if (smart) {
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, expected);
} else {
try {
LocalDate.parse(str, f);
fail("Should have failed");
} catch (DateTimeParseException ex) {
// expected
}
}
}
示例4: data_resolveTwoNoChange
import java.time.temporal.IsoFields; //导入依赖的package包/类
@DataProvider(name="resolveTwoNoChange")
Object[][] data_resolveTwoNoChange() {
return new Object[][]{
{YEAR, 2012, MONTH_OF_YEAR, 5},
{YEAR, 2012, DAY_OF_MONTH, 5},
{YEAR, 2012, DAY_OF_WEEK, 5},
{YEAR, 2012, ALIGNED_WEEK_OF_YEAR, 5},
{YEAR, 2012, ALIGNED_WEEK_OF_MONTH, 5},
{YEAR, 2012, IsoFields.QUARTER_OF_YEAR, 3},
{YEAR, 2012, MINUTE_OF_HOUR, 5},
{YEAR, 2012, SECOND_OF_MINUTE, 5},
{YEAR, 2012, NANO_OF_SECOND, 5},
{MONTH_OF_YEAR, 5, DAY_OF_MONTH, 5},
{MONTH_OF_YEAR, 5, DAY_OF_WEEK, 5},
{MONTH_OF_YEAR, 5, ALIGNED_WEEK_OF_YEAR, 5},
{MONTH_OF_YEAR, 5, ALIGNED_WEEK_OF_MONTH, 5},
{MONTH_OF_YEAR, 3, IsoFields.QUARTER_OF_YEAR, 5},
{MONTH_OF_YEAR, 5, MINUTE_OF_HOUR, 5},
{MONTH_OF_YEAR, 5, SECOND_OF_MINUTE, 5},
{MONTH_OF_YEAR, 5, NANO_OF_SECOND, 5},
};
}
示例5: getPeriod
import java.time.temporal.IsoFields; //导入依赖的package包/类
private long getPeriod(Tick tick) {
switch (timeLevel) {
case DAY: // return previous day
return tick.getEndTime().getDayOfYear();
case WEEK: // return previous week
return tick.getEndTime().get(IsoFields.WEEK_OF_WEEK_BASED_YEAR);
case MONTH: // return previous month
return tick.getEndTime().getMonthValue();
default: // return previous year
return tick.getEndTime().getYear();
}
}
示例6: test_parse_quarters
import java.time.temporal.IsoFields; //导入依赖的package包/类
@Test(dataProvider = "quarter")
public void test_parse_quarters(LocalDate date, int doq, int qoy) {
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(YEAR).appendLiteral('-')
.appendValue(IsoFields.QUARTER_OF_YEAR).appendLiteral('-')
.appendValue(IsoFields.DAY_OF_QUARTER)
.toFormatter().withResolverStyle(ResolverStyle.STRICT);
LocalDate parsed = LocalDate.parse(date.getYear() + "-" + qoy + "-" + doq, f);
assertEquals(parsed, date);
}
示例7: test_parse_quarters_SMART
import java.time.temporal.IsoFields; //导入依赖的package包/类
@Test(dataProvider = "quarter")
public void test_parse_quarters_SMART(LocalDate date, int doq, int qoy) {
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(YEAR).appendLiteral('-')
.appendValue(IsoFields.QUARTER_OF_YEAR).appendLiteral('-')
.appendValue(IsoFields.DAY_OF_QUARTER)
.toFormatter().withResolverStyle(ResolverStyle.SMART);
LocalDate parsed = LocalDate.parse(date.getYear() + "-" + qoy + "-" + doq, f);
assertEquals(parsed, date);
}
示例8: test_parse_quarters_LENIENT
import java.time.temporal.IsoFields; //导入依赖的package包/类
@Test(dataProvider = "quarter")
public void test_parse_quarters_LENIENT(LocalDate date, int doq, int qoy) {
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(YEAR).appendLiteral('-')
.appendValue(IsoFields.QUARTER_OF_YEAR).appendLiteral('-')
.appendValue(IsoFields.DAY_OF_QUARTER)
.toFormatter().withResolverStyle(ResolverStyle.LENIENT);
LocalDate parsed = LocalDate.parse(date.getYear() + "-" + qoy + "-" + doq, f);
assertEquals(parsed, date);
}
示例9: test_parse_parseLenientQuarter_STRICT
import java.time.temporal.IsoFields; //导入依赖的package包/类
@Test(dataProvider = "parseLenientQuarter", expectedExceptions = DateTimeParseException.class)
public void test_parse_parseLenientQuarter_STRICT(String str, LocalDate expected, boolean smart) {
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(YEAR).appendLiteral(':')
.appendValue(IsoFields.QUARTER_OF_YEAR).appendLiteral(':')
.appendValue(IsoFields.DAY_OF_QUARTER)
.toFormatter().withResolverStyle(ResolverStyle.STRICT);
LocalDate.parse(str, f);
}
示例10: test_parse_parseLenientQuarter_LENIENT
import java.time.temporal.IsoFields; //导入依赖的package包/类
@Test(dataProvider = "parseLenientQuarter")
public void test_parse_parseLenientQuarter_LENIENT(String str, LocalDate expected, boolean smart) {
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(YEAR).appendLiteral(':')
.appendValue(IsoFields.QUARTER_OF_YEAR).appendLiteral(':')
.appendValue(IsoFields.DAY_OF_QUARTER)
.toFormatter().withResolverStyle(ResolverStyle.LENIENT);
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, expected);
}
示例11: test_parse_weeks_STRICT
import java.time.temporal.IsoFields; //导入依赖的package包/类
@Test(dataProvider="week")
public void test_parse_weeks_STRICT(LocalDate date, DayOfWeek dow, int week, int wby) {
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(IsoFields.WEEK_BASED_YEAR).appendLiteral('-')
.appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR).appendLiteral('-')
.appendValue(DAY_OF_WEEK)
.toFormatter().withResolverStyle(ResolverStyle.STRICT);
LocalDate parsed = LocalDate.parse(wby + "-" + week + "-" + dow.getValue(), f);
assertEquals(parsed, date);
}
示例12: test_parse_weeks_SMART
import java.time.temporal.IsoFields; //导入依赖的package包/类
@Test(dataProvider="week")
public void test_parse_weeks_SMART(LocalDate date, DayOfWeek dow, int week, int wby) {
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(IsoFields.WEEK_BASED_YEAR).appendLiteral('-')
.appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR).appendLiteral('-')
.appendValue(DAY_OF_WEEK)
.toFormatter().withResolverStyle(ResolverStyle.SMART);
LocalDate parsed = LocalDate.parse(wby + "-" + week + "-" + dow.getValue(), f);
assertEquals(parsed, date);
}
示例13: test_parse_weeks_LENIENT
import java.time.temporal.IsoFields; //导入依赖的package包/类
@Test(dataProvider="week")
public void test_parse_weeks_LENIENT(LocalDate date, DayOfWeek dow, int week, int wby) {
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(IsoFields.WEEK_BASED_YEAR).appendLiteral('-')
.appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR).appendLiteral('-')
.appendValue(DAY_OF_WEEK)
.toFormatter().withResolverStyle(ResolverStyle.LENIENT);
LocalDate parsed = LocalDate.parse(wby + "-" + week + "-" + dow.getValue(), f);
assertEquals(parsed, date);
}
示例14: test_parse_parseLenientWeek_STRICT
import java.time.temporal.IsoFields; //导入依赖的package包/类
@Test(dataProvider = "parseLenientWeek", expectedExceptions = DateTimeParseException.class)
public void test_parse_parseLenientWeek_STRICT(String str, LocalDate expected, boolean smart) {
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(IsoFields.WEEK_BASED_YEAR).appendLiteral(':')
.appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR).appendLiteral(':')
.appendValue(DAY_OF_WEEK)
.toFormatter().withResolverStyle(ResolverStyle.STRICT);
LocalDate.parse(str, f);
}
示例15: test_parse_parseLenientWeek_LENIENT
import java.time.temporal.IsoFields; //导入依赖的package包/类
@Test(dataProvider = "parseLenientWeek")
public void test_parse_parseLenientWeek_LENIENT(String str, LocalDate expected, boolean smart) {
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(IsoFields.WEEK_BASED_YEAR).appendLiteral(':')
.appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR).appendLiteral(':')
.appendValue(DAY_OF_WEEK)
.toFormatter().withResolverStyle(ResolverStyle.LENIENT);
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, expected);
}