com.informix.lang

## Class IntervalYM

- java.lang.Object
- - com.informix.lang.Interval
  - - com.informix.lang.IntervalYM

    public class IntervalYM
    extends Interval

This class represents year-to-month INTERVAL SQL data types in Java. This class was created because the Sun JDBC specification did not include such a class.

See Also:
  `Timestamp`

### Field Summary

Fields
`protected long` `months`
`protected static int` `MonthsPerYear`

### Fields inherited from class com.informix.lang.Interval

`DAY_IDX, DECSIZE, dtdelim, FRAC_IDX, HOUR_IDX, int_qual, MIN_IDX, MONTH_IDX, NUMBER_UNITS, SEC_IDX, TU_DAY, TU_F1, TU_F2, TU_F3, TU_F4, TU_F5, TU_FRAC, TU_HOUR, TU_MINUTE, TU_MONTH, TU_SECOND, TU_YEAR, YEAR_IDX`

### Constructor Summary

Constructors
Constructor and Description
`IntervalYM()` Default Constructor with a default qualifier of leading field precision = 4 start code = TU_YEAR end code = TU_MONTH
`IntervalYM(java.sql.Connection conn)` Default Constructor with the default qualifier.
`IntervalYM(int years, int months)` Creates an Interval from a number of years and months.
`IntervalYM(int years, int months, java.sql.Connection conn)` Creates an Interval from a number of years and months.
`IntervalYM(int months, short qual)` Creates an Interval from a number of months and a qualifier.
`IntervalYM(int months, short qual, java.sql.Connection conn)` Creates an Interval from a number of months and a qualifier.
`IntervalYM(java.lang.String str)` Creates an Interval from a string and a default qualifier of leading field precision = 4 start code = TU_YEAR end code = TU_MONTH
`IntervalYM(java.lang.String str, java.sql.Connection conn)` Creates an Interval from a string and the default qualifier.
`IntervalYM(java.lang.String str, int len, byte startCode, byte endCode)` Creates an Interval from a string and qualifier information.
`IntervalYM(java.lang.String str, int len, byte startCode, byte endCode, java.sql.Connection conn)` Creates an Interval from a string and qualifier information.
`IntervalYM(java.lang.String str, short qual)` Creates an Interval from a string and the qualifier.
`IntervalYM(java.lang.String str, short qual, java.sql.Connection conn)` Creates an Interval from a string and the qualifier.
`IntervalYM(java.sql.Timestamp t1, java.sql.Timestamp t2)` Creates an Interval object from two timestamps.
`IntervalYM(java.sql.Timestamp t1, java.sql.Timestamp t2, java.sql.Connection conn)` Creates an Interval object from two timestamps.

### Method Summary

All Methods Instance Methods Concrete Methods
`boolean` `equals(java.lang.Object obj)`
`void` `fromString(java.lang.String str)` Sets the values for the Interval from a string.
`long` `getMonths()` Returns the number of months in the interval.
`boolean` `greaterThan(IntervalYM other)` Compares this Interval with another to see if it is greater (longer in time) than the other.
`int` `hashCode()`
`boolean` `lessThan(IntervalYM other)` Compares this Interval with another to see if it is less (shorter in time) than the other.
`void` `set(int years, int months)` Sets the value of the Interval from years and months.
`void` `set(java.lang.String str)` Set the value of the Interval from a string.
`void` `set(java.sql.Timestamp t1, java.sql.Timestamp t2)` Sets the value of the Interval from two Timestamps.
`void` `setQualifier(byte len, byte startCode, byte endCode)` Sets the qualifier from its constituent pieces.
`void` `setQualifier(short qualifier)` Sets the qualifier from an existing qualifier.
`java.lang.String` `toString()` Returns a string representation of the Interval in the following format: yyyy-mm The presence of the various fields depends upon the qualifier.

### Methods inherited from class com.informix.lang.Interval

`getEndCode, getEndCode, getFieldName, getFirstLength, getIfxTypeName, getLength, getLength, getQualifier, getQualifier, getQualifier, getScale, getStartCode, getStartCode, getStaticEndCode, getStaticStartCode, goodQualifier, setConnection, stringToUnits`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Field Detail

