getTimestamp(TimeZone tz) { String str = getString().Trim(); return((tz == null) ? SqlDates.parseTimestamp(str, false) : SqlDates.parseTimestamp(str, tz)); }
getTime(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 value.Length == SqlDates.D_FMT.Length) // Date only { /* ** There is no time component, so create a time EPOCH value. ** 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.getEpochTime() : SqlDates.parseTime(SqlDates.T_EPOCH, tz)); } else if (value.Length == SqlDates.TS_FMT.Length) // Timestamp { /* ** Remove the date component but retain correct time: ** ** 1. Convert to GMT timestamp using TZ for current connection. ** 2. Re-format as time only using local TZ to get local time. ** 3. Generate Time value using requested/local TZ. */ DateTime ts = SqlDates.parseTimestamp(value, use_gmt); String str = SqlDates.formatTime(ts, false); return((osql_dates && tz != null) ? SqlDates.parseTime(str, tz) : SqlDates.parseTime(str, false)); } else // Interval { /* ** Can't support intervals with Time 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; } } // getTime
get(TimeZone tz) { DateTime ts; switch (dbms_type) { case DBMS_TYPE_TS: /* ** DAS formats local time using GMT. */ ts = SqlDates.parseTimestamp(value, true); break; case DBMS_TYPE_TSWO: /* ** Interpret as local time in requested or default timezone. */ ts = (tz != null) ? SqlDates.parseTimestamp(value, tz) : SqlDates.parseTimestamp(value, false); break; case DBMS_TYPE_TSTZ: /* ** Apply explicit timezone. */ ts = SqlDates.parseTimestamp(value, SqlDates.getTZ(timezone)); break; default: // should never happen since constructor checked throw SqlEx.get(ERR_GC401B_INVALID_DATE); } // ts.setNanos(nanos); if (nanos > 0) { TimeSpan span = new TimeSpan(nanos / 100L); // one tick = 100 nanos ts += span; // add the nanos back in } return(ts); } // get
setTimestamp(DateTime value, TimeZone tz) { // DateTime is never null //if ( value == null ) //setNull(); //else { /* ** The timestamp is stored in GMT. Timezones are not applied to ** Ingres timestamps since they are also stored in GMT. OpenSQL ** timestamps are assumed to be in the client TZ, so timezones ** can be applied to store values for specific timezones. */ if (osql_dates && tz != null) { /* ** First retrieve the timestamp for the desired TZ. */ String str = SqlDates.formatTimestamp(value, tz); /* ** The local TZ will be applied, either by the driver or ** the gateway, during subsequent processing. We use the ** local TZ to save the desired value to cancel the future ** application. */ value = SqlDates.parseTimestamp(str, false); } setNotNull(); this.value = SqlDates.formatTimestamp(value, use_gmt); interval = false; } return; } // setTimestamp
getTimestamp(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 { /* ** Create a timstamp EPOCH value. 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.getEpochTimestamp() : SqlDates.parseTimestamp(SqlDates.TS_EPOCH, tz)); } else if (value.Length == SqlDates.D_FMT.Length) // Date only { /* ** There is no time component, so convert to timestamp with ** a 0 time component for the requested/local timezone. */ DateTime date = (tz == null) ? SqlDates.parseDate(value, false) : SqlDates.parseDate(value, tz); return(date); } else if (value.Length == SqlDates.TS_FMT.Length) // Timestamp { /* ** Convert to GMT timestamp using TZ for current connection. */ DateTime ts = SqlDates.parseTimestamp(value, use_gmt); if (osql_dates && tz != null) { /* ** Effectively, we need to apply time difference ** between local and requested timezones. First, ** apply local TZ to get local timestamp. Then ** apply requested TZ to get desired GMT value. */ String str = SqlDates.formatTimestamp(ts, false); ts = SqlDates.parseTimestamp(str, tz); } return(ts); } else // Interval { /* ** Can't support intervals with Timestamp 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; } } // getTimestamp
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
getTimestamp(TimeZone tz) { return((tz == null) ? SqlDates.parseTimestamp(value.Trim(), false) : SqlDates.parseTimestamp(value.Trim(), tz)); }