public void setDate(int parameterIndex, java.sql.Date inputValue,
                            java.util.Calendar inputCalendar) //throws SQLException
        {
            String dateString;

            /*
             *     Convert string to YYYYMMDD format that dBase needs.
             */
            if (inputValue == (java.sql.Date)null)
            {
                setString(parameterIndex, (String)null);
            }
            else if (inputValue.toString().trim().length() < 8)
            {
                setString(parameterIndex, (String)null);
            }
            else
            {
                dateString = inputValue.toString().trim();

                /*
                 *        Convert date string to the standard YYYYMMDD format
                 */
                dateString = UtilString.dateValue(dateString);
                setString(parameterIndex, dateString);
            }
        }
Example #2
0
 /*
  * <p>Returns the length of the duration in milli-seconds.</p>
  *
  * <p>If the seconds field carries more digits than milli-second order,
  * those will be simply discarded (or in other words, rounded to zero.)
  * For example, for any Calendar value <code>x</code>,</p>
  * <pre>
  * <code>new Duration("PT10.00099S").getTimeInMills(x) == 10000</code>.
  * <code>new Duration("-PT10.00099S").getTimeInMills(x) == -10000</code>.
  * </pre>
  *
  * <p/>
  * Note that this method uses the {@link #addTo(Calendar)} method,
  * which may work incorrectly with <code>Duration</code> objects with
  * very large values in its fields. See the {@link #addTo(Calendar)}
  * method for details.
  *
  * @param startInstant
  *      The length of a month/year varies. The <code>startInstant</code> is
  *      used to disambiguate this variance. Specifically, this method
  *      returns the difference between <code>startInstant</code> and
  *      <code>startInstant+duration</code>
  *
  * @return milliseconds between <code>startInstant</code> and
  *   <code>startInstant</code> plus this <code>Duration</code>
  *
  * @throws NullPointerException if <code>startInstant</code> parameter
  * is null.
  *
  */
 public long getTimeInMillis(java.util.Calendar startInstant)
 {
     java.util.Calendar cal = (java.util.Calendar)startInstant.clone();
     addTo(cal);
     return(getCalendarTimeInMillis(cal)
            - getCalendarTimeInMillis(startInstant));
 }
Example #3
0
 public void setTimestamp(java.io.RandomAccessFile ff) //throws tinySQLException
 {
     try
     {
         java.util.Calendar cal = java.util.Calendar.getInstance();
         cal.setTime(new java.util.Date());
         int dd = cal.get(java.util.Calendar.DAY_OF_MONTH);
         int mm = cal.get(java.util.Calendar.MONTH) + 1;
         int yy = cal.get(java.util.Calendar.YEAR);
         yy = yy % 100;          // Y2K problem: only 2 digits
         ff.seek(DATE_INDEX);
         ff.write(yy);
         ff.write(mm);
         ff.write(dd);
     }
     catch (Exception e)
     {
         throw new TinySQLException(e.getMessage());
     }
 }
Example #4
0
        /**
         * Convert a Date object to a DOS date/time field.
         *
         * <p>Stolen from InfoZip's <code>fileio.c</code></p>
         * @param t number of milliseconds since the epoch
         * @return the date as a byte array
         */
        public static byte[] toDosTime(long t)
        {
            java.util.Calendar c = java.util.Calendar.getInstance();
            c.setTimeInMillis(t);

            int year = c.get(java.util.Calendar.YEAR);

            if (year < 1980)
            {
                return(copy(DOS_TIME_MIN)); // stop callers from changing the array
            }
            int  month = c.get(java.util.Calendar.MONTH) + 1;
            long value = ((year - 1980) << 25)
                         | (month << 21)
                         | (c.get(java.util.Calendar.DAY_OF_MONTH) << 16)
                         | (c.get(java.util.Calendar.HOUR_OF_DAY) << 11)
                         | (c.get(java.util.Calendar.MINUTE) << 5)
                         | (c.get(java.util.Calendar.SECOND) >> 1);

            return(ZipLong.getBytes(value));
        }