#### months

    protected long months

#### MonthsPerYear

    protected static final int MonthsPerYear

See Also:
  Constant Field Values

### Constructor Detail

#### IntervalYM

    public IntervalYM()
               throws java.sql.SQLException

Default Constructor with a default qualifier of leading field precision = 4 start code = TU_YEAR end code = TU_MONTH

Throws:
  `java.sql.SQLException`

#### IntervalYM

    public IntervalYM(java.sql.Connection conn)
               throws java.sql.SQLException

Default Constructor with the default qualifier. This constructor supports localized error messages.

Throws:
  `java.sql.SQLException`

#### IntervalYM

    public IntervalYM(java.sql.Timestamp t1,
                      java.sql.Timestamp t2)
               throws java.sql.SQLException

Creates an Interval object from two timestamps. The Interval calculated is always positive, regardless of the order of the passed arguments. The default qualifier is set too: leading field precision = 4 start code = TU_YEAR end code = TU_MONTH

Parameters:
  `t1` - First timestamp.
  `t2` - Second timestamp.
Throws:
  `java.sql.SQLException`

#### IntervalYM

    public IntervalYM(java.sql.Timestamp t1,
                      java.sql.Timestamp t2,
                      java.sql.Connection conn)
               throws java.sql.SQLException

Creates an Interval object from two timestamps. The Interval calculated is always positive, regardless of the order of the passed arguments. This constructor supports localized error messages.

Parameters:
  `t1` - First timestamp.
  `t2` - Second timestamp.
  `conn` - Connection object
Throws:
  `java.sql.SQLException`

#### IntervalYM

    public IntervalYM(int years,
                      int months)
               throws java.sql.SQLException

Creates an Interval from a number of years and months. The default qualifier is set too: leading field precision = 4 start code = TU_YEAR end code = TU_MONTH

Parameters:
  `years` - Number of years.
  `months` - Number of months.
Throws:
  `java.sql.SQLException`

#### IntervalYM

    public IntervalYM(int years,
                      int months,
                      java.sql.Connection conn)
               throws java.sql.SQLException

Creates an Interval from a number of years and months. This constructor supports localized error messages.

Parameters:
  `years` - Number of years.
  `months` - Number of months.
  `conn` - Connection object.
Throws:
  `java.sql.SQLException`

#### IntervalYM

    public IntervalYM(int months,
                      short qual)
               throws java.sql.SQLException

Creates an Interval from a number of months and a qualifier.

Parameters:
  `months` - Number of months.
  `qual` - Interval qualifier.
Throws:
  `java.sql.SQLException`

#### IntervalYM

    public IntervalYM(int months,
                      short qual,
                      java.sql.Connection conn)
               throws java.sql.SQLException

Creates an Interval from a number of months and a qualifier. This constructor supports localized error messages.

Parameters:
  `months` - Number of months.
  `qual` - Interval qualifier.
  `conn` - Connection object
Throws:
  `java.sql.SQLException`

#### IntervalYM

    public IntervalYM(java.lang.String str)
               throws java.sql.SQLException

Creates an Interval from a string and a default qualifier of leading field precision = 4 start code = TU_YEAR end code = TU_MONTH

Parameters:
  `str` - String representation of an Interval value.
Throws:
  `java.sql.SQLException`

#### IntervalYM

    public IntervalYM(java.lang.String str,
                      java.sql.Connection conn)
               throws java.sql.SQLException

Creates an Interval from a string and the default qualifier. This constructor supports localized error messages.

Parameters:
  `str` - String representation of an Interval value.
  `conn` - Connection object
Throws:
  `java.sql.SQLException`

#### IntervalYM

    public IntervalYM(java.lang.String str,
                      short qual)
               throws java.sql.SQLException

Creates an Interval from a string and the qualifier.

Parameters:
  `str` - String representation of an Interval value.
  `qual` - Interval qualifier.
Throws:
  `java.sql.SQLException`

#### IntervalYM

    public IntervalYM(java.lang.String str,
                      short qual,
                      java.sql.Connection conn)
               throws java.sql.SQLException

