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


Java LocalDate.isLeapYear方法代码示例

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


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

示例1: getWeek

import java.time.LocalDate; //导入方法依赖的package包/类
private static int getWeek(LocalDate date) {
    int dow0 = date.getDayOfWeek().ordinal();
    int doy0 = date.getDayOfYear() - 1;
    int doyThu0 = doy0 + (3 - dow0);  // adjust to mid-week Thursday (which is 3 indexed from zero)
    int alignedWeek = doyThu0 / 7;
    int firstThuDoy0 = doyThu0 - (alignedWeek * 7);
    int firstMonDoy0 = firstThuDoy0 - 3;
    if (firstMonDoy0 < -3) {
        firstMonDoy0 += 7;
    }
    if (doy0 < firstMonDoy0) {
        return (int) getWeekRange(date.withDayOfYear(180).minusYears(1)).getMaximum();
    }
    int week = ((doy0 - firstMonDoy0) / 7) + 1;
    if (week == 53) {
        if ((firstMonDoy0 == -3 || (firstMonDoy0 == -2 && date.isLeapYear())) == false) {
            week = 1;
        }
    }
    return week;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:IsoFields.java

示例2: getWeek

import java.time.LocalDate; //导入方法依赖的package包/类
private static int getWeek(LocalDate date) {

      int dow0 = date.getDayOfWeek().ordinal();
      int doy0 = date.getDayOfYear() - 1;
      int doyThu0 = doy0 + (3 - dow0); // adjust to mid-week Thursday (which is 3 indexed from zero)
      int alignedWeek = doyThu0 / 7;
      int firstThuDoy0 = doyThu0 - (alignedWeek * 7);
      int firstMonDoy0 = firstThuDoy0 - 3;
      if (firstMonDoy0 < -3) {
        firstMonDoy0 += 7;
      }
      if (doy0 < firstMonDoy0) {
        return (int) getWeekRange(date.withDayOfYear(180).minusYears(1)).getMaximum();
      }
      int week = ((doy0 - firstMonDoy0) / 7) + 1;
      if (week == 53) {
        if ((firstMonDoy0 == -3 || (firstMonDoy0 == -2 && date.isLeapYear())) == false) {
          week = 1;
        }
      }
      return week;
    }
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:23,代码来源:ISOWeeks.java

示例3: getWeekRange

import java.time.LocalDate; //导入方法依赖的package包/类
private static int getWeekRange(int wby) {
    LocalDate date = LocalDate.of(wby, 1, 1);
    // 53 weeks if standard year starts on Thursday, or Wed in a leap year
    if (date.getDayOfWeek() == THURSDAY || (date.getDayOfWeek() == WEDNESDAY && date.isLeapYear())) {
        return 53;
    }
    return 52;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:9,代码来源:IsoFields.java

示例4: getWeekRange

import java.time.LocalDate; //导入方法依赖的package包/类
private static DateTimeValueRange getWeekRange(LocalDate date) {

      int wby = getWeekBasedYear(date);
      date = date.withDayOfYear(1).withYear(wby);
      // 53 weeks if standard year starts on Thursday, or Wed in a leap year
      if (date.getDayOfWeek() == THURSDAY || (date.getDayOfWeek() == WEDNESDAY && date.isLeapYear())) {
        return DateTimeValueRange.of(1, 53);
      }
      return DateTimeValueRange.of(1, 52);
    }
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:11,代码来源:ISOWeeks.java

示例5: test_loop

import java.time.LocalDate; //导入方法依赖的package包/类
public void test_loop() {
    // loop round at least one 400 year cycle, including before 1970
    LocalDate date = LocalDate.of(1960, 1, 5);  // Tuseday of week 1 1960
    int year = 1960;
    int wby = 1960;
    int weekLen = 52;
    int week = 1;
    while (date.getYear() < 2400) {
        DayOfWeek loopDow = date.getDayOfWeek();
        if (date.getYear() != year) {
            year = date.getYear();
        }
        if (loopDow == MONDAY) {
            week++;
            if ((week == 53 && weekLen == 52) || week == 54) {
                week = 1;
                LocalDate firstDayOfWeekBasedYear = date.plusDays(14).withDayOfYear(1);
                DayOfWeek firstDay = firstDayOfWeekBasedYear.getDayOfWeek();
                weekLen = (firstDay == THURSDAY || (firstDay == WEDNESDAY && firstDayOfWeekBasedYear.isLeapYear()) ? 53 : 52);
                wby++;
            }
        }
        assertEquals(IsoFields.WEEK_OF_WEEK_BASED_YEAR.rangeRefinedBy(date), ValueRange.of(1, weekLen), "Failed on " + date + " " + date.getDayOfWeek());
        assertEquals(IsoFields.WEEK_OF_WEEK_BASED_YEAR.getFrom(date), week, "Failed on " + date + " " + date.getDayOfWeek());
        assertEquals(date.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR), week, "Failed on " + date + " " + date.getDayOfWeek());
        assertEquals(IsoFields.WEEK_BASED_YEAR.getFrom(date), wby, "Failed on " + date + " " + date.getDayOfWeek());
        assertEquals(date.get(IsoFields.WEEK_BASED_YEAR), wby, "Failed on " + date + " " + date.getDayOfWeek());
        date = date.plusDays(1);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:31,代码来源:TCKIsoFields.java


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