Class Years<U extends IsoDateUnit>

java.lang.Object
net.time4j.range.SingleUnitTimeSpan<U,​Years<U>>
net.time4j.range.Years<U>
Type Parameters:
U - generic type of year units
All Implemented Interfaces:
Serializable, Comparable<Years<U>>, TimeSpan<U>

public final class Years<U extends IsoDateUnit> extends SingleUnitTimeSpan<U,​Years<U>>

Represents a time span in gregorian or week-based years.

Since:
3.21/4.17
Author:
Meno Hochschild
See Also:
Serialized Form
  • Field Details

    • ZERO

      public static final Years<CalendarUnit> ZERO

      Constant for zero gregorian years.

    • ONE

      public static final Years<CalendarUnit> ONE

      Constant for exactly one gregorian year.

  • Method Details

    • ofGregorian

      public static Years<CalendarUnit> ofGregorian(int years)

      Obtains a time span in given gregorian years.

      Parameters:
      years - count of gregorian years, maybe negative
      Returns:
      time span in years
      See Also:
      CalendarUnit.YEARS
    • ofWeekBased

      public static Years<Weekcycle> ofWeekBased(int years)

      Obtains a time span in given week-based years.

      Week-based years have a length of either 364 or 371 days.

      Parameters:
      years - count of week-based years, maybe negative
      Returns:
      time span in years
      See Also:
      CalendarUnit.weekBasedYears()
    • between

      public static <T extends TimePoint<? super CalendarUnit,​ T>> Years<CalendarUnit> between(T t1, T t2)

      Determines the temporal distance between given dates/time-points in gregorian years.

      Type Parameters:
      T - generic type of time-points
      Parameters:
      t1 - first time-point
      t2 - second time-point
      Returns:
      result of year difference
      See Also:
      PlainDate, PlainTimestamp
    • between

      public static Years<CalendarUnit> between(CalendarYear y1, CalendarYear y2)

      Determines the difference in years between given calendar years.

      Parameters:
      y1 - first calendar year
      y2 - second calendar year
      Returns:
      year difference
    • between

      public static Years<CalendarUnit> between(CalendarQuarter q1, CalendarQuarter q2)

      Determines the difference in years between given quarter years.

      Parameters:
      q1 - first quarter year
      q2 - second quarter year
      Returns:
      year difference
    • between

      public static Years<CalendarUnit> between(CalendarMonth m1, CalendarMonth m2)

      Determines the difference in years between given calendar months.

      Parameters:
      m1 - first calendar month
      m2 - second calendar month
      Returns:
      year difference
    • between

      public static Years<Weekcycle> between(CalendarWeek w1, CalendarWeek w2)

      Determines the difference in years between given calendar weeks.

      Parameters:
      w1 - first calendar week
      w2 - second calendar week
      Returns:
      year difference
    • parseGregorian

      public static Years<CalendarUnit> parseGregorian(String period) throws ParseException

      Parses the canonical ISO-8601-format "PnY" with possible preceding minus-char.

      Parameters:
      period - the formatted string to be parsed
      Returns:
      parsed instance
      Throws:
      ParseException - if given argument cannot be parsed
    • parseWeekBased

      public static Years<Weekcycle> parseWeekBased(String period) throws ParseException

      Like parseGregorian(period) but interpretes years as week-based.

      Parameters:
      period - the formatted string to be parsed
      Returns:
      parsed instance
      Throws:
      ParseException - if given argument cannot be parsed
      See Also:
      parseGregorian(String), CalendarUnit.weekBasedYears()