Creates an Interval from a string and the qualifier. This constructor supports localized error messages.

Parameters:
  `str` - String representation of an Interval value.
  `qual` - Interval qualifier.
  `conn` - Connection object
Throws:
  `java.sql.SQLException`

#### IntervalYM

    public IntervalYM(java.lang.String str,
                      int len,
                      byte startCode,
                      byte endCode)
               throws java.sql.SQLException

Creates an Interval from a string and qualifier information.

Parameters:
  `str` - The string representation of the year to month Interval.
  `len` - The total length of the qualifier.
  `startCode` - The starting time unit value (TU_XXX).
  `endCode` - The ending time unit value (TU_XXX).
Throws:
  `java.sql.SQLException`

#### IntervalYM

    public IntervalYM(java.lang.String str,
                      int len,
                      byte startCode,
                      byte endCode,
                      java.sql.Connection conn)
               throws java.sql.SQLException

Creates an Interval from a string and qualifier information. This constructor supports localized error messages.

Parameters:
  `str` - The string representation of the year to month Interval.
  `len` - The total length of the qualifier.
  `startCode` - The starting time unit value (TU_XXX).
  `endCode` - The ending time unit value (TU_XXX).
  `conn` - Connection object
Throws:
  `java.sql.SQLException`

### Method Detail

#### set

    public void set(java.sql.Timestamp t1,
                    java.sql.Timestamp t2)

Sets the value of the Interval from two Timestamps. The Interval calculated is always positive, regardless of the order of the passed arguments.

Parameters:
  `t1` - First timestamp.
  `t2` - Second timestamp.

#### set

    public void set(int years,
                    int months)

Sets the value of the Interval from years and months.

Parameters:
  `years` - Number of years.
  `months` - Number of months.

#### set

    public void set(java.lang.String str)
             throws java.sql.SQLException

Set the value of the Interval from a string.

Parameters:
  `str` - A valid string representing a year to month INTERVAL.
Throws:
  `java.sql.SQLException`

#### toString

    public java.lang.String toString()

Returns a string representation of the Interval in the following format: yyyy-mm The presence of the various fields depends upon the qualifier. If no qualifier has been set, the default is the full format.

Overrides:
  `toString` in class `java.lang.Object`
Returns:
  A string of the format yyyy-mm.

#### fromString

    public void fromString(java.lang.String str)
                    throws java.sql.SQLException

Sets the values for the Interval from a string. This is done as a separate method rather than using the valueOf() method, since valueOf() is usually a class method, and this method must use the qualifier property.

Parameters:
  `str` - String representation of an Interval value in y-m format.
Throws:
  `java.sql.SQLException`

#### getMonths

    public long getMonths()

Returns the number of months in the interval.

Returns:
  The number of months.

#### hashCode

    public int hashCode()

Overrides:
  `hashCode` in class `Interval`

#### equals

    public boolean equals(java.lang.Object obj)

Overrides:
  `equals` in class `Interval`

#### greaterThan

    public boolean greaterThan(IntervalYM other)

Compares this Interval with another to see if it is greater (longer in time) than the other.

Parameters:
  `other` - The IntervalYM object to which this Interval is compared.
Returns:
  True if this Interval is greater, false if not.

#### lessThan

    public boolean lessThan(IntervalYM other)

Compares this Interval with another to see if it is less (shorter in time) than the other.

Parameters:
  `other` - The IntervalYM object to which this Interval is compared.
Returns:
  True if this Interval is less, false if not.

#### setQualifier

    public void setQualifier(byte len,
                             byte startCode,
                             byte endCode)
                      throws java.sql.SQLException

Sets the qualifier from its constituent pieces.

Parameters:
  `len` - The total length of the qualifier.
  `startCode` - The starting time unit value (TU_XXX).
  `endCode` - The ending time unit value (TU_XXX).
Throws:
  `java.sql.SQLException`

#### setQualifier

    public void setQualifier(short qualifier)
                      throws java.sql.SQLException

Sets the qualifier from an existing qualifier.

Parameters:
  `qualifier` - Qualifier value.
Throws:
  `java.sql.SQLException`