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

import com.opengamma.financial.convention.daycount.DayCount;
import com.opengamma.financial.convention.daycount.DayCountFactory;
import com.opengamma.util.ArgumentChecker;

import javax.time.calendar.LocalDate;
import javax.time.calendar.TimeZone;
import javax.time.calendar.ZonedDateTime;

/**
 * Converts dates to 'Analytics Time'. The latter are stored as doubles, 
 * and typically represent the fraction of years between some date and the current one.
 */
public abstract class TimeCalculator {
  private static final DayCount ACT_ACT = DayCountFactory.INSTANCE.getDayCount("Actual/Actual ISDA");

  public static double getTimeBetween(final ZonedDateTime date1, final ZonedDateTime date2) {
    ArgumentChecker.notNull(date1, "date1");
    ArgumentChecker.notNull(date1, "date2");
    
    // Note that here we convert date2 to the same zone as date1 so we don't accidentally gain or lose a day.
    ZonedDateTime rebasedDate2 = date2.withZoneSameInstant(date1.getZone());
    
    final boolean timeIsNegative = date1.isAfter(rebasedDate2); // date1 >= date2


    if (!timeIsNegative) {
      final double time = ACT_ACT.getDayCountFraction(date1, rebasedDate2);
      return time;
    }
    return -1.0 * ACT_ACT.getDayCountFraction(rebasedDate2, date1);
  }

  public static double getTimeBetween(final LocalDate date1, final LocalDate date2) {
    return getTimeBetween(date1.atStartOfDayInZone(TimeZone.UTC), date2.atStartOfDayInZone(TimeZone.UTC));
  }
}
<commit_msg>TimeCalculator: Added forms for combos of zonedDateTime nd LocalDate<commit_after>/**
 * Copyright (C) 2011 - present by OpenGamma Inc. and the OpenGamma group of companies
 * 
 * Please see distribution for license.
 */
package com.opengamma.analytics.util.time;

import com.opengamma.financial.convention.daycount.DayCount;
import com.opengamma.financial.convention.daycount.DayCountFactory;
import com.opengamma.util.ArgumentChecker;

import javax.time.calendar.LocalDate;
import javax.time.calendar.TimeZone;
import javax.time.calendar.ZonedDateTime;

/**
 * Converts dates to 'Analytics Time'. The latter are stored as doubles, 
 * and typically represent the fraction of years between some date and the current one.
 */
public abstract class TimeCalculator {
  private static final DayCount ACT_ACT = DayCountFactory.INSTANCE.getDayCount("Actual/Actual ISDA");

  public static double getTimeBetween(final ZonedDateTime date1, final ZonedDateTime date2) {
    ArgumentChecker.notNull(date1, "date1");
    ArgumentChecker.notNull(date1, "date2");

    // Note that here we convert date2 to the same zone as date1 so we don't accidentally gain or lose a day.
    ZonedDateTime rebasedDate2 = date2.withZoneSameInstant(date1.getZone());

    final boolean timeIsNegative = date1.isAfter(rebasedDate2); // date1 >= date2

    if (!timeIsNegative) {
      final double time = ACT_ACT.getDayCountFraction(date1, rebasedDate2);
      return time;
    }
    return -1.0 * ACT_ACT.getDayCountFraction(rebasedDate2, date1);
  }

  public static double getTimeBetween(final LocalDate date1, final LocalDate date2) {
    return getTimeBetween(date1.atStartOfDayInZone(TimeZone.UTC), date2.atStartOfDayInZone(TimeZone.UTC));
  }

  public static double getTimeBetween(final ZonedDateTime zdt1, final LocalDate date2) {
    ZonedDateTime zdt2 = date2.atStartOfDayInZone(TimeZone.UTC);
    ZonedDateTime rebasedZdt1 = zdt1.withZoneSameInstant(TimeZone.UTC);
    return getTimeBetween(rebasedZdt1, zdt2);
  }

  public static double getTimeBetween(final LocalDate date1, final ZonedDateTime zdt2) {
    ZonedDateTime zdt1 = date1.atStartOfDayInZone(TimeZone.UTC);
    ZonedDateTime rebasedZdt2 = zdt2.withZoneSameInstant(TimeZone.UTC);
    return getTimeBetween(zdt1, rebasedZdt2);
  }
}

{'fraction_non_alphanumeric': 0.08619817997977755, 'fraction_numerical': 0.01870576339737108, 'mean_word_length': 4.734782608695652, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1222535', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1199, 'n_words': 318}