You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mu...@apache.org on 2023/10/15 14:10:52 UTC

[xalan-java] branch xalan-j_xslt3.0 updated: committing improvements to implementation of xs:dateTime data type for the xpath 3.1 processor, and also committing few new related working test cases as well

This is an automated email from the ASF dual-hosted git repository.

mukulg pushed a commit to branch xalan-j_xslt3.0
in repository https://gitbox.apache.org/repos/asf/xalan-java.git


The following commit(s) were added to refs/heads/xalan-j_xslt3.0 by this push:
     new a09bdb83 committing improvements to implementation of xs:dateTime data type for the xpath 3.1 processor, and also committing few new related working test cases as well
     new ba70ed68 Merge pull request #102 from mukulga/xalan-j_xslt3.0_mukul
a09bdb83 is described below

commit a09bdb83f1fd7496886125eea30c40faf86ee82b
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Sun Oct 15 19:36:45 2023 +0530

    committing improvements to implementation of xs:dateTime data type for the xpath 3.1 processor, and also committing few new related working test cases as well
---
 .../xalan/templates/XSConstructorFunctionUtil.java |  11 +
 src/org/apache/xpath/compiler/Keywords.java        |   3 +
 .../xpath/functions/FuncCurrentDateTime.java       |   5 +-
 src/org/apache/xpath/objects/XObject.java          |  13 ++
 src/org/apache/xpath/xs/types/XSCalendarType.java  |  25 +++
 src/org/apache/xpath/xs/types/XSDate.java          |  51 ++---
 src/org/apache/xpath/xs/types/XSDateTime.java      | 226 ++++++++++++++++++++-
 tests/org/apache/xalan/xpath3/XsDateTimeTests.java | 100 +++++++++
 tests/org/apache/xalan/xslt3/Xsl3TestSuite1.java   |   3 +-
 tests/xs_dateTime/gold/test1.out                   |   8 +
 tests/xs_dateTime/gold/test2.out                   |   8 +
 tests/xs_dateTime/gold/test3.out                   |   8 +
 tests/xs_dateTime/gold/test4.out                   |   8 +
 tests/xs_dateTime/gold/test5.out                   |   6 +
 tests/xs_dateTime/test1.xsl                        |  55 +++++
 tests/xs_dateTime/test1_a.xml                      |   4 +
 tests/xs_dateTime/test2.xsl                        |  55 +++++
 tests/xs_dateTime/test3.xsl                        |  55 +++++
 tests/xs_dateTime/test4.xsl                        |  55 +++++
 tests/xs_dateTime/test5.xsl                        |  51 +++++
 20 files changed, 701 insertions(+), 49 deletions(-)

diff --git a/src/org/apache/xalan/templates/XSConstructorFunctionUtil.java b/src/org/apache/xalan/templates/XSConstructorFunctionUtil.java
index 870a6c21..5d8f5115 100644
--- a/src/org/apache/xalan/templates/XSConstructorFunctionUtil.java
+++ b/src/org/apache/xalan/templates/XSConstructorFunctionUtil.java
@@ -32,6 +32,7 @@ import org.apache.xpath.objects.ResultSequence;
 import org.apache.xpath.objects.XObject;
 import org.apache.xpath.xs.types.XSBoolean;
 import org.apache.xpath.xs.types.XSDate;
+import org.apache.xpath.xs.types.XSDateTime;
 import org.apache.xpath.xs.types.XSDayTimeDuration;
 import org.apache.xpath.xs.types.XSDecimal;
 import org.apache.xpath.xs.types.XSDouble;
@@ -205,6 +206,16 @@ public class XSConstructorFunctionUtil {
                         evalResultSequence = (new XSDate()).constructor(argSequence); 
                         evalResult = evalResultSequence.item(0);
                         
+                        break;
+                    case Keywords.XS_DATETIME :
+                        for (int idx = 0; idx < funcExtFunction.getArgCount(); idx++) {
+                            XObject argVal = (funcExtFunction.getArg(idx)).execute(xctxt);
+                            argSequence.add(XSDateTime.parseDateTime(XslTransformEvaluationHelper.getStrVal(argVal)));
+                        }
+    
+                        evalResultSequence = (new XSDateTime()).constructor(argSequence); 
+                        evalResult = evalResultSequence.item(0);
+                        
                         break;
                     case Keywords.XS_DURATION :
                         for (int idx = 0; idx < funcExtFunction.getArgCount(); idx++) {
diff --git a/src/org/apache/xpath/compiler/Keywords.java b/src/org/apache/xpath/compiler/Keywords.java
index 33ff76f9..471f925d 100644
--- a/src/org/apache/xpath/compiler/Keywords.java
+++ b/src/org/apache/xpath/compiler/Keywords.java
@@ -387,6 +387,9 @@ public class Keywords
   /** xs:date data type string. */
   public static final String XS_DATE = "date";
   
+  /** xs:dateTime data type string. */
+  public static final String XS_DATETIME = "dateTime";
+  
   /** xs:duration data type string. */
   public static final String XS_DURATION = "duration";
   
diff --git a/src/org/apache/xpath/functions/FuncCurrentDateTime.java b/src/org/apache/xpath/functions/FuncCurrentDateTime.java
index ad26223e..08314a91 100644
--- a/src/org/apache/xpath/functions/FuncCurrentDateTime.java
+++ b/src/org/apache/xpath/functions/FuncCurrentDateTime.java
@@ -64,8 +64,9 @@ public class FuncCurrentDateTime extends Function {
   public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
     
     XSDateTime xsDateTime = new XSDateTime(xctxt.getCurrentDateTime(), xctxt.getTimezone());
-
-    return (XObject)xsDateTime;
+    xsDateTime.setPopulatedFromFnCurrentDateTime(true);
+    
+    return xsDateTime;
   }
 
   /**
diff --git a/src/org/apache/xpath/objects/XObject.java b/src/org/apache/xpath/objects/XObject.java
index 429c6c1b..e23050ed 100644
--- a/src/org/apache/xpath/objects/XObject.java
+++ b/src/org/apache/xpath/objects/XObject.java
@@ -37,6 +37,7 @@ import org.apache.xpath.XPathVisitor;
 import org.apache.xpath.res.XPATHErrorResources;
 import org.apache.xpath.xs.types.XSBoolean;
 import org.apache.xpath.xs.types.XSDate;
+import org.apache.xpath.xs.types.XSDateTime;
 import org.apache.xpath.xs.types.XSDecimal;
 import org.apache.xpath.xs.types.XSDouble;
 import org.apache.xpath.xs.types.XSFloat;
@@ -652,6 +653,9 @@ public class XObject extends Expression implements Serializable, Cloneable
        else if ((this instanceof XSDate) && (obj2 instanceof XSDate)) {
            return ((XSDate)this).lt((XSDate)obj2);    
        }
+       else if ((this instanceof XSDateTime) && (obj2 instanceof XSDateTime)) {
+           return ((XSDateTime)this).lt((XSDateTime)obj2);    
+       }
        else if ((this instanceof XNumber) && (obj2 instanceof XNumber)) {
            return ((XNumber)this).num() < ((XNumber)obj2).num(); 
        }
@@ -775,6 +779,9 @@ public class XObject extends Expression implements Serializable, Cloneable
        else if ((this instanceof XSDate) && (obj2 instanceof XSDate)) {
           return ((XSDate)this).gt((XSDate)obj2);    
        }
+       else if ((this instanceof XSDateTime) && (obj2 instanceof XSDateTime)) {
+           return ((XSDateTime)this).gt((XSDateTime)obj2);    
+       }
        else if ((this instanceof XString) && (obj2 instanceof XString)) {          
           String lStr = (((XString)this)).str();
           String rStr = (((XString)obj2)).str();
@@ -956,6 +963,9 @@ public class XObject extends Expression implements Serializable, Cloneable
     else if ((this instanceof XSDate) && (obj2 instanceof XSDate)) {
        return ((XSDate)this).equals((XSDate)obj2);    
     }
+    else if ((this instanceof XSDateTime) && (obj2 instanceof XSDateTime)) {
+        return ((XSDateTime)this).equals((XSDateTime)obj2);    
+    }
     else if ((this instanceof XSInteger) && (obj2 instanceof XNumber)) {
        double lDouble = ((XSInteger)this).doubleValue();
        double rDouble = ((XNumber)obj2).num();
@@ -1020,6 +1030,9 @@ public class XObject extends Expression implements Serializable, Cloneable
     else if ((this instanceof XSDate) && (obj2 instanceof XSDate)) {
         return ((XSDate)this).equals((XSDate)obj2);    
     }
+    else if ((this instanceof XSDateTime) && (obj2 instanceof XSDateTime)) {
+        return ((XSDateTime)this).equals((XSDateTime)obj2);    
+    }
     else if ((this instanceof XSString) && (obj2 instanceof XSString)) {
         return ((XSString)this).equals((XSString)obj2);    
     }
diff --git a/src/org/apache/xpath/xs/types/XSCalendarType.java b/src/org/apache/xpath/xs/types/XSCalendarType.java
index 8a2ecc09..85bb69f2 100644
--- a/src/org/apache/xpath/xs/types/XSCalendarType.java
+++ b/src/org/apache/xpath/xs/types/XSCalendarType.java
@@ -27,5 +27,30 @@ package org.apache.xpath.xs.types;
 public abstract class XSCalendarType extends XSCtrType {
 
     private static final long serialVersionUID = -6546129697566314664L;
+    
+    /**
+     * Determine whether, two timezone values (represented as XSDuration objects) 
+     * are equal. 
+     */
+    protected boolean isTimezoneEqual(XSDuration tz1, XSDuration tz2, 
+                                               boolean isPopulatedFromFnDateFunc1, 
+                                               boolean isPopulatedFromFnDateFunc2) {
+         
+        boolean isTimezoneEqual = false;         
+        
+        if (tz1 == null && tz2 == null) {
+           isTimezoneEqual = true;
+        }
+        else if (tz1 != null && tz2 != null) {
+           isTimezoneEqual = ((tz1.hours() == tz2.hours()) && 
+                                                   (tz1.minutes() == tz2.minutes()) && 
+                                                           (tz1.negative() == tz2.negative()));
+        }
+        else if (isPopulatedFromFnDateFunc1 || isPopulatedFromFnDateFunc2) {
+            isTimezoneEqual = true; 
+        }
+        
+        return isTimezoneEqual;
+    }
 	
 }
diff --git a/src/org/apache/xpath/xs/types/XSDate.java b/src/org/apache/xpath/xs/types/XSDate.java
index bc19218c..8544a235 100644
--- a/src/org/apache/xpath/xs/types/XSDate.java
+++ b/src/org/apache/xpath/xs/types/XSDate.java
@@ -44,8 +44,10 @@ public class XSDate extends XSCalendarType {
     
     private XSDuration _tz;
     
-    // The value of this class field, stores the fact that whether this XSDate
-    // object is constructed via XPath function call fn:current-date().
+    /**
+     * The value of this class field, stores the fact that whether this XSDate
+     * object is constructed via XPath function call fn:current-date().
+     */
     private boolean isPopulatedFromFnCurrentDate = false;
     
     /**
@@ -70,7 +72,7 @@ public class XSDate extends XSCalendarType {
         }
     }
 
-    /*
+    /**
      * Class constructor. 
      */
     public XSDate() {}
@@ -196,7 +198,7 @@ public class XSDate extends XSCalendarType {
      * @return true    if there is a timezone associated with this XSDate object.
      *                 false otherwise.
      */
-    public boolean isXsDateObjectTimezoned() {
+    public boolean isDateTimezoned() {
         return _timezoned;
     }
 
@@ -219,7 +221,7 @@ public class XSDate extends XSCalendarType {
         xsDateStrValue += XSDateTime.padInt(calendarObj.get(Calendar.
                                                                   DAY_OF_MONTH), 2);
 
-        if (isXsDateObjectTimezoned()) {
+        if (isDateTimezoned()) {
             int hrs = _tz.hours();
             int min = _tz.minutes();
             double secs = _tz.seconds();
@@ -243,7 +245,7 @@ public class XSDate extends XSCalendarType {
         return xsDateStrValue;
     }
     
-    /*
+    /**
      * Determine whether, two XSDate objects are equal.
      */
     public boolean equals(XSDate xsDate) {
@@ -263,9 +265,9 @@ public class XSDate extends XSCalendarType {
         XSDuration tz1 = getTimezone();
         XSDuration tz2 = xsDate.getTimezone();
         
-        isDateEqual = (((year1 + month1 + date1) == (year2 + month2 + date2)) && 
-                                     isTimezoneEqual(tz1, tz2, isPopulatedFromFnCurrentDate, 
-                                                                   xsDate.isPopulatedFromFnCurrentDate())); 
+        isDateEqual = ((year1 == year2) && (month1 == month2) && (date1 == date2)) && 
+                                               isTimezoneEqual(tz1, tz2, isPopulatedFromFnCurrentDate, 
+                                                                                   xsDate.isPopulatedFromFnCurrentDate()); 
         
         return isDateEqual; 
     }
@@ -288,7 +290,7 @@ public class XSDate extends XSCalendarType {
        return strVal.hashCode();
     }
     
-    /*
+    /**
      * Determine whether, this XSDate object is less that, the 
      * XSDate object provided as an argument to this method. 
      */
@@ -308,7 +310,7 @@ public class XSDate extends XSCalendarType {
         return isDateBefore;
     }
     
-    /*
+    /**
      * Determine whether, this XSDate object is greater than, the 
      * XSDate object provided as an argument to this method. 
      */
@@ -407,7 +409,7 @@ public class XSDate extends XSCalendarType {
         return CLASS_XS_DATE;
     }
     
-    /*
+    /**
      * Do a data type cast, of an XSAnyType argument passed to this method, to
      * an XSDate object.
      */
@@ -424,30 +426,5 @@ public class XSDate extends XSCalendarType {
 
         return parseDate(xsAnyType.stringValue());
     }
-    
-    /*
-     * Determine whether, two timezone values (represented as XSDuration objects) 
-     * are equal. 
-     */
-    private boolean isTimezoneEqual(XSDuration tz1, XSDuration tz2, 
-                                          boolean isPopulatedFromFnCurrentDate1, 
-                                                          boolean isPopulatedFromFnCurrentDate2) {
-         
-        boolean isTimezoneEqual = false;         
-        
-        if (tz1 == null && tz2 == null) {
-           isTimezoneEqual = true;
-        }
-        else if (tz1 != null && tz2 != null) {
-           isTimezoneEqual = ((tz1.hours() == tz2.hours()) && 
-                                                   (tz1.minutes() == tz2.minutes()) && 
-                                                           (tz1.negative() == tz2.negative()));
-        }
-        else if (isPopulatedFromFnCurrentDate1 || isPopulatedFromFnCurrentDate2) {
-            isTimezoneEqual = true; 
-        }
-        
-        return isTimezoneEqual;
-    }
 
 }
diff --git a/src/org/apache/xpath/xs/types/XSDateTime.java b/src/org/apache/xpath/xs/types/XSDateTime.java
index e854ab4d..0ceac968 100644
--- a/src/org/apache/xpath/xs/types/XSDateTime.java
+++ b/src/org/apache/xpath/xs/types/XSDateTime.java
@@ -20,6 +20,7 @@
 package org.apache.xpath.xs.types;
 
 import java.util.Calendar;
+import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.TimeZone;
 
@@ -47,6 +48,13 @@ public class XSDateTime extends XSCalendarType {
     
     private XSDuration _tz;
     
+    /**
+     * The value of this class field, stores the fact that whether this
+     * XSDateTime object is constructed via XPath function call 
+     * fn:current-dateTime().
+     */
+    private boolean isPopulatedFromFnCurrentDateTime = false;
+    
     /**
      * Class constructor.
      * 
@@ -92,9 +100,20 @@ public class XSDateTime extends XSCalendarType {
     }
 
     @Override
-    public ResultSequence constructor(ResultSequence arg) {
-        // TO DO
-        return null;
+    public ResultSequence constructor(ResultSequence arg) throws TransformerException {
+        ResultSequence resultSeq = new ResultSequence();
+        
+        if (arg.size() == 0) {
+           return resultSeq;     
+        }
+        
+        XSAnyType xsAnyType = (XSAnyType)arg.item(0);
+        
+        XSDateTime xsDateTime = castToDateTime(xsAnyType);
+        
+        resultSeq.add(xsDateTime);
+        
+        return resultSeq;
     }
     
     public Calendar getCalendar() {
@@ -532,6 +551,31 @@ public class XSDateTime extends XSCalendarType {
         return returnVal;
     }
     
+    public int year() {
+        int year = _calendar.get(Calendar.YEAR);
+        if (_calendar.get(Calendar.ERA) == GregorianCalendar.BC) {
+           year = year * -1;
+        }
+
+        return year;
+    }
+    
+    public int month() {
+        return _calendar.get(Calendar.MONTH) + 1;
+    }
+    
+    public int day() {
+        return _calendar.get(Calendar.DAY_OF_MONTH);
+    }
+    
+    public int hour() {
+        return _calendar.get(Calendar.HOUR_OF_DAY);
+    }
+    
+    public int minute() {
+        return _calendar.get(Calendar.MINUTE);
+    }
+    
     public double second() {
         double secondVal = _calendar.get(Calendar.SECOND);
         double millisecVal = _calendar.get(Calendar.MILLISECOND);
@@ -542,17 +586,13 @@ public class XSDateTime extends XSCalendarType {
         return secondVal;
     }
     
-    public int month() {
-        return _calendar.get(Calendar.MONTH) + 1;
-    }
-    
     /**
      * Check whether this XSDateTime object has an, timezone associated with it.
      * 
      * @return true    if there is a timezone associated with this XSDateTime object.
      *                 false otherwise.
      */
-    public boolean isXsDateTimeObjectTimezoned() {
+    public boolean isDateTimeTimezoned() {
         return _timezoned;
     }
 
@@ -597,7 +637,7 @@ public class XSDateTime extends XSCalendarType {
             }
         }
 
-        if (isXsDateTimeObjectTimezoned()) {
+        if (isDateTimeTimezoned()) {
             int hrs = _tz.hours();
             int min = _tz.minutes();
             double secs = _tz.seconds();
@@ -621,10 +661,178 @@ public class XSDateTime extends XSCalendarType {
         return returnVal;
     }
     
+    /**
+     * Determine whether, two XSDateTime objects are equal.
+     */
+    public boolean equals(XSDateTime xsDateTime) {
+        boolean isDateTimeEqual = false;
+        
+        Calendar cal1 = getCalendar();
+        Calendar cal2 = xsDateTime.getCalendar();
+        
+        int year1 = cal1.get(Calendar.YEAR);
+        int month1 = cal1.get(Calendar.MONTH);
+        int date1 = cal1.get(Calendar.DATE);
+        int hour1 = hour();
+        int mins1 = minute();
+        double secs1 = second();
+        
+        int year2 = cal2.get(Calendar.YEAR);
+        int month2 = cal2.get(Calendar.MONTH);
+        int date2 = cal2.get(Calendar.DATE);
+        int hour2 = xsDateTime.hour();
+        int mins2 = xsDateTime.minute();
+        double secs2 = xsDateTime.second();
+        
+        XSDuration tz1 = getTimezone();
+        XSDuration tz2 = xsDateTime.getTimezone();
+        
+        isDateTimeEqual = ((year1 == year2) && (month1 == month2) && (date1 == date2) && 
+                           (hour1 == hour2) && (mins1 == mins2) && (secs1 == secs2)) && 
+                                                    isTimezoneEqual(tz1, tz2, isPopulatedFromFnCurrentDateTime, 
+                                                                    xsDateTime.isPopulatedFromFnCurrentDateTime());
+        
+        return isDateTimeEqual;
+    }
+    
+    @Override
+    public boolean equals(Object obj) {
+       boolean isDateTimeEqual = false;
+        
+       if (obj instanceof XSDateTime) {
+           isDateTimeEqual = this.equals((XSDateTime)obj);  
+       }
+       
+       return isDateTimeEqual;
+    }
+    
+    @Override
+    public int hashCode() {       
+       String strVal = stringValue();       
+       
+       return strVal.hashCode();
+    }
+    
+    /**
+     * Determine whether, this XSDateTime object is less that, the 
+     * XSDateTime object provided as an argument to this method. 
+     */
+    public boolean lt(XSDateTime xsDateTime) {
+        boolean isDateTimeBefore = false;
+        
+        Calendar cal1 = getCalendar();
+        Calendar cal2 = xsDateTime.getCalendar();
+        
+        Date date1 = new Date(cal1.get(Calendar.YEAR), cal1.get(Calendar.MONTH), 
+                                                                     cal1.get(Calendar.DATE));
+        Date date2 = new Date(cal2.get(Calendar.YEAR), cal2.get(Calendar.MONTH), 
+                                                                     cal2.get(Calendar.DATE));
+        
+        if (date1.before(date2)) {
+           isDateTimeBefore = true;  
+        }
+        else if (date1.equals(date2)) {
+            int hour1 = hour();
+            int mins1 = minute();
+            double secs1 = second();
+            
+            int hour2 = xsDateTime.hour();
+            int mins2 = xsDateTime.minute();
+            double secs2 = xsDateTime.second();
+            
+            if (hour1 < hour2) {
+               isDateTimeBefore = true; 
+            }
+            else if (hour1 == hour2) {
+               if (mins1 < mins2) {
+                  isDateTimeBefore = true;  
+               }
+               else if (mins1 == mins2) {
+                  if (secs1 < secs2) {
+                     isDateTimeBefore = true;  
+                  }
+               }
+            }
+        }
+        
+        return isDateTimeBefore;
+    }
+    
+    /**
+     * Determine whether, this XSDateTime object is greater that, the 
+     * XSDateTime object provided as an argument to this method. 
+     */
+    public boolean gt(XSDateTime xsDateTime) {
+        boolean isDateTimeAfter = false;
+        
+        Calendar cal1 = getCalendar();
+        Calendar cal2 = xsDateTime.getCalendar();
+        
+        Date date1 = new Date(cal1.get(Calendar.YEAR), cal1.get(Calendar.MONTH), 
+                                                                     cal1.get(Calendar.DATE));
+        Date date2 = new Date(cal2.get(Calendar.YEAR), cal2.get(Calendar.MONTH), 
+                                                                     cal2.get(Calendar.DATE));
+        
+        if (date1.after(date2)) {
+           isDateTimeAfter = true;  
+        }
+        else if (date1.equals(date2)) {
+            int hour1 = hour();
+            int mins1 = minute();
+            double secs1 = second();
+            
+            int hour2 = xsDateTime.hour();
+            int mins2 = xsDateTime.minute();
+            double secs2 = xsDateTime.second();
+            
+            if (hour1 > hour2) {
+               isDateTimeAfter = true; 
+            }
+            else if (hour1 == hour2) {
+               if (mins1 > mins2) {
+                  isDateTimeAfter = true;  
+               }
+               else if (mins1 == mins2) {
+                  if (secs1 > secs2) {
+                     isDateTimeAfter = true;  
+                  }
+               }
+            }
+        }
+        
+        return isDateTimeAfter;
+    }
+    
+    public boolean isPopulatedFromFnCurrentDateTime() {
+        return isPopulatedFromFnCurrentDateTime;
+    }
+    
+    public void setPopulatedFromFnCurrentDateTime(boolean isPopulatedFromFnCurrentDateTime) {
+        this.isPopulatedFromFnCurrentDateTime = isPopulatedFromFnCurrentDateTime;
+    }
+    
     public int getType() {
         return CLASS_XS_DATETIME;
     }
     
+    /**
+     * Do a data type cast, of an XSAnyType argument passed to this method, to
+     * an XSDateTime object.
+     */
+    private XSDateTime castToDateTime(XSAnyType xsAnyType) throws TransformerException {
+        if (xsAnyType instanceof XSDate) {
+            XSDate xsDate = (XSDate) xsAnyType;
+            return new XSDateTime(xsDate.getCalendar(), xsDate.getTimezone());
+        }
+
+        if (xsAnyType instanceof XSDateTime) {
+            XSDateTime xsDateTime = (XSDateTime) xsAnyType;
+            return new XSDateTime(xsDateTime.getCalendar(), xsDateTime.getTimezone());
+        }
+
+        return parseDateTime(xsAnyType.stringValue()); 
+    }
+    
     /**
      * Set a particular field within an java.util.Calendar object.
      * 
diff --git a/tests/org/apache/xalan/xpath3/XsDateTimeTests.java b/tests/org/apache/xalan/xpath3/XsDateTimeTests.java
new file mode 100644
index 00000000..a8c6bc2a
--- /dev/null
+++ b/tests/org/apache/xalan/xpath3/XsDateTimeTests.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.xalan.xpath3;
+
+import org.apache.xalan.util.XslTransformTestsUtil;
+import org.apache.xalan.xslt3.XSLConstants;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * XPath 3.1 xs:dateTime data type's test cases.
+ * 
+ * @author Mukul Gandhi <mu...@apache.org>
+ * 
+ * @xsl.usage advanced
+ */
+public class XsDateTimeTests extends XslTransformTestsUtil {        
+    
+    private static final String XSL_TRANSFORM_INPUT_DIRPATH = XSLConstants.XSL_TRANSFORM_INPUT_DIRPATH_PREFIX + "xs_dateTime/";
+    
+    private static final String XSL_TRANSFORM_GOLD_DIRPATH = XSLConstants.XSL_TRANSFORM_GOLD_DIRPATH_PREFIX + "xs_dateTime/gold/";
+
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+        // no op
+    }
+
+    @AfterClass
+    public static void tearDownAfterClass() throws Exception {        
+        xmlDocumentBuilderFactory = null;
+        xmlDocumentBuilder = null;
+        xslTransformerFactory = null;
+    }
+
+    @Test
+    public void xsDateTimeTest1() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1.xsl"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test1.out";                
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
+    
+    @Test
+    public void xsDateTimeTest2() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test2.xsl"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test2.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test2.out";                
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
+    
+    @Test
+    public void xsDateTimeTest3() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test3.xsl"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test3.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test3.out";                
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
+    
+    @Test
+    public void xsDateTimeTest4() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test4.xsl"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test4.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test4.out";                
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
+    
+    @Test
+    public void xsDateTimeTest5() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1_a.xml"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test5.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test5.out";                
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
+
+}
diff --git a/tests/org/apache/xalan/xslt3/Xsl3TestSuite1.java b/tests/org/apache/xalan/xslt3/Xsl3TestSuite1.java
index 8890efcb..db4f362a 100644
--- a/tests/org/apache/xalan/xslt3/Xsl3TestSuite1.java
+++ b/tests/org/apache/xalan/xslt3/Xsl3TestSuite1.java
@@ -18,6 +18,7 @@ package org.apache.xalan.xslt3;
 
 import org.apache.xalan.xpath3.FnDataTests;
 import org.apache.xalan.xpath3.FnDocTests;
+import org.apache.xalan.xpath3.XsDateTimeTests;
 import org.junit.runner.RunWith;
 import org.junit.runners.Suite;
 import org.junit.runners.Suite.SuiteClasses;
@@ -31,7 +32,7 @@ import org.junit.runners.Suite.SuiteClasses;
  */
 @RunWith(Suite.class)
 @SuiteClasses({ FnDocTests.class, FnDataTests.class, RecursiveFunctionTests.class,
-                XslFunctionTests.class, HigherOrderFunctionTests.class })
+                XslFunctionTests.class, HigherOrderFunctionTests.class, XsDateTimeTests.class })
 public class Xsl3TestSuite1 {
 
 }
diff --git a/tests/xs_dateTime/gold/test1.out b/tests/xs_dateTime/gold/test1.out
new file mode 100644
index 00000000..f968eac5
--- /dev/null
+++ b/tests/xs_dateTime/gold/test1.out
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+  <one>true</one>
+  <two>true</two>
+  <three>false</three>
+  <four>true</four>
+  <five>false</five>
+  <six>true</six>
+</result>
diff --git a/tests/xs_dateTime/gold/test2.out b/tests/xs_dateTime/gold/test2.out
new file mode 100644
index 00000000..f968eac5
--- /dev/null
+++ b/tests/xs_dateTime/gold/test2.out
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+  <one>true</one>
+  <two>true</two>
+  <three>false</three>
+  <four>true</four>
+  <five>false</five>
+  <six>true</six>
+</result>
diff --git a/tests/xs_dateTime/gold/test3.out b/tests/xs_dateTime/gold/test3.out
new file mode 100644
index 00000000..0ce1ce80
--- /dev/null
+++ b/tests/xs_dateTime/gold/test3.out
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+  <one>false</one>
+  <two>false</two>
+  <three>true</three>
+  <four>false</four>
+  <five>true</five>
+  <six>false</six>
+</result>
diff --git a/tests/xs_dateTime/gold/test4.out b/tests/xs_dateTime/gold/test4.out
new file mode 100644
index 00000000..866a4bd2
--- /dev/null
+++ b/tests/xs_dateTime/gold/test4.out
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+  <one>false</one>
+  <two>true</two>
+  <three>false</three>
+  <four>true</four>
+  <five>false</five>
+  <six>false</six>
+</result>
diff --git a/tests/xs_dateTime/gold/test5.out b/tests/xs_dateTime/gold/test5.out
new file mode 100644
index 00000000..38e941bb
--- /dev/null
+++ b/tests/xs_dateTime/gold/test5.out
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+  <one>true</one>
+  <two>false</two>
+  <three>false</three>
+  <four>true</four>
+</result>
diff --git a/tests/xs_dateTime/test1.xsl b/tests/xs_dateTime/test1.xsl
new file mode 100644
index 00000000..9f8e5853
--- /dev/null
+++ b/tests/xs_dateTime/test1.xsl
@@ -0,0 +1,55 @@
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                xmlns:xs="http://www.w3.org/2001/XMLSchema"
+                exclude-result-prefixes="xs"
+                version="3.0">
+                
+  <!-- Author: mukulg@apache.org -->
+  
+  <!-- This XSLT stylesheet tests, xs:dateTime data type's constructor
+       function, and XPath's '=' operator on xs:dateTime values. 
+  -->                
+                
+  <xsl:output method="xml" indent="yes"/>
+  
+  <xsl:template match="/">     
+     <result>
+        <one>
+           <xsl:value-of select="xs:dateTime('1982-03-23T07:20:15') = xs:dateTime('1982-03-23T07:20:15')"/>
+        </one>
+        <two>
+	       <xsl:value-of select="xs:dateTime('1982-03-23T07:20:15Z') = xs:dateTime('1982-03-23T07:20:15Z')"/>
+        </two>
+        <three>
+           <xsl:value-of select="xs:dateTime('1982-03-23T07:20:15Z') = xs:dateTime('1982-03-23T07:20:15')"/>
+        </three>
+        <four>
+	       <xsl:value-of select="xs:dateTime('1982-03-23T07:20:15+10:30') = xs:dateTime('1982-03-23T07:20:15+10:30')"/>
+        </four>
+        <five>
+           <xsl:value-of select="xs:dateTime('2023-03-22T07:20:15') = xs:dateTime('2023-03-23T07:20:15')"/>
+        </five>
+        <six>
+	       <xsl:value-of select="current-dateTime() = current-dateTime()"/>
+        </six>
+     </result>
+  </xsl:template>
+  
+  <!--
+      * Licensed to the Apache Software Foundation (ASF) under one
+      * or more contributor license agreements. See the NOTICE file
+      * distributed with this work for additional information
+      * regarding copyright ownership. The ASF licenses this file
+      * to you under the Apache License, Version 2.0 (the  "License");
+      * you may not use this file except in compliance with the License.
+      * You may obtain a copy of the License at
+      *
+      *     http://www.apache.org/licenses/LICENSE-2.0
+      *
+      * Unless required by applicable law or agreed to in writing, software
+      * distributed under the License is distributed on an "AS IS" BASIS,
+      * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+      * See the License for the specific language governing permissions and
+      * limitations under the License.
+   -->
+
+</xsl:stylesheet>
\ No newline at end of file
diff --git a/tests/xs_dateTime/test1_a.xml b/tests/xs_dateTime/test1_a.xml
new file mode 100644
index 00000000..ccd23d28
--- /dev/null
+++ b/tests/xs_dateTime/test1_a.xml
@@ -0,0 +1,4 @@
+<info>
+  <dateTime>1982-03-23T07:20:15</dateTime>
+  <dateTime>2570-03-23T07:20:15</dateTime>
+</info>
\ No newline at end of file
diff --git a/tests/xs_dateTime/test2.xsl b/tests/xs_dateTime/test2.xsl
new file mode 100644
index 00000000..12c759b8
--- /dev/null
+++ b/tests/xs_dateTime/test2.xsl
@@ -0,0 +1,55 @@
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                xmlns:xs="http://www.w3.org/2001/XMLSchema"
+                exclude-result-prefixes="xs"
+                version="3.0">
+                
+  <!-- Author: mukulg@apache.org -->
+  
+  <!-- This XSLT stylesheet tests, xs:dateTime data type's constructor
+       function, and XPath's 'eq' operator on xs:dateTime values. 
+  -->                
+                
+  <xsl:output method="xml" indent="yes"/>
+  
+  <xsl:template match="/">     
+     <result>
+        <one>
+           <xsl:value-of select="xs:dateTime('1982-03-23T07:20:15') eq xs:dateTime('1982-03-23T07:20:15')"/>
+        </one>
+        <two>
+	       <xsl:value-of select="xs:dateTime('1982-03-23T07:20:15Z') eq xs:dateTime('1982-03-23T07:20:15Z')"/>
+        </two>
+        <three>
+           <xsl:value-of select="xs:dateTime('1982-03-23T07:20:15Z') eq xs:dateTime('1982-03-23T07:20:15')"/>
+        </three>
+        <four>
+	       <xsl:value-of select="xs:dateTime('1982-03-23T07:20:15+10:30') eq xs:dateTime('1982-03-23T07:20:15+10:30')"/>
+        </four>
+        <five>
+           <xsl:value-of select="xs:dateTime('2023-03-22T07:20:15') eq xs:dateTime('2023-03-23T07:20:15')"/>
+        </five>
+        <six>
+	       <xsl:value-of select="current-dateTime() eq current-dateTime()"/>
+        </six>
+     </result>
+  </xsl:template>
+  
+  <!--
+      * Licensed to the Apache Software Foundation (ASF) under one
+      * or more contributor license agreements. See the NOTICE file
+      * distributed with this work for additional information
+      * regarding copyright ownership. The ASF licenses this file
+      * to you under the Apache License, Version 2.0 (the  "License");
+      * you may not use this file except in compliance with the License.
+      * You may obtain a copy of the License at
+      *
+      *     http://www.apache.org/licenses/LICENSE-2.0
+      *
+      * Unless required by applicable law or agreed to in writing, software
+      * distributed under the License is distributed on an "AS IS" BASIS,
+      * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+      * See the License for the specific language governing permissions and
+      * limitations under the License.
+   -->
+
+</xsl:stylesheet>
\ No newline at end of file
diff --git a/tests/xs_dateTime/test3.xsl b/tests/xs_dateTime/test3.xsl
new file mode 100644
index 00000000..c0900a31
--- /dev/null
+++ b/tests/xs_dateTime/test3.xsl
@@ -0,0 +1,55 @@
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                xmlns:xs="http://www.w3.org/2001/XMLSchema"
+                exclude-result-prefixes="xs"
+                version="3.0">
+                
+  <!-- Author: mukulg@apache.org -->
+  
+  <!-- This XSLT stylesheet tests, xs:dateTime data type's constructor
+       function, and XPath's 'lt' operator on xs:dateTime values. 
+  -->                
+                
+  <xsl:output method="xml" indent="yes"/>
+  
+  <xsl:template match="/">     
+     <result>
+        <one>
+           <xsl:value-of select="xs:dateTime('1982-03-23T07:20:15') lt xs:dateTime('1982-03-23T07:20:15')"/>
+        </one>
+        <two>
+	       <xsl:value-of select="xs:dateTime('1982-03-23T07:20:16') lt xs:dateTime('1982-03-23T07:20:15')"/>
+        </two>
+        <three>
+	       <xsl:value-of select="xs:dateTime('1982-03-23T07:20:14') lt xs:dateTime('1982-03-23T07:20:15')"/>
+        </three>
+        <four>
+	       <xsl:value-of select="xs:dateTime('1982-03-24T07:20:15') lt xs:dateTime('1982-03-23T07:20:15')"/>
+        </four>
+        <five>
+	       <xsl:value-of select="xs:dateTime('1982-03-22T07:20:15') lt xs:dateTime('1982-03-23T07:20:15')"/>
+        </five>
+        <six>
+           <xsl:value-of select="current-dateTime() lt current-dateTime()"/>
+        </six>
+     </result>
+  </xsl:template>
+  
+  <!--
+      * Licensed to the Apache Software Foundation (ASF) under one
+      * or more contributor license agreements. See the NOTICE file
+      * distributed with this work for additional information
+      * regarding copyright ownership. The ASF licenses this file
+      * to you under the Apache License, Version 2.0 (the  "License");
+      * you may not use this file except in compliance with the License.
+      * You may obtain a copy of the License at
+      *
+      *     http://www.apache.org/licenses/LICENSE-2.0
+      *
+      * Unless required by applicable law or agreed to in writing, software
+      * distributed under the License is distributed on an "AS IS" BASIS,
+      * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+      * See the License for the specific language governing permissions and
+      * limitations under the License.
+   -->
+
+</xsl:stylesheet>
\ No newline at end of file
diff --git a/tests/xs_dateTime/test4.xsl b/tests/xs_dateTime/test4.xsl
new file mode 100644
index 00000000..253cbbbb
--- /dev/null
+++ b/tests/xs_dateTime/test4.xsl
@@ -0,0 +1,55 @@
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                xmlns:xs="http://www.w3.org/2001/XMLSchema"
+                exclude-result-prefixes="xs"
+                version="3.0">
+                
+  <!-- Author: mukulg@apache.org -->
+  
+  <!-- This XSLT stylesheet tests, xs:dateTime data type's constructor
+       function, and XPath's 'gt' operator on xs:dateTime values. 
+  -->                
+                
+  <xsl:output method="xml" indent="yes"/>
+  
+  <xsl:template match="/">     
+     <result>
+        <one>
+           <xsl:value-of select="xs:dateTime('1982-03-23T07:20:15') gt xs:dateTime('1982-03-23T07:20:15')"/>
+        </one>
+        <two>
+	       <xsl:value-of select="xs:dateTime('1982-03-23T07:20:16') gt xs:dateTime('1982-03-23T07:20:15')"/>
+        </two>
+        <three>
+	       <xsl:value-of select="xs:dateTime('1982-03-23T07:20:14') gt xs:dateTime('1982-03-23T07:20:15')"/>
+        </three>
+        <four>
+	       <xsl:value-of select="xs:dateTime('1982-03-24T07:20:15') gt xs:dateTime('1982-03-23T07:20:15')"/>
+        </four>
+        <five>
+	       <xsl:value-of select="xs:dateTime('1982-03-22T07:20:15') gt xs:dateTime('1982-03-23T07:20:15')"/>
+        </five>
+        <six>
+           <xsl:value-of select="current-dateTime() gt current-dateTime()"/>
+        </six>
+     </result>
+  </xsl:template>
+  
+  <!--
+      * Licensed to the Apache Software Foundation (ASF) under one
+      * or more contributor license agreements. See the NOTICE file
+      * distributed with this work for additional information
+      * regarding copyright ownership. The ASF licenses this file
+      * to you under the Apache License, Version 2.0 (the  "License");
+      * you may not use this file except in compliance with the License.
+      * You may obtain a copy of the License at
+      *
+      *     http://www.apache.org/licenses/LICENSE-2.0
+      *
+      * Unless required by applicable law or agreed to in writing, software
+      * distributed under the License is distributed on an "AS IS" BASIS,
+      * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+      * See the License for the specific language governing permissions and
+      * limitations under the License.
+  -->
+
+</xsl:stylesheet>
\ No newline at end of file
diff --git a/tests/xs_dateTime/test5.xsl b/tests/xs_dateTime/test5.xsl
new file mode 100644
index 00000000..b922faf4
--- /dev/null
+++ b/tests/xs_dateTime/test5.xsl
@@ -0,0 +1,51 @@
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                xmlns:xs="http://www.w3.org/2001/XMLSchema"
+                exclude-result-prefixes="xs"
+                version="3.0">
+                
+  <!-- Author: mukulg@apache.org -->
+  
+  <!-- use with test1_a.xml -->
+  
+  <!-- This XSLT stylesheet tests, xs:dateTime data type's constructor
+       function, and XPath's 'lt' and 'gt' operators on xs:dateTime values. 
+  -->                 
+                
+  <xsl:output method="xml" indent="yes"/>
+  
+  <xsl:template match="/info">     
+     <result>
+        <one>
+           <xsl:value-of select="xs:dateTime(dateTime[1]) lt current-dateTime()"/>
+        </one>
+        <two>
+	       <xsl:value-of select="xs:dateTime(dateTime[1]) gt current-dateTime()"/>
+        </two>
+        <three>
+           <xsl:value-of select="xs:dateTime(dateTime[2]) lt current-dateTime()"/>
+        </three>
+        <four>
+	       <xsl:value-of select="xs:dateTime(dateTime[2]) gt current-dateTime()"/>
+        </four>
+     </result>
+  </xsl:template>
+  
+  <!--
+      * Licensed to the Apache Software Foundation (ASF) under one
+      * or more contributor license agreements. See the NOTICE file
+      * distributed with this work for additional information
+      * regarding copyright ownership. The ASF licenses this file
+      * to you under the Apache License, Version 2.0 (the  "License");
+      * you may not use this file except in compliance with the License.
+      * You may obtain a copy of the License at
+      *
+      *     http://www.apache.org/licenses/LICENSE-2.0
+      *
+      * Unless required by applicable law or agreed to in writing, software
+      * distributed under the License is distributed on an "AS IS" BASIS,
+      * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+      * See the License for the specific language governing permissions and
+      * limitations under the License.
+  -->
+
+</xsl:stylesheet>
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xalan.apache.org
For additional commands, e-mail: commits-help@xalan.apache.org