Example #5
0
        /**
         * Converts DOS time to Java time (number of milliseconds since
         * epoch).
         */
        public static long dosToJavaTime(long dosTime)
        {
            java.util.Calendar cal = java.util.Calendar.getInstance();
            // CheckStyle:MagicNumberCheck OFF - no point

            /* Basties Note: why so many method calls?
             * cal.set(java.util.Calendar.YEAR, (int) ((dosTime >> 25) & 0x7f) + 1980);
             * cal.set(java.util.Calendar.MONTH, (int) ((dosTime >> 21) & 0x0f) - 1);
             * cal.set(java.util.Calendar.DATE, (int) (dosTime >> 16) & 0x1f);
             * cal.set(java.util.Calendar.HOUR_OF_DAY, (int) (dosTime >> 11) & 0x1f);
             * cal.set(java.util.Calendar.MINUTE, (int) (dosTime >> 5) & 0x3f);
             * cal.set(java.util.Calendar.SECOND, (int) (dosTime << 1) & 0x3e);
             */
            cal.set((int)(((dosTime >> 25) & 0x7f) + 1980),
                    (int)(((dosTime >> 21) & 0x0f) - 1),
                    (int)((dosTime >> 16) & 0x1f),
                    (int)((dosTime >> 11) & 0x1f),
                    (int)((dosTime >> 5) & 0x3f),
                    (int)((dosTime << 1) & 0x3e));
            // CheckStyle:MagicNumberCheck ON
            return(cal.getTime().getTime());
        }
 public void setTimestamp(int parameterIndex, java.sql.Timestamp inputValue,
                          java.util.Calendar inputCalendar) //throws SQLException
 {
     setString(parameterIndex, inputValue.toString());
 }
Example #7
0
 /*
  * <p>Calls the {@link Calendar#getTimeInMillis} method.
  * Prior to JDK1.4, this method was protected and therefore
  * cannot be invoked directly.</p>
  *
  * <p>TODO: In future, this should be replaced by <code>cal.getTimeInMillis()</code>.</p>
  *
  * @param cal <code>Calendar</code> to get time in milliseconds.
  *
  * @return Milliseconds of <code>cal</code>.
  */
 private static long getCalendarTimeInMillis(java.util.Calendar cal)
 {
     return(cal.getTime().getTime());
 }
Example #8
0
 /*
  * <p>Converts the years and months fields into the days field
  * by using a specific time instant as the reference point.</p>
  *
  * <p>For example, duration of one month normalizes to 31 days
  * given the start time instance "July 8th 2003, 17:40:32".</p>
  *
  * <p>Formally, the computation is done as follows:</p>
  * <ol>
  *  <li>the given Calendar object is cloned</li>
  *  <li>the years, months and days fields will be added to the {@link Calendar} object
  *      by using the {@link Calendar#add(int,int)} method</li>
  *  <li>the difference between the two Calendars in computed in milliseconds and converted to days,
  *     if a remainder occurs due to Daylight Savings Time, it is discarded</li>
  *  <li>the computed days, along with the hours, minutes and seconds
  *      fields of this duration object is used to construct a new
  *      Duration object.</li>
  * </ol>
  *
  * <p>Note that since the Calendar class uses <code>int</code> to
  * hold the value of year and month, this method may produce
  * an unexpected result if this duration object holds
  * a very large value in the years or months fields.</p>
  *
  * @param startTimeInstant <code>Calendar</code> reference point.
  *
  * @return <code>Duration</code> of years and months of this <code>Duration</code> as days.
  *
  * @throws NullPointerException If the startTimeInstant parameter is null.
  */
 public abstract Duration normalizeWith(java.util.Calendar startTimeInstant);
Example #9
0
 /*
  * Adds this duration to a {@link Calendar} object.
  *
  * <p>
  * Calls {@link java.util.Calendar#add(int,int)} in the
  * order of YEARS, MONTHS, DAYS, HOURS, MINUTES, SECONDS, and MILLISECONDS
  * if those fields are present. Because the {@link Calendar} class
  * uses int to hold values, there are cases where this method
  * won't work correctly (for example if values of fields
  * exceed the range of int.)
  * </p>
  *
  * <p>
  * Also, since this duration class is a Gregorian duration, this
  * method will not work correctly if the given {@link Calendar}
  * object is based on some other calendar systems.
  * </p>
  *
  * <p>
  * Any fractional parts of this <code>Duration</code> object
  * beyond milliseconds will be simply ignored. For example, if
  * this duration is "P1.23456S", then 1 is added to SECONDS,
  * 234 is added to MILLISECONDS, and the rest will be unused.
  * </p>
  *
  * <p/>
  * Note that because {@link Calendar#add(int, int)} is using
  * <tt>int</tt>, <code>Duration</code> with values beyond the
  * range of <tt>int</tt> in its fields
  * will cause overflow/underflow to the given {@link Calendar}.
  * {@link XMLGregorianCalendar#add(Duration)} provides the same
  * basic operation as this method while avoiding
  * the overflow/underflow issues.
  *
  * @param calendar
  *      A calendar object whose value will be modified.
  * @throws NullPointerException
  *      if the calendar parameter is null.
  */
 public abstract void addTo(java.util.Calendar calendar);