本文整理匯總了Java中java.time.Month.length方法的典型用法代碼示例。如果您正苦於以下問題:Java Month.length方法的具體用法?Java Month.length怎麽用?Java Month.length使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.time.Month
的用法示例。
在下文中一共展示了Month.length方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test_next
import java.time.Month; //導入方法依賴的package包/類
@Test
public void test_next() {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(false); i++) {
LocalDate date = date(2007, month, i);
for (DayOfWeek dow : DayOfWeek.values()) {
LocalDate test = (LocalDate) TemporalAdjusters.next(dow).adjustInto(date);
assertSame(test.getDayOfWeek(), dow, date + " " + test);
if (test.getYear() == 2007) {
int dayDiff = test.getDayOfYear() - date.getDayOfYear();
assertTrue(dayDiff > 0 && dayDiff < 8);
} else {
assertSame(month, Month.DECEMBER);
assertTrue(date.getDayOfMonth() > 24);
assertEquals(test.getYear(), 2008);
assertSame(test.getMonth(), Month.JANUARY);
assertTrue(test.getDayOfMonth() < 8);
}
}
}
}
}
示例2: test_previous
import java.time.Month; //導入方法依賴的package包/類
@Test
public void test_previous() {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(false); i++) {
LocalDate date = date(2007, month, i);
for (DayOfWeek dow : DayOfWeek.values()) {
LocalDate test = (LocalDate) TemporalAdjusters.previous(dow).adjustInto(date);
assertSame(test.getDayOfWeek(), dow, date + " " + test);
if (test.getYear() == 2007) {
int dayDiff = test.getDayOfYear() - date.getDayOfYear();
assertTrue(dayDiff < 0 && dayDiff > -8, dayDiff + " " + test);
} else {
assertSame(month, Month.JANUARY);
assertTrue(date.getDayOfMonth() < 8);
assertEquals(test.getYear(), 2006);
assertSame(test.getMonth(), Month.DECEMBER);
assertTrue(test.getDayOfMonth() > 24);
}
}
}
}
}
示例3: test_getDayOfWeek
import java.time.Month; //導入方法依賴的package包/類
@Test
public void test_getDayOfWeek() {
DayOfWeek dow = DayOfWeek.MONDAY;
for (Month month : Month.values()) {
int length = month.length(false);
for (int i = 1; i <= length; i++) {
LocalDateTime d = LocalDateTime.of(LocalDate.of(2007, month, i),
TEST_2007_07_15_12_30_40_987654321.toLocalTime());
assertSame(d.getDayOfWeek(), dow);
dow = dow.plus(1);
}
}
}
示例4: test_lastDayOfYear_nonLeap
import java.time.Month; //導入方法依賴的package包/類
@Test
public void test_lastDayOfYear_nonLeap() {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(false); i++) {
LocalDate date = date(2007, month, i);
LocalDate test = (LocalDate) TemporalAdjusters.lastDayOfYear().adjustInto(date);
assertEquals(test.getYear(), 2007);
assertEquals(test.getMonth(), Month.DECEMBER);
assertEquals(test.getDayOfMonth(), 31);
}
}
}
示例5: test_getDayOfWeek
import java.time.Month; //導入方法依賴的package包/類
@Test
public void test_getDayOfWeek() {
DayOfWeek dow = DayOfWeek.MONDAY;
for (Month month : Month.values()) {
int length = month.length(false);
for (int i = 1; i <= length; i++) {
LocalDate d = LocalDate.of(2007, month, i);
assertSame(d.getDayOfWeek(), dow);
dow = dow.plus(1);
}
}
}
示例6: test_lastDayOfMonth_nonLeap
import java.time.Month; //導入方法依賴的package包/類
@Test
public void test_lastDayOfMonth_nonLeap() {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(false); i++) {
LocalDate date = date(2007, month, i);
LocalDate test = (LocalDate) TemporalAdjusters.lastDayOfMonth().adjustInto(date);
assertEquals(test.getYear(), 2007);
assertEquals(test.getMonth(), month);
assertEquals(test.getDayOfMonth(), month.length(false));
}
}
}
示例7: test_firstDayOfYear_leap
import java.time.Month; //導入方法依賴的package包/類
@Test
public void test_firstDayOfYear_leap() {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(true); i++) {
LocalDate date = date(2008, month, i);
LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfYear().adjustInto(date);
assertEquals(test.getYear(), 2008);
assertEquals(test.getMonth(), Month.JANUARY);
assertEquals(test.getDayOfMonth(), 1);
}
}
}
示例8: test_firstDayOfNextMonth_nonLeap
import java.time.Month; //導入方法依賴的package包/類
@Test
public void test_firstDayOfNextMonth_nonLeap() {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(false); i++) {
LocalDate date = date(2007, month, i);
LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfNextMonth().adjustInto(date);
assertEquals(test.getYear(), month == DECEMBER ? 2008 : 2007);
assertEquals(test.getMonth(), month.plus(1));
assertEquals(test.getDayOfMonth(), 1);
}
}
}
示例9: test_firstDayOfNextMonth_leap
import java.time.Month; //導入方法依賴的package包/類
@Test
public void test_firstDayOfNextMonth_leap() {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(true); i++) {
LocalDate date = date(2008, month, i);
LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfNextMonth().adjustInto(date);
assertEquals(test.getYear(), month == DECEMBER ? 2009 : 2008);
assertEquals(test.getMonth(), month.plus(1));
assertEquals(test.getDayOfMonth(), 1);
}
}
}
示例10: test_nextOrCurrent
import java.time.Month; //導入方法依賴的package包/類
@Test
public void test_nextOrCurrent() {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(false); i++) {
LocalDate date = date(2007, month, i);
for (DayOfWeek dow : DayOfWeek.values()) {
LocalDate test = (LocalDate) TemporalAdjusters.nextOrSame(dow).adjustInto(date);
assertSame(test.getDayOfWeek(), dow);
if (test.getYear() == 2007) {
int dayDiff = test.getDayOfYear() - date.getDayOfYear();
assertTrue(dayDiff < 8);
assertEquals(date.equals(test), date.getDayOfWeek() == dow);
} else {
assertFalse(date.getDayOfWeek() == dow);
assertSame(month, Month.DECEMBER);
assertTrue(date.getDayOfMonth() > 24);
assertEquals(test.getYear(), 2008);
assertSame(test.getMonth(), Month.JANUARY);
assertTrue(test.getDayOfMonth() < 8);
}
}
}
}
}
示例11: test_firstDayOfNextYear_nonLeap
import java.time.Month; //導入方法依賴的package包/類
@Test
public void test_firstDayOfNextYear_nonLeap() {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(false); i++) {
LocalDate date = date(2007, month, i);
LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfNextYear().adjustInto(date);
assertEquals(test.getYear(), 2008);
assertEquals(test.getMonth(), JANUARY);
assertEquals(test.getDayOfMonth(), 1);
}
}
}
示例12: test_firstDayOfNextYear_leap
import java.time.Month; //導入方法依賴的package包/類
@Test
public void test_firstDayOfNextYear_leap() {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(true); i++) {
LocalDate date = date(2008, month, i);
LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfNextYear().adjustInto(date);
assertEquals(test.getYear(), 2009);
assertEquals(test.getMonth(), JANUARY);
assertEquals(test.getDayOfMonth(), 1);
}
}
}
示例13: test_lastDayOfYear_leap
import java.time.Month; //導入方法依賴的package包/類
@Test
public void test_lastDayOfYear_leap() {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(true); i++) {
LocalDate date = date(2008, month, i);
LocalDate test = (LocalDate) TemporalAdjusters.lastDayOfYear().adjustInto(date);
assertEquals(test.getYear(), 2008);
assertEquals(test.getMonth(), Month.DECEMBER);
assertEquals(test.getDayOfMonth(), 31);
}
}
}
示例14: test_previousOrCurrent
import java.time.Month; //導入方法依賴的package包/類
@Test
public void test_previousOrCurrent() {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(false); i++) {
LocalDate date = date(2007, month, i);
for (DayOfWeek dow : DayOfWeek.values()) {
LocalDate test = (LocalDate) TemporalAdjusters.previousOrSame(dow).adjustInto(date);
assertSame(test.getDayOfWeek(), dow);
if (test.getYear() == 2007) {
int dayDiff = test.getDayOfYear() - date.getDayOfYear();
assertTrue(dayDiff <= 0 && dayDiff > -7);
assertEquals(date.equals(test), date.getDayOfWeek() == dow);
} else {
assertFalse(date.getDayOfWeek() == dow);
assertSame(month, Month.JANUARY);
assertTrue(date.getDayOfMonth() < 7);
assertEquals(test.getYear(), 2006);
assertSame(test.getMonth(), Month.DECEMBER);
assertTrue(test.getDayOfMonth() > 25);
}
}
}
}
}