Beispiel #1
0
 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