You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vxquery.apache.org by pr...@apache.org on 2012/07/12 01:21:55 UTC

svn commit: r1360472 - in /incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel: accessors/atomic/ util/

Author: prestonc
Date: Wed Jul 11 23:21:54 2012
New Revision: 1360472

URL: http://svn.apache.org/viewvc?rev=1360472&view=rev
Log:
Basic pointable and util functions needed todo basic date and time operations.

Added:
    incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/util/
    incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/util/DateTime.java   (with props)
Modified:
    incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDatePointable.java
    incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDateTimePointable.java
    incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSTimePointable.java

Modified: incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDatePointable.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDatePointable.java?rev=1360472&r1=1360471&r2=1360472&view=diff
==============================================================================
--- incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDatePointable.java (original)
+++ incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDatePointable.java Wed Jul 11 23:21:54 2012
@@ -1,7 +1,145 @@
 package org.apache.vxquery.datamodel.accessors.atomic;
 
+import org.apache.vxquery.datamodel.api.IDate;
+
+import edu.uci.ics.hyracks.api.dataflow.value.ITypeTraits;
 import edu.uci.ics.hyracks.data.std.api.AbstractPointable;
+import edu.uci.ics.hyracks.data.std.api.IPointable;
+import edu.uci.ics.hyracks.data.std.api.IPointableFactory;
+import edu.uci.ics.hyracks.data.std.primitive.BytePointable;
+import edu.uci.ics.hyracks.data.std.primitive.ShortPointable;
+
+/**
+ * The date is split up into five sections. Due to leap year, we have decided to keep the
+ * storage simple by saving each date section separately. For calculations you can access
+ * YearMonth (months) and DayTime (milliseconds) values.
+ * 
+ * @author prestoncarman
+ */
+public class XSDatePointable extends AbstractPointable implements IDate {
+    public final static int YEAR_OFFSET = 0;
+    public final static int MONTH_OFFSET = 2;
+    public final static int DAY_OFFSET = 3;
+    public final static int TIMEZONE_HOUR_OFFSET = 4;
+    public final static int TIMEZONE_MINUTE_OFFSET = 5;
+    // CHRONON_OF_DAY is used to convert days into milliseconds.
+    private final static long CHRONON_OF_DAY = 24 * 60 * 60 * 1000;
+
+    public static final ITypeTraits TYPE_TRAITS = new ITypeTraits() {
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        public boolean isFixedLength() {
+            return true;
+        }
+
+        @Override
+        public int getFixedLength() {
+            return 6;
+        }
+    };
+
+    public static final IPointableFactory FACTORY = new IPointableFactory() {
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        public IPointable createPointable() {
+            return new XSDatePointable();
+        }
+
+        @Override
+        public ITypeTraits getTypeTraits() {
+            return TYPE_TRAITS;
+        }
+    };
+
+    public void setDate(long year, long month, long day, long timezoneHour, long timezoneMinute) {
+        setDate(bytes, start, year, month, day, timezoneHour, timezoneMinute);
+    }
+
+    public static void setDate(byte[] bytes, int start, long year, long month, long day, long timezoneHour, long timezoneMinute) {
+        System.out.println("  day1 = " + day);
+        System.out.println("  month1 = " + month);
+        System.out.println("  year1 = " + year);
+        System.out.println("  timezoneHour = " + timezoneHour);
+        System.out.println("  timezoneMinute = " + timezoneMinute);
+        ShortPointable.setShort(bytes, start + YEAR_OFFSET, (short) year);
+        BytePointable.setByte(bytes, start + MONTH_OFFSET, (byte) month);
+        BytePointable.setByte(bytes, start + DAY_OFFSET, (byte) day);
+        BytePointable.setByte(bytes, start + TIMEZONE_HOUR_OFFSET, (byte) timezoneHour);
+        BytePointable.setByte(bytes, start + TIMEZONE_MINUTE_OFFSET, (byte) timezoneMinute);
+    }
+
+    @Override
+    public long getYear() {
+        return getYear(bytes, start);
+    }
+
+    public static long getYear(byte[] bytes, int start) {
+        return (long) ShortPointable.getShort(bytes, start + YEAR_OFFSET);
+    }
+
+    @Override
+    public long getMonth() {
+        return getMonth(bytes, start);
+    }
+
+    public static long getMonth(byte[] bytes, int start) {
+        return (long) BytePointable.getByte(bytes, start + MONTH_OFFSET);
+    }
+
+    @Override
+    public long getDay() {
+        return getDay(bytes, start);
+    }
+
+    public static long getDay(byte[] bytes, int start) {
+        return (long) BytePointable.getByte(bytes, start + DAY_OFFSET);
+    }
+
+    @Override
+    public long getTimezoneHour() {
+        return getTimezoneHour(bytes, start);
+    }
+
+    public static long getTimezoneHour(byte[] bytes, int start) {
+        return (long) BytePointable.getByte(bytes, start + TIMEZONE_HOUR_OFFSET);
+    }
+
+    @Override
+    public long getTimezoneMinute() {
+        return getTimezoneMinute(bytes, start);
+    }
+
+    public static long getTimezoneMinute(byte[] bytes, int start) {
+        return (long) BytePointable.getByte(bytes, start + TIMEZONE_MINUTE_OFFSET);
+    }
+
+    @Override
+    public long getTimezone() {
+        return getTimezone(bytes, start);
+    }
+
+    public static long getTimezone(byte[] bytes, int start) {
+        return (getTimezoneHour(bytes, start) * 60 + getTimezoneMinute(bytes, start));
+    }
+
+    @Override
+    public long getYearMonth() {
+        return getYearMonth(bytes, start);
+    }
+
+    public static long getYearMonth(byte[] bytes, int start) {
+        return (getYear(bytes, start) * 12 + getMonth(bytes, start));
+    }
+
+    @Override
+    public long getDayTime() {
+        return getDayTime(bytes, start);
+    }
 
-public class XSDatePointable extends AbstractPointable {
+    public static long getDayTime(byte[] bytes, int start) {
+        return getDay(bytes, start) * CHRONON_OF_DAY;
+    }
 
 }
\ No newline at end of file

Modified: incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDateTimePointable.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDateTimePointable.java?rev=1360472&r1=1360471&r2=1360472&view=diff
==============================================================================
--- incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDateTimePointable.java (original)
+++ incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDateTimePointable.java Wed Jul 11 23:21:54 2012
@@ -1,7 +1,187 @@
 package org.apache.vxquery.datamodel.accessors.atomic;
 
+import org.apache.vxquery.datamodel.api.IDate;
+import org.apache.vxquery.datamodel.api.ITime;
+import org.apache.vxquery.datamodel.util.DateTime;
+
+import edu.uci.ics.hyracks.api.dataflow.value.ITypeTraits;
 import edu.uci.ics.hyracks.data.std.api.AbstractPointable;
+import edu.uci.ics.hyracks.data.std.api.IPointable;
+import edu.uci.ics.hyracks.data.std.api.IPointableFactory;
+import edu.uci.ics.hyracks.data.std.primitive.BytePointable;
+import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
+import edu.uci.ics.hyracks.data.std.primitive.ShortPointable;
+
+/**
+ * The datetime is split up into eight sections. Due to leap year, we have decided to keep the
+ * storage simple by saving each datetime section separately. For calculations you can access
+ * YearMonth (months) and DayTime (milliseconds) values.
+ * 
+ * @author prestoncarman
+ */
+public class XSDateTimePointable extends AbstractPointable implements IDate, ITime {
+    public final static int YEAR_OFFSET = 0;
+    public final static int MONTH_OFFSET = 2;
+    public final static int DAY_OFFSET = 3;
+    public final static int HOUR_OFFSET = 4;
+    public final static int MINUTE_OFFSET = 5;
+    public final static int MILLISECOND_OFFSET = 6;
+    public final static int TIMEZONE_HOUR_OFFSET = 10;
+    public final static int TIMEZONE_MINUTE_OFFSET = 11;
+
+    public static final ITypeTraits TYPE_TRAITS = new ITypeTraits() {
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        public boolean isFixedLength() {
+            return true;
+        }
+
+        @Override
+        public int getFixedLength() {
+            return 12;
+        }
+    };
+
+    public static final IPointableFactory FACTORY = new IPointableFactory() {
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        public IPointable createPointable() {
+            return new XSDateTimePointable();
+        }
+
+        @Override
+        public ITypeTraits getTypeTraits() {
+            return TYPE_TRAITS;
+        }
+    };
+
+    public void setDateTime(long year, long month, long day, long hour, long minute, long milliSecond,
+            long timezoneHour, long timezoneMinute) {
+        setDateTime(bytes, start, year, month, day, hour, minute, milliSecond, timezoneHour, timezoneMinute);
+    }
+
+    public static void setDateTime(byte[] bytes, int start, long year, long month, long day, long hour, long minute,
+            long milliSecond, long timezoneHour, long timezoneMinute) {
+        ShortPointable.setShort(bytes, start + YEAR_OFFSET, (short) year);
+        BytePointable.setByte(bytes, start + MONTH_OFFSET, (byte) month);
+        BytePointable.setByte(bytes, start + DAY_OFFSET, (byte) day);
+        BytePointable.setByte(bytes, start + HOUR_OFFSET, (byte) hour);
+        BytePointable.setByte(bytes, start + MINUTE_OFFSET, (byte) minute);
+        IntegerPointable.setInteger(bytes, start + MILLISECOND_OFFSET, (int) milliSecond);
+        BytePointable.setByte(bytes, start + TIMEZONE_HOUR_OFFSET, (byte) timezoneHour);
+        BytePointable.setByte(bytes, start + TIMEZONE_MINUTE_OFFSET, (byte) timezoneMinute);
+    }
+
+    @Override
+    public long getYear() {
+        return getYear(bytes, start);
+    }
+
+    public static long getYear(byte[] bytes, int start) {
+        return (long) ShortPointable.getShort(bytes, start + YEAR_OFFSET);
+    }
+
+    @Override
+    public long getMonth() {
+        return getMonth(bytes, start);
+    }
+
+    public static long getMonth(byte[] bytes, int start) {
+        return (long) BytePointable.getByte(bytes, start + MONTH_OFFSET);
+    }
+
+    @Override
+    public long getDay() {
+        return getDay(bytes, start);
+    }
+
+    public static long getDay(byte[] bytes, int start) {
+        return (long) BytePointable.getByte(bytes, start + DAY_OFFSET);
+    }
+
+    @Override
+    public long getHour() {
+        return getHour(bytes, start);
+    }
+
+    public static long getHour(byte[] bytes, int start) {
+        return (long) BytePointable.getByte(bytes, start + HOUR_OFFSET);
+    }
+
+    @Override
+    public long getMinute() {
+        return getMinute(bytes, start);
+    }
+
+    public static long getMinute(byte[] bytes, int start) {
+        return (long) BytePointable.getByte(bytes, start + MINUTE_OFFSET);
+    }
+
+    @Override
+    public long getMilliSecond() {
+        return getMilliSecond(bytes, start);
+    }
+
+    public static long getMilliSecond(byte[] bytes, int start) {
+        return (long) IntegerPointable.getInteger(bytes, start + MILLISECOND_OFFSET);
+    }
+
+    @Override
+    public long getTimezoneHour() {
+        return getTimezoneHour(bytes, start);
+    }
+
+    public static long getTimezoneHour(byte[] bytes, int start) {
+        return (long) BytePointable.getByte(bytes, start + TIMEZONE_HOUR_OFFSET);
+    }
+
+    @Override
+    public long getTimezoneMinute() {
+        return getTimezoneMinute(bytes, start);
+    }
+
+    public static long getTimezoneMinute(byte[] bytes, int start) {
+        return (long) BytePointable.getByte(bytes, start + TIMEZONE_MINUTE_OFFSET);
+    }
+
+    @Override
+    public long getTimezone() {
+        return getTimezone(bytes, start);
+    }
+
+    public static long getTimezone(byte[] bytes, int start) {
+        return (getTimezoneHour(bytes, start) * 60 + getTimezoneMinute(bytes, start));
+    }
+
+    @Override
+    public long getYearMonth() {
+        return getYearMonth(bytes, start);
+    }
+
+    public static long getYearMonth(byte[] bytes, int start) {
+        return (getYear(bytes, start) * 12 + getMonth(bytes, start));
+    }
+
+    @Override
+    public long getDayTime() {
+        return getDayTime(bytes, start);
+    }
+
+    public static long getDayTime(byte[] bytes, int start) {
+        return (getDay(bytes, start) * DateTime.CHRONON_OF_DAY + getHour(bytes, start)
+                * DateTime.CHRONON_OF_HOUR + getMinute(bytes, start)
+                * DateTime.CHRONON_OF_MINUTE + getMilliSecond(bytes, start));
+    }
+
+    public String toString() {
+        return toString(bytes, start);
+    }
 
-public class XSDateTimePointable extends AbstractPointable {
+    public static String toString(byte[] bytes, int start) {
+        return getMonth(bytes, start) + "/" + getDay(bytes, start) + "/" + getYear(bytes, start) + "T"
+                + getHour(bytes, start) + ":" + getMinute(bytes, start) + ":" + getMilliSecond(bytes, start);
+    }
 
 }
\ No newline at end of file

Modified: incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSTimePointable.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSTimePointable.java?rev=1360472&r1=1360471&r2=1360472&view=diff
==============================================================================
--- incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSTimePointable.java (original)
+++ incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSTimePointable.java Wed Jul 11 23:21:54 2012
@@ -1,7 +1,129 @@
 package org.apache.vxquery.datamodel.accessors.atomic;
 
+import org.apache.vxquery.datamodel.api.ITime;
+
+import edu.uci.ics.hyracks.api.dataflow.value.ITypeTraits;
 import edu.uci.ics.hyracks.data.std.api.AbstractPointable;
+import edu.uci.ics.hyracks.data.std.api.IPointable;
+import edu.uci.ics.hyracks.data.std.api.IPointableFactory;
+import edu.uci.ics.hyracks.data.std.primitive.BytePointable;
+import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
+
+/**
+ * The time is split up into five sections. Due to leap year, we have decided to keep the
+ * storage simple by saving each date section separately. For calculations you can access
+ * DayTime (milliseconds) values.
+ * 
+ * @author prestoncarman
+ */
+public class XSTimePointable extends AbstractPointable implements ITime {
+    public final static int HOUR_OFFSET = 0;
+    public final static int MINUTE_OFFSET = 1;
+    public final static int MILLISECOND_OFFSET = 2;
+    public final static int TIMEZONE_HOUR_OFFSET = 6;
+    public final static int TIMEZONE_MINUTE_OFFSET = 7;
+
+    public static final ITypeTraits TYPE_TRAITS = new ITypeTraits() {
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        public boolean isFixedLength() {
+            return true;
+        }
+
+        @Override
+        public int getFixedLength() {
+            return 4;
+        }
+    };
+
+    public static final IPointableFactory FACTORY = new IPointableFactory() {
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        public IPointable createPointable() {
+            return new XSTimePointable();
+        }
+
+        @Override
+        public ITypeTraits getTypeTraits() {
+            return TYPE_TRAITS;
+        }
+    };
+
+    public void setTime(long hour, long minute, long second, long timezoneHour, long timezoneMinute) {
+        setTime(bytes, start, hour, minute, second, timezoneHour, timezoneMinute);
+    }
+
+    public static void setTime(byte[] bytes, int start, long hour, long minute, long second, long timezoneHour, long timezoneMinute) {
+        BytePointable.setByte(bytes, start + HOUR_OFFSET, (byte) hour);
+        BytePointable.setByte(bytes, start + MINUTE_OFFSET, (byte) minute);
+        IntegerPointable.setInteger(bytes, start + MILLISECOND_OFFSET, (byte) second);
+        BytePointable.setByte(bytes, start + TIMEZONE_HOUR_OFFSET, (byte) timezoneHour);
+        BytePointable.setByte(bytes, start + TIMEZONE_MINUTE_OFFSET, (byte) timezoneMinute);
+    }
+
+    @Override
+    public long getHour() {
+        return getHour(bytes, start);
+    }
+
+    public static long getHour(byte[] bytes, int start) {
+        return (long) BytePointable.getByte(bytes, start + HOUR_OFFSET);
+    }
+
+    @Override
+    public long getMinute() {
+        return getMinute(bytes, start);
+    }
+
+    public static long getMinute(byte[] bytes, int start) {
+        return (long) BytePointable.getByte(bytes, start + MINUTE_OFFSET);
+    }
+
+    @Override
+    public long getMilliSecond() {
+        return getMilliSecond(bytes, start);
+    }
+
+    public static long getMilliSecond(byte[] bytes, int start) {
+        return (long) IntegerPointable.getInteger(bytes, start + MILLISECOND_OFFSET);
+    }
+
+    @Override
+    public long getTimezoneHour() {
+        return getTimezoneHour(bytes, start);
+    }
+
+    public static long getTimezoneHour(byte[] bytes, int start) {
+        return (long) BytePointable.getByte(bytes, start + TIMEZONE_HOUR_OFFSET);
+    }
+
+    @Override
+    public long getTimezoneMinute() {
+        return getTimezoneMinute(bytes, start);
+    }
+
+    public static long getTimezoneMinute(byte[] bytes, int start) {
+        return (long) BytePointable.getByte(bytes, start + TIMEZONE_MINUTE_OFFSET);
+    }
+
+    @Override
+    public long getTimezone() {
+        return getTimezone(bytes, start);
+    }
+
+    public static long getTimezone(byte[] bytes, int start) {
+        return (getTimezoneHour(bytes, start) * 60 + getTimezoneMinute(bytes, start));
+    }
+
+    @Override
+    public long getDayTime() {
+        return getDayTime(bytes, start);
+    }
 
-public class XSTimePointable extends AbstractPointable {
+    public static long getDayTime(byte[] bytes, int start) {
+        return (((getHour(bytes, start)) * 60 + getMinute(bytes, start)) * 60 * 1000 + getMilliSecond(bytes, start));
+    }
 
 }
\ No newline at end of file

Added: incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/util/DateTime.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/util/DateTime.java?rev=1360472&view=auto
==============================================================================
--- incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/util/DateTime.java (added)
+++ incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/util/DateTime.java Wed Jul 11 23:21:54 2012
@@ -0,0 +1,98 @@
+package org.apache.vxquery.datamodel.util;
+
+import org.apache.vxquery.datamodel.accessors.atomic.XSDateTimePointable;
+
+public class DateTime {
+    public static final long[] DAYS_OF_MONTH_ORDI = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+    public static final long[] DAYS_OF_MONTH_LEAP = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+
+    public static final long CHRONON_OF_SECOND = 1000;
+    public static final long CHRONON_OF_MINUTE = 60 * CHRONON_OF_SECOND;
+    public static final long CHRONON_OF_HOUR = 60 * CHRONON_OF_MINUTE;
+    public static final long CHRONON_OF_DAY = 24 * CHRONON_OF_HOUR;
+
+    /**
+     * Minimum feasible value of each field
+     */
+    public static final int[] FIELD_MINS = { Short.MIN_VALUE, // year
+            1, // month
+            1, // day
+            0, // hour
+            0, // minute
+            0 // millisecond
+    };
+
+    public static final int[] FIELD_MAXS = { Short.MAX_VALUE, // year
+            12, // month
+            31, // day
+            23, // hour
+            59, // minute
+            59999 // millisecond
+    };
+
+    public static final int TIMEZONE_HOUR_MIN = -12, TIMEZONE_HOUR_MAX = 14, TIMEZONE_MIN_MIN = -60,
+            TIMEZONE_MIN_MAX = 60;
+    // Used to store the timezone value when one does not exist.
+    public static final byte TIMEZONE_HOUR_NULL = 127, TIMEZONE_MIN_NULL = 127;
+
+    public static final int YEAR_FIELD_INDEX = 0, MONTH_FIELD_INDEX = 1, DAY_FIELD_INDEX = 2, HOUR_FIELD_INDEX = 3,
+            MINUTE_FIELD_INDEX = 4, MILLISECOND_FIELD_INDEX = 5;
+
+    /**
+     * Check whether a given year is a leap year.
+     * 
+     * @param year
+     * @return
+     */
+    public static boolean isLeapYear(long year) {
+        return ((year & 3) == 0) && ((year % 100) != 0 || (year % 400) == 0);
+    }
+
+    /**
+     * Return a normalized time.
+     * 
+     * @param year
+     * @return
+     */
+    public static void normalizeDateTime(byte[] bytes, int start, long yearMonth, long dayTime) {
+        long[] monthDayLimits;
+
+        long day = dayTime / CHRONON_OF_DAY;
+        dayTime %= CHRONON_OF_DAY;
+        long hour = dayTime / CHRONON_OF_HOUR;
+        dayTime %= CHRONON_OF_HOUR;
+        long minute = dayTime / CHRONON_OF_MINUTE;
+        dayTime %= CHRONON_OF_MINUTE;
+        long millisecond = dayTime;
+        long month = yearMonth % 12;
+        long year = yearMonth / 12;
+
+        monthDayLimits = (isLeapYear(year) ? DateTime.DAYS_OF_MONTH_LEAP : DateTime.DAYS_OF_MONTH_ORDI);
+        while (day < DateTime.FIELD_MINS[DateTime.DAY_FIELD_INDEX] || day > monthDayLimits[(int) month - 1]
+                || month < DateTime.FIELD_MINS[DateTime.MONTH_FIELD_INDEX]
+                || month > DateTime.FIELD_MAXS[DateTime.MONTH_FIELD_INDEX]) {
+            if (day < DateTime.FIELD_MINS[DateTime.DAY_FIELD_INDEX]) {
+                // Too small
+                --month;
+                day += monthDayLimits[(int) month - 1];
+            }
+            if (day > monthDayLimits[(int) month - 1]) {
+                // Too large
+                day -= monthDayLimits[(int) month - 1];
+                ++month;
+            }
+            if (month < DateTime.FIELD_MINS[DateTime.MONTH_FIELD_INDEX]) {
+                // Too small
+                month = DateTime.FIELD_MAXS[DateTime.MONTH_FIELD_INDEX];
+                --year;
+            } else if (month > DateTime.FIELD_MAXS[DateTime.MONTH_FIELD_INDEX]) {
+                // Too large
+                month = DateTime.FIELD_MINS[DateTime.MONTH_FIELD_INDEX];
+                ++year;
+            }
+            monthDayLimits = (isLeapYear(year) ? DateTime.DAYS_OF_MONTH_LEAP : DateTime.DAYS_OF_MONTH_ORDI);
+        }
+        XSDateTimePointable.setDateTime(bytes, 0, year, month, day, hour, minute, millisecond, 0, 0);
+    }
+
+}

Propchange: incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/util/DateTime.java
------------------------------------------------------------------------------
    svn:eol-style = native