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


Java ZonedDateTime.getYear方法代码示例

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


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

示例1: equalsToAccuracy

import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
/**
 * Compares two expiry dates for equality to the given level of accuracy only.
 *
 * @param accuracy  the accuracy to compare to, not null
 * @param expiry1  the first date/time to compare, not null
 * @param expiry2  the second date/time to compare, not null
 * @return true if the two dates/times are equal to the requested accuracy
 */
public static boolean equalsToAccuracy(final ExpiryAccuracy accuracy, final ZonedDateTime expiry1, final ZonedDateTime expiry2) {
  switch (accuracy) {
    case MIN_HOUR_DAY_MONTH_YEAR:
      return (expiry1.getMinute() == expiry2.getMinute()) && (expiry1.getHour() == expiry2.getHour()) && (expiry1.getDayOfMonth() == expiry2.getDayOfMonth())
          && (expiry1.getMonth() == expiry2.getMonth()) && (expiry1.getYear() == expiry2.getYear());
    case HOUR_DAY_MONTH_YEAR:
      return (expiry1.getHour() == expiry2.getHour()) && (expiry1.getDayOfMonth() == expiry2.getDayOfMonth()) && (expiry1.getMonth() == expiry2.getMonth())
          && (expiry1.getYear() == expiry2.getYear());
    case DAY_MONTH_YEAR:
      return (expiry1.getDayOfMonth() == expiry2.getDayOfMonth()) && (expiry1.getMonth() == expiry2.getMonth()) && (expiry1.getYear() == expiry2.getYear());
    case MONTH_YEAR:
      return (expiry1.getMonth() == expiry2.getMonth()) && (expiry1.getYear() == expiry2.getYear());
    case YEAR:
      return (expiry1.getYear() == expiry2.getYear());
    default:
      throw new IllegalArgumentException("accuracy");
  }
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:27,代码来源:Expiry.java

示例2: getSchedule

import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
public ZonedDateTime[] getSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate) {
  ArgumentChecker.notNull(startDate, "start date");
  ArgumentChecker.notNull(endDate, "end date");
  ArgumentChecker.isFalse(startDate.isAfter(endDate), "start date must not be after end date");
  if (startDate.equals(endDate)) {
    if (startDate.getDayOfMonth() == _dayOfMonth) {
      return new ZonedDateTime[] {startDate};
    }
    throw new IllegalArgumentException("Start date and end date were the same but their day of month was not the same as that required");
  }
  final List<ZonedDateTime> dates = new ArrayList<>();
  int year = endDate.getYear();
  Month month = startDate.getMonth();
  ZonedDateTime date = startDate.withMonth(month.getValue()).withDayOfMonth(_dayOfMonth);
  if (date.isBefore(startDate)) {
    month = month.plus(1);
    date = date.withMonth(month.getValue());
  }
  year = date.getYear();
  while (!date.isAfter(endDate)) {
    dates.add(date);
    month = month.plus(1);
    if (month == Month.JANUARY) {
      year++;
    }
    date = date.with(LocalDate.of(year, month.getValue(), _dayOfMonth));
  }
  return dates.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:30,代码来源:MonthlyScheduleOnDayCalculator.java

示例3: test2

import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void test2() {
  final ZonedDateTime startDate = DateUtils.getUTCDate(2000, 1, 1);
  final ZonedDateTime endDate = DateUtils.getUTCDate(2002, 2, 9);
  final int months = 25;
  final ZonedDateTime[] forward = CALCULATOR.getSchedule(startDate, endDate, false, true);
  assertEquals(forward.length, months);
  final ZonedDateTime firstDate = DateUtils.getUTCDate(2000, 1, 31);
  assertEquals(forward[0], firstDate);
  final ZonedDateTime lastDate = DateUtils.getUTCDate(2002, 1, 31);
  assertEquals(forward[months - 1], lastDate);
  ZonedDateTime d1;
  for (int i = 1; i < months; i++) {
    d1 = forward[i];
    if (d1.getYear() == forward[i - 1].getYear()) {
      assertEquals(d1.getMonthValue() - forward[i - 1].getMonthValue(), 1);
    } else {
      assertEquals(d1.getMonthValue() - forward[i - 1].getMonthValue(), -11);
    }
    assertEquals(d1.getDayOfMonth(), d1.toLocalDate().lengthOfMonth());
  }
  assertArrayEquals(CALCULATOR.getSchedule(startDate, endDate, true, false), forward);
  assertArrayEquals(CALCULATOR.getSchedule(startDate, endDate, true, true), forward);
  assertArrayEquals(CALCULATOR.getSchedule(startDate, endDate, false, false), forward);
  assertArrayEquals(CALCULATOR.getSchedule(startDate, endDate, false, true), forward);
  assertArrayEquals(CALCULATOR.getSchedule(startDate, endDate), forward);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:28,代码来源:EndOfMonthScheduleCalculatorTest.java

示例4: futureBundleToGenericFutureTicker

import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
public static ExternalId futureBundleToGenericFutureTicker(ExternalIdBundle bundle, ZonedDateTime now, OffsetTime futureExpiryTime, ZoneId futureExpiryTimeZone) {
  ZonedDateTime nextExpiry = now.toLocalDate().with(s_monthlyExpiryAdjuster).atTime(now.toLocalTime()).atZone(now.getZone());
  ExternalId bbgTicker = bundle.getExternalId(ExternalSchemes.BLOOMBERG_TICKER);
  if (bbgTicker == null) {
    throw new OpenGammaRuntimeException("Could not find a Bloomberg Ticker in the supplied bundle " + bundle.toString());
  }
  final String code = bbgTicker.getValue();
  final String marketSector = splitTickerAtMarketSector(code).getSecond();
  try {
    String typeCode;
    String monthCode;
    int year;
    if (code.length() > 4 && code.charAt(4) == ' ') {
      // four letter futures code
      typeCode = code.substring(0, 2);
      monthCode = code.substring(2, 3);
      year = Integer.parseInt(code.substring(3, 4));

      final int thisYear = now.getYear();
      if ((thisYear % 10) > year) {
        year = ((thisYear / 10) * 10) + 10 + year;
      } else if ((thisYear % 10) == year) {
        // This code assumes that the code is for this year, so constructs a trial date using the year and month and adjusts it forward to the expiry
        // note we're not taking into account exchange closing time here.
        final Month month = s_monthCode.inverse().get(monthCode);
        if (month == null) {
          throw new OpenGammaRuntimeException("Invalid month code " + monthCode);
        }
        LocalDate nextExpiryIfThisYear = LocalDate.of((((thisYear / 10) * 10) + year), month, 1).with(s_monthlyExpiryAdjuster);
        ZonedDateTime nextExpiryDateTimeIfThisYear = nextExpiryIfThisYear.atTime(futureExpiryTime).atZoneSimilarLocal(futureExpiryTimeZone);
        if (now.isAfter(nextExpiryDateTimeIfThisYear)) {
          year = ((thisYear / 10) * 10) + 10 + year;
        } else {
          year = ((thisYear / 10) * 10) + year;
        }
      } else {
        year = ((thisYear / 10) * 10) + year;
      }
    } else if (code.length() > 5 && code.charAt(5) == ' ') {
      // five letter futures code
      typeCode = code.substring(0, 2);
      monthCode = code.substring(2, 3);
      s_logger.warn("Parsing retired futures code format {}", code);
      year = Integer.parseInt(code.substring(3, 5));
      if (year > 70) { // 58 year time bomb and ticking...
        year += 1900;
      } else {
        year += 2000;
      }
    } else {
      s_logger.warn("Unknown futures code format {}", code);
      return null;
    }
    // phew.
    // now we generate the expiry of the future from the code:
    // Again, note that we're not taking into account exchange trading hours.
    LocalDate expiryDate = LocalDate.of(year, s_monthCode.inverse().get(monthCode), 1).with(s_monthlyExpiryAdjuster);
    ZonedDateTime expiry = expiryDate.atTime(futureExpiryTime).atZoneSimilarLocal(futureExpiryTimeZone);
    int quarters = (int) nextExpiry.periodUntil(expiry, MONTHS) / 3;
    int genericFutureNumber = quarters + 1;
    StringBuilder sb = new StringBuilder();
    sb.append(typeCode);
    sb.append(genericFutureNumber);
    sb.append(" ");
    sb.append(marketSector);
    return ExternalId.of(ExternalSchemes.BLOOMBERG_TICKER, sb.toString());
  } catch (final NumberFormatException nfe) {
    s_logger.error("Could not parse futures code {}", code);
  }
  return null;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:72,代码来源:BloombergDataUtils.java


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