com.informix.util

## Class dateUtil

- java.lang.Object
- - com.informix.util.dateUtil

    public class dateUtil
    extends java.lang.Object

### Field Summary

Fields
`static int` `NUMSECSINDY`
`static int` `NUMSECSINHR`
`static int` `NUMSECSINMN`
`static int` `NUMSECSINWK`
`static int` `NUMSECSINYR`

### Constructor Summary

Constructors
Constructor and Description
`dateUtil()`

### Method Summary

Methods
`static int` `calcNumDays(java.lang.String date)` Calculate the number of days elapsed for a given date (e.g.
`static java.sql.Date` `convertDateObj(java.lang.String dateStr, IfxConnection conn)` Determine the localized java.sql.Date object of a date string based on a char or varchar date string representation.
`static java.lang.String` `convertDateStr(java.sql.Date date, IfxConnection conn)` Determine the localized date format of a date string based on a java.sql.Date object.
`static java.lang.String` `convertDateTimeStr(java.util.Date datetime, IfxConnection conn, long value)` Determine the localized date format of a datetime/time string based on a java.sql.Timestamp/java.sql.Time object.
`static java.lang.String` `convertNativeSQLDate(java.lang.String dateStr, IfxConnection conn)` Determine the localized date format of a date string whose original representation was in NativeSQL JDBC escape format "yyyy-mm-dd'.
`static java.lang.String` `convertNativeSQLDateTime(java.lang.String datetimeStr, IfxConnection conn, boolean isTime)` Determine the localized datetime format of a datetime string whose original representation was in NativeSQL JDBC escape format 'yyyy-mm-dd hh:mm:ss[.fffff]' (for datetime) or 'hh:mm:ss' (for time).
`static java.sql.Time` `convertStringToTime(java.lang.String timeStr, IfxConnection conn)` Converts the given string to a Time object
`static java.sql.Timestamp` `convertStringToTimestamp(java.lang.String datetimeStr, IfxConnection conn)` Converts the given string to a Time object
`static java.util.GregorianCalendar` `getCurrentDateGC(IfxConnection conn)`
`static java.util.Locale` `getLocaleValue(java.lang.String dateLocale)` Determine the correct locale setting based on whether a server is a GLS server or not.
`static long` `gregToJulian(java.lang.String date)` Given a valid date ('yyyy-mm-dd' format), calculate the julian day of that date.
`static boolean` `isLeapYear(int year)` Determine if the given year is a leap year or not.
`static boolean` `isValidDate(int year, int month, int day)` Verify that the date is valid based on year, month and day provided
`static boolean` `isValidDate(java.lang.String date)` Verify that the input string is a valid date value.
`static boolean` `isValidTime(java.lang.String time)` Verify that the input string is a valid time value.
`static boolean` `isValidTimeStamp(java.lang.String timeStamp)` Verify that the input string is a valid timestamp value.
`static java.lang.String` `trimExcessTimestampFraction(java.lang.String s)` Informix only supports up to 5 digits in the fractions of a second field (frac(5)).

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

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### NUMSECSINHR

    public static final int NUMSECSINHR

See Also:
  Constant Field Values

#### NUMSECSINDY

    public static final int NUMSECSINDY

See Also:
  Constant Field Values

#### NUMSECSINWK

    public static final int NUMSECSINWK

See Also:
  Constant Field Values

#### NUMSECSINMN

    public static final int NUMSECSINMN

See Also:
  Constant Field Values

#### NUMSECSINYR

    public static final int NUMSECSINYR

See Also:
  Constant Field Values

### Constructor Detail

#### dateUtil

    public dateUtil()

### Method Detail

#### calcNumDays

    public static int calcNumDays(java.lang.String date)

Calculate the number of days elapsed for a given date (e.g. 1998/2/2 - 32 days have elapsed in that year).

Parameters:
  `a` - string representation of a date
Returns:
  an int (-1 for error)

#### isValidTimeStamp

    public static boolean isValidTimeStamp(java.lang.String timeStamp)

Verify that the input string is a valid timestamp value. timestamp is assumed to be in 'yyyy-mm-dd hh:mm:ss[.fffff] format.

Parameters:
  `a` - string representation of a timestamp
Returns:
  true/false

#### trimExcessTimestampFraction

    public static java.lang.String trimExcessTimestampFraction(java.lang.String s)

Informix only supports up to 5 digits in the fractions of a second field (frac(5)). So if we get one that has more digits, we have to truncate it.

Parameters:
  `a` - string representation of a timestamp
Returns:
  an Informix compliant timestamp

#### isValidTime

    public static boolean isValidTime(java.lang.String time)

Verify that the input string is a valid time value. time is assumed to be in 'hh:mm:ss' format.

Parameters:
  `a` - string representation of a time
Returns:
  true/false

#### isValidDate

    public static boolean isValidDate(java.lang.String date)

Verify that the input string is a valid date value. date is assumed to be in 'yyyy-mm-dd' format.

Parameters:
  `a` - string representation of a date
Returns:
  true/false

#### gregToJulian

    public static long gregToJulian(java.lang.String date)

Given a valid date ('yyyy-mm-dd' format), calculate the julian day of that date.

#### isLeapYear

    public static boolean isLeapYear(int year)

Determine if the given year is a leap year or not. date is assumed to be in 'yyyy-mm-dd' format.

Parameters:
  `integer` - representation of a year
Returns:
  true/false

#### getLocaleValue

    public static java.util.Locale getLocaleValue(java.lang.String dateLocale)

Determine the correct locale setting based on whether a server is a GLS server or not. If the server is a GLS server, then a locale will have been previously set and this value needs to be parsed for correct use in the various date formatting methods. If the server is not a GLS server then the locale will not have been previously set and in this case the default locale of the system will be used.

Parameters:
  `dateLocale` - a string representation of the current client or database locale
Returns:
  client locale value representation in format that is expected by date formatting methods.

#### convertNativeSQLDate

    public static java.lang.String convertNativeSQLDate(java.lang.String dateStr,
                                        IfxConnection conn)
                                                 throws java.sql.SQLException

Determine the localized date format of a date string whose original representation was in NativeSQL JDBC escape format "yyyy-mm-dd'.

Parameters:
  `dateStr` - - a string representation of a date in "yyyy-mm-dd" JDBC escape format.
  `conn` - - the current connection object.
Returns:
  locdateStr - the localized date string representation.
Throws:
  `java.sql.SQLException`

#### convertNativeSQLDateTime

    public static java.lang.String convertNativeSQLDateTime(java.lang.String datetimeStr,
                                            IfxConnection conn,
                                            boolean isTime)
                                                     throws java.sql.SQLException

Determine the localized datetime format of a datetime string whose original representation was in NativeSQL JDBC escape format 'yyyy-mm-dd hh:mm:ss[.fffff]' (for datetime) or 'hh:mm:ss' (for time).

Parameters:
  `datetimeStr` - - a string representation of a datetime in "yyyy-mm-dd hh:mm:ss[.fffff]" (for datetime) or "hh:mm:ss" (for time) JDBC escape format.
  `conn` - - the current connection object.
  `isTime` - - true represents java.sql.Time, false represents java.sql.Timestamp
Returns:
  locdatetimeStr - the localized datetime string representation.
Throws:
  `java.sql.SQLException`

#### convertDateStr

    public static java.lang.String convertDateStr(java.sql.Date date,
                                  IfxConnection conn)
                                           throws java.sql.SQLException

Determine the localized date format of a date string based on a java.sql.Date object.

Parameters:
  `date` - - java.sql.Date object representation
  `conn` - - the current connection object.
Returns:
  locdateStr - the localized date string representation.
Throws:
  `java.sql.SQLException`

#### convertDateTimeStr

    public static java.lang.String convertDateTimeStr(java.util.Date datetime,
                                      IfxConnection conn,
                                      long value)
                                               throws java.sql.SQLException

Determine the localized date format of a datetime/time string based on a java.sql.Timestamp/java.sql.Time object.

Parameters:
  `datetime` - - java.sql.Timestamp or java.sql.Time object representation
  `conn` - - the current connection object.
  `value` - - long integer representation of datetime value.
Returns:
  locdatetimeStr - the localized datetime string representation.
Throws:
  `java.sql.SQLException`

#### convertDateObj

    public static java.sql.Date convertDateObj(java.lang.String dateStr,
                               IfxConnection conn)
                                        throws java.sql.SQLException

Determine the localized java.sql.Date object of a date string based on a char or varchar date string representation.

Parameters:
  `dateStr` - - a string representation of a date value.
  `conn` - - the current connection object.
Returns:
  locdateObj - the localized java.sql.Date object
Throws:
  `java.sql.SQLException`

#### convertStringToTimestamp

    public static java.sql.Timestamp convertStringToTimestamp(java.lang.String datetimeStr,
                                              IfxConnection conn)
                                                       throws java.sql.SQLException

Converts the given string to a Time object

Parameters:
  `datetimeStr` - Input String
  `conn` - Informix Connection
Returns:
  Timestamp a timestamp object based on the given input string
Throws:
  `java.sql.SQLException`

#### convertStringToTime

    public static java.sql.Time convertStringToTime(java.lang.String timeStr,
                                    IfxConnection conn)
                                             throws java.sql.SQLException

Converts the given string to a Time object

Parameters:
  `timeStr` - Input String
  `conn` - Informix Connection
Returns:
  Time the Time object based on the time string
Throws:
  `java.sql.SQLException`

#### getCurrentDateGC

    public static java.util.GregorianCalendar getCurrentDateGC(IfxConnection conn)
                                                        throws java.sql.SQLException

Throws:
  `java.sql.SQLException`

#### isValidDate

    public static boolean isValidDate(int year,
                      int month,
                      int day)

Verify that the date is valid based on year, month and day provided

Parameters:
  `int` - year, int month, int day
Returns:
  true/false