getTime(TimeZone tz) { /* ** Strip date component by re-formatting as time value. */ return(SqlDates.parseTime(SqlDates.formatTime(get(tz), false), false)); } // getTime
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
set(DateTime value, TimeZone tz) { // DateTime does not have a null //if (value == null) //{ // setNull(); // return; //} setNotNull(); nanos = 0; if (value.Kind == DateTimeKind.Utc) // if UTC, normalize to LOCAL { value = value.ToLocalTime(); } switch (dbms_type) { case DBMS_TYPE_TIME: /* ** DAS parses local time using GMT. */ this.value = SqlDates.formatTime(value, true); break; case DBMS_TYPE_TMWO: /* ** Format as local time using requested or default timezone. */ this.value = (tz != null) ? SqlDates.formatTime(value, tz) : SqlDates.formatTime(value, false); break; case DBMS_TYPE_TMTZ: /* ** Format as local time using requested or default timezone. */ this.value = (tz != null) ? SqlDates.formatTime(value, tz) : SqlDates.formatTime(value, false); /* ** Java applies TZ and DST of 'epoch' date: 1970-01-01. ** Ingres applies TZ and DST of todays date, so use ** current date to determine explicit TZ offset. */ long millis = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; timezone = (tz != null) ? SqlDates.formatTZ(tz, millis) : SqlDates.formatTZ(millis); break; } return; } // set
setTime(DateTime value, TimeZone tz) { // DateTime is never null //if ( value == null ) //setNull(); //else { /* ** The time is stored in GMT. Timezones are not applied to ** Ingres times since they are also stored in GMT. OpenSQL ** times 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 time in the desired TZ. */ String str = SqlDates.formatTime(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 so as to cancel the ** future application of the local TZ. */ value = SqlDates.parseTime(str, false); } /* ** Produce the correct time value for the current connection. ** ** Ingres only partially supports time only values and adds ** the current date to such values. JDBC specifies that the ** date portion for time values should be set to the date ** epoch 1970-01-01. When the current date has a different ** daylight savings offset than the epoch, a one hour offset ** can occur because of the different GMT offsets applied by ** Java and Ingres. Due to these problems, format the time ** as a timestamp to ensure consistent processing. Note that ** formatTimestamp() takes a java.util.Date parameter of which ** java.sql.Time is a sub-class. */ setNotNull(); this.value = SqlDates.formatTimestamp(value, use_gmt); interval = false; } return; } // setTime
getString() { /* ** Format using local default TZ for local time. ** Nano-seconds must be manually formatted. */ String str = SqlDates.formatTime(get(null), false); if (nanos > 0) { str += SqlDates.formatFrac(nanos); } return(str); } // getString
setTime(DateTime value, TimeZone tz) { // DateTime is never null //if (value == null) // setNull(); //else if (tz != null) { setString(SqlDates.formatTime(value, tz)); } else { setString(SqlDates.formatTime(value, false)); } return; } // setTime