<commit_before>/**
 * Copyright (C) 2012 - present by OpenGamma Inc. and the OpenGamma group of companies
 * 
 * Please see distribution for license.
 */
package com.opengamma.financial.analytics.model.irfutureoption;

import javax.time.calendar.DateAdjuster;
import javax.time.calendar.DateAdjusters;
import javax.time.calendar.LocalDate;
import javax.time.calendar.ZonedDateTime;

import com.opengamma.financial.analytics.ircurve.NextExpiryAdjuster;
import com.opengamma.util.time.DateUtils;

/**
 * 
 */
public class IRFutureOptionUtils {
  private static final DateAdjuster s_nextExpiryAdjuster = new NextExpiryAdjuster();
  private static final DateAdjuster s_firstOfMonthAdjuster = DateAdjusters.firstDayOfMonth();

  public static Double getTime(final Number x, final ZonedDateTime now) {
    final LocalDate today = now.toLocalDate();
    final int n = x.intValue();
    if (n == 1) {
      final LocalDate nextExpiry = today.with(s_nextExpiryAdjuster);
      final LocalDate previousMonday = nextExpiry.minusDays(2); //TODO this should take a calendar and do two business days, and should use a convention for the number of days
      return DateUtils.getDaysBetween(today, previousMonday) / 365.; //TODO or use daycount?
    }
    final LocalDate date = today.with(s_firstOfMonthAdjuster);
    final LocalDate plusMonths = date.plusMonths(n * 3); //TODO this is hard-coding the futures to be quarterly
    final LocalDate thirdWednesday = plusMonths.with(s_nextExpiryAdjuster);
    final LocalDate previousMonday = thirdWednesday.minusDays(2); //TODO this should take a calendar and do two business days and also use a convention for the number of days
    return DateUtils.getDaysBetween(today, previousMonday) / 365.; //TODO or use daycount?
  }
}<commit_msg>IRFutureOptionUtils now uses consistent function to convert expiries to years<commit_after>/**
 * Copyright (C) 2012 - present by OpenGamma Inc. and the OpenGamma group of companies
 * 
 * Please see distribution for license.
 */
package com.opengamma.financial.analytics.model.irfutureoption;

import javax.time.calendar.DateAdjuster;
import javax.time.calendar.DateAdjusters;
import javax.time.calendar.LocalDate;
import javax.time.calendar.ZonedDateTime;

import com.opengamma.financial.analytics.ircurve.NextExpiryAdjuster;
import com.opengamma.util.time.TimeCalculator;

/**
 * 
 */
public class IRFutureOptionUtils {
  private static final DateAdjuster s_nextExpiryAdjuster = new NextExpiryAdjuster();
  private static final DateAdjuster s_firstOfMonthAdjuster = DateAdjusters.firstDayOfMonth();

  public static Double getTime(final Number x, final ZonedDateTime now) {
    final LocalDate today = now.toLocalDate();
    final int n = x.intValue();
    if (n == 1) {
      final LocalDate nextExpiry = today.with(s_nextExpiryAdjuster);
      final LocalDate previousMonday = nextExpiry.minusDays(2); //TODO this should take a calendar and do two business days, and should use a convention for the number of days
      return TimeCalculator.getTimeBetween(today, previousMonday);
    }
    final LocalDate date = today.with(s_firstOfMonthAdjuster);
    final LocalDate plusMonths = date.plusMonths(n * 3); //TODO this is hard-coding the futures to be quarterly
    final LocalDate thirdWednesday = plusMonths.with(s_nextExpiryAdjuster);
    final LocalDate previousMonday = thirdWednesday.minusDays(2); //TODO this should take a calendar and do two business days and also use a convention for the number of days
    return TimeCalculator.getTimeBetween(today, previousMonday);

  }
}
{'fraction_non_alphanumeric': 0.07921348314606741, 'fraction_numerical': 0.006179775280898876, 'mean_word_length': 4.625592417061611, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4447258', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1005, 'n_words': 321}