getDate(TimeZone tz) { /* ** Strip time component by re-formatting as date value. */ return(SqlDates.parseDate(SqlDates.formatDate(get(tz), false), false)); } // getDate
getString() { /* ** Do conversion to check for valid format. */ return(SqlDates.formatDate(get(null), false)); } // getString
setDate(DateTime value, TimeZone tz) { // DateTime is never null //if (value == null) // setNull(); //else if (tz != null) { setString(SqlDates.formatDate(value, tz)); } else { setString(SqlDates.formatDate(value, false)); } return; } // setDate
set(DateTime value, TimeZone tz) { // DateTime structure can never be null //if (value == null) //{ // setNull(); // return; //} /* ** Dates should be independent of TZ, but JDBC date values ** are stored in UTC. Use the TZ provided to ensure the ** formatted value represents the date in the desired TZ. ** Otherwise, the local default TZ is used. */ setNotNull(); this.value = (tz != null) ? SqlDates.formatDate(value, tz) : SqlDates.formatDate(value, false); return; } // set
setDate(DateTime value, TimeZone tz) { // DateTime is never null // if ( value == null ) // setNull(); // else { /* ** The date is stored in GMT such as to have a 0 time for ** the local TZ. Ingres dates are not associated with a ** TZ. Gateways add a 0 time to dates which is assumed to ** be in the client TZ. Timezones can be applied in both ** cases to get the actual date in the desired TZ. Other- ** wise, the date in the local TZ is used. */ setNotNull(); interval = false; this.value = (tz != null) ? SqlDates.formatDate(value, tz) : SqlDates.formatDate(value, false); } return; } // setDate
getDate(TimeZone tz) { /* ** Ingres dates are overloaded with 'empty' date, ** date only, timestamp and interval values. The ** first three types are handled explicitly below. ** Intervals will either cause an exception while ** attempting to parse the value or as the default ** action for an unrecognized format. */ try { if (value.Length == 0) // Empty date { /* ** Ingres permits zero length date literals or 'empty' ** dates. Since does not have any corresponding ** date/time concept, we use the date epoch. If ** no timezone is provided, we can return the local ** epoch constant. Otherwise, the epoch value for the ** requested timezone must be generated. */ return((tz == null) ? SqlDates.getEpochDate() : SqlDates.parseDate(SqlDates.D_EPOCH, tz)); } else if (value.Length == SqlDates.D_FMT.Length) // Date only { /* ** The date is stored in GMT such as to have a 0 time for ** the target TZ (requested/local). */ return((tz == null) ? SqlDates.parseDate(value, false) : SqlDates.parseDate(value, tz)); } else if (value.Length == SqlDates.TS_FMT.Length) // Timestamp { /* ** Remove the time component but retain correct date: ** ** 1. Convert to GMT Timestamp using TZ for current connection. ** 2. Format as date only using local TZ to get local date. ** 3. Generate Date value using requested/local timezone. */ DateTime date = SqlDates.parseTimestamp(value, use_gmt); String str = SqlDates.formatDate(date, false); return((osql_dates && tz != null) ? SqlDates.parseDate(str, tz) : SqlDates.parseDate(str, false)); } else // Interval { /* ** Can't support intervals with Date objects. */ throw SqlEx.get(ERR_GC401B_INVALID_DATE); } } catch (SqlEx ex) { /* ** Any parsing error is assumed to be caused by an interval. */ interval = true; throw ex; } } // getDate
getString() { String str; /* ** Ingres dates are overloaded with 'empty' date, ** date only, timestamp and interval values. The ** raw data string is returned for empty dates and ** intervals. Date only values and timestamps are ** parsed/formatted to validate and set timezone. ** Intervals will cause an exception if an attempt ** is made to parse the value or will be detected ** by a mis-match in expected string lengths. */ try { if (value.Length == 0) // Empty date { /* ** Return the empty date string. */ str = value; } else if (value.Length == SqlDates.D_FMT.Length) // Date only { /* ** Do conversion to check for valid format (in ** case this is an interval). Ingres dates are ** indepedent of timezone, so use local TZ. */ DateTime dt = SqlDates.parseDate(value, false); str = SqlDates.formatDate(dt, false); } else if (value.Length == SqlDates.TS_FMT.Length) // Timestamp { /* ** Convert to GMT using TZ for current connection ** and then to local time using local TZ. */ DateTime ts = SqlDates.parseTimestamp(value, use_gmt); str = SqlDates.formatTimestamp(ts, false); } else // Interval { /* ** Return the interval string and produce a warning. */ interval = true; str = value; } } catch (SqlEx) { /* ** Any parsing error is assumed to be caused by an interval. */ interval = true; str = value; } return(str); } // getString