myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mmarinsc...@apache.org
Subject svn commit: r295103 - in /myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/calendar/resource: Test.java date.js popcalendar.js
Date Wed, 05 Oct 2005 20:29:31 GMT
Author: mmarinschek
Date: Wed Oct  5 13:29:11 2005
New Revision: 295103

URL: http://svn.apache.org/viewcvs?rev=295103&view=rev
Log:
Trying to implement a date parser for javascript compatible to SimpleDateFormat. None under
ASL available...

Added:
    myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/calendar/resource/Test.java
    myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/calendar/resource/date.js
Modified:
    myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/calendar/resource/popcalendar.js

Added: myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/calendar/resource/Test.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/calendar/resource/Test.java?rev=295103&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/calendar/resource/Test.java
(added)
+++ myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/calendar/resource/Test.java
Wed Oct  5 13:29:11 2005
@@ -0,0 +1,113 @@
+package org.apache.myfaces.custom.calendar.resource;
+
+import java.util.Date;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: developer
+ * Date: 05.10.2005
+ * Time: 14:53:18
+ * To change this template use File | Settings | File Templates.
+ */
+public class Test
+{
+    private String pattern;
+
+    public Test(String pattern)
+    {
+        this.pattern = pattern;
+    }
+
+    private Date parse(String dateStr)
+    {
+        int patternIndex = 0;
+        int dateIndex = 0;
+        boolean commentMode = false;
+        char lastChar = 0;
+        char c=0;
+        String patternSub = null;
+
+        int year;
+        int month;
+        int day;
+        int hour;
+        int min;
+        int sec;
+
+        while (patternIndex < pattern.length())
+        {
+            c = pattern.charAt(patternIndex);
+
+            if (c == '\'' && lastChar!='\\')
+            {
+                commentMode = !commentMode;
+                patternIndex++;
+            }
+            else
+            {
+                if(!commentMode)
+                {
+                    if (c == '\\' && lastChar!='\\')
+                    {
+                        patternIndex++;
+                    }
+                    else if(c == lastChar)
+                    {
+                        patternSub+=c;
+                        patternIndex++;
+                    }
+                    else if(patternSub == null)
+                    {
+                        patternSub = "";
+                        patternSub+=c;
+                        patternIndex++;
+                    }
+                    else
+                    {
+                        /*dateStr.substring(dateIndex-patternSub.length(),dateIndex)*/
+
+                        handlePatternSub(patternSub, dateStr, patternIndex, dateIndex);
+
+                        if(patternSub.equals("yyyy") || patternSub.equals("yy")
+                                || patternSub.equals("y"))
+                        {
+
+                        }
+                        patternSub = "";
+                    }
+                }
+                else
+                {
+                    if(pattern.charAt(patternIndex)!=dateStr.charAt(dateIndex))
+                    {
+                        //invalid character in dateString
+                        return null;
+                    }
+
+                    patternIndex++;
+                    dateIndex++;
+                }
+            }
+
+            lastChar = c;
+        }
+
+        return null;
+    }
+
+    private void handlePatternSub(String patternSub, String dateStrSub,
+                                  int patternIndex, int dateIndex)
+    {
+        if(patternSub.equals("yyyy"))
+        {
+            System.out.println(patternSub);
+        }
+    }
+
+    public static void main(String[] args)
+    {
+        Test test = new Test("dd.MM.yyyy");
+
+        test.parse("11.06.2005");
+    }
+}

Added: myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/calendar/resource/date.js
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/calendar/resource/date.js?rev=295103&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/calendar/resource/date.js (added)
+++ myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/calendar/resource/date.js Wed
Oct  5 13:29:11 2005
@@ -0,0 +1,102 @@
+var DateFormatSymbols = Class.create();
+DateFormatSymbols.prototype = {
+    initialize: function()
+    {
+        this.eras = new Array('BC', 'AD');
+        this.months = new Array('January', 'February', 'March', 'April',
+                'May', 'June', 'July', 'August', 'October',
+                'November', 'December', 'Undecimber');
+        this.months = new Array('Jan', 'Feb', 'Mar', 'Apr',
+                'May', 'Jun', 'Jul', 'Aug', 'Oct',
+                'Nov', 'Dec', 'Und');
+        this.weekdays = new Array('', 'Sunday', 'Monday', 'Tuesday',
+                'Wednesday', 'Thursday', 'Friday', 'Saturday');
+        this.shortWeekdays = new Array('', 'Sun', 'Mon', 'Tue',
+                'Wed', 'Thu', 'Fri', 'Sat');
+        this.ampms = new Array('AM', 'PM');
+        this.zoneStrings = new Array(new Array(0, 'long-name', 'short-name'));
+    },
+}
+
+var SimpleDateFormat = Class.create();
+SimpleDateFormat.prototype = {
+    initialize: function(pattern, dateFormatSymbols)
+    {
+        this.pattern = pattern;
+        this.dateFormatSymbols = dateFormatSymbols;
+    },
+
+    format: function(date)
+    {
+
+    },
+
+    parse: function(dateStr)
+    {
+        var patternIndex = 0;
+        var dateIndex = 0;
+        var commentMode = false;
+        var lastChar = -1;
+        var patternSub = null;
+
+        var year;
+        var month;
+        var day;
+        var hour;
+        var min;
+        var sec;
+
+        while (patternIndex < pattern.length)
+        {
+            c = pattern.charAt(patternIndex);
+
+            if (c == '\'' && lastChar!='\\')
+            {
+                commentMode = !commentMode;
+                patternIndex++;
+            }
+            else
+            {
+                if(!commentMode)
+                {
+                    if (c == '\\' && lastChar!='\\')
+                    {
+                        patternIndex++;
+                    }
+                    else if(c == lastChar)
+                    {
+                        patternSub+=c;
+                        patternIndex++;
+                        dateIndex++;
+                    }
+                    else
+                    {
+                        if(patternSub != null)
+                        {
+                            handlePatternSub(patternSub, dateStr.substring(dateIndex-patternSub.length,dateIndex))
+                            patternSub = null;
+                        }
+                        else
+                        {
+                            if(pattern.charAt(patternIndex)!=dateStr.charAt(dateIndex))
+                            {
+                                //invalid character in dateString
+                                return null;
+                            }
+                        }
+                    }
+                }
+                else
+                {
+                    if(pattern.charAt(patternIndex)!=dateStr.charAt(dateIndex))
+                    {
+                        //invalid character in dateString
+                        return null;
+                    }
+                }
+            }
+
+            lastChar = c;
+        }
+    },
+}
\ No newline at end of file

Modified: myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/calendar/resource/popcalendar.js
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/calendar/resource/popcalendar.js?rev=295103&r1=295102&r2=295103&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/calendar/resource/popcalendar.js
(original)
+++ myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/calendar/resource/popcalendar.js
Wed Oct  5 13:29:11 2005
@@ -132,8 +132,8 @@
 		if (jscalendarShowToday==1)
 			document.getElementById("lblToday").innerHTML =	jscalendarTodayString + " <a onmousemove='window.status=\""+jscalendarGotoString+"\"'
onmouseout='window.status=\"\"' title='"+jscalendarGotoString+"' class='"+jscalendarThemePrefix+"-today-style'
href='javascript:jscalendarMonthSelected=jscalendarMonthNow;jscalendarYearSelected=jscalendarYearNow;jscalendarConstructCalendar();'>"+jscalendarDayName[(jscalendarToday.getDay()-jscalendarStartAt==-1)?6:(jscalendarToday.getDay()-jscalendarStartAt)]+",
" + jscalendarDateNow + " " + jscalendarMonthName[jscalendarMonthNow].substring(0,3)	+ "	"
+	jscalendarYearNow	+ "</a>";
 
-		var sHTML1 ="<span id='spanLeft'  class='"+jscalendarThemePrefix+"-title-control-normal-style'
onmouseover='jscalendarSwapImage(\"changeLeft\",\"left2.gif\");  this.className=\""+jscalendarThemePrefix+"-title-control-select-style\";
window.status=\""+jscalendarScrollLeftMessage+"\"' onclick='javascript:jscalendarDecMonth()'
onmouseout='clearInterval(jscalendarIntervalID1);jscalendarSwapImage(\"changeLeft\",\"left1.gif\");
this.className=\""+jscalendarThemePrefix+"-title-control-normal-style\"; window.status=\"\"'
onmousedown='clearTimeout(jscalendarTimeoutID1);jscalendarTimeoutID1=setTimeout(\"jscalendarStartDecMonth()\",500)'
onmouseup='clearTimeout(jscalendarTimeoutID1);clearInterval(jscalendarIntervalID1)'>&nbsp<IMG
id='changeLeft' SRC='"+jscalendarImgDir+"left1.gif' width=10 height=11 BORDER=0>&nbsp</span>&#160;"
-		sHTML1+="<span id='spanRight' class='"+jscalendarThemePrefix+"-title-control-normal-style'
onmouseover='jscalendarSwapImage(\"changeRight\",\"right2.gif\");this.className=\""+jscalendarThemePrefix+"-title-control-select-style\";
window.status=\""+jscalendarScrollRightMessage+"\"' onmouseout='clearInterval(jscalendarIntervalID1);jscalendarSwapImage(\"changeRight\",\"right1.gif\");
this.className=\""+jscalendarThemePrefix+"-title-control-normal-style\"; window.status=\"\"'
onclick='jscalendarIncMonth()' onmousedown='clearTimeout(jscalendarTimeoutID1);jscalendarTimeoutID1=setTimeout(\"jscalendarStartIncMonth()\",500)'
onmouseup='clearTimeout(jscalendarTimeoutID1);clearInterval(jscalendarIntervalID1)'>&nbsp<IMG
id='changeRight' SRC='"+jscalendarImgDir+"right1.gif'	width=10 height=11 BORDER=0>&nbsp</span>&nbsp"
+		var sHTML1 ="<span id='spanLeft'  class='"+jscalendarThemePrefix+"-title-control-normal-style'
onmouseover='jscalendarSwapImage(\"changeLeft\",\"left2.gif\");  this.className=\""+jscalendarThemePrefix+"-title-control-select-style\";
window.status=\""+jscalendarScrollLeftMessage+"\"' onclick='javascript:jscalendarDecMonth()'
onmouseout='clearInterval(jscalendarIntervalID1);jscalendarSwapImage(\"changeLeft\",\"left1.gif\");
this.className=\""+jscalendarThemePrefix+"-title-control-normal-style\"; window.status=\"\"'
onmousedown='clearTimeout(jscalendarTimeoutID1);jscalendarTimeoutID1=setTimeout(\"jscalendarStartDecMonth()\",500)'
onmouseup='clearTimeout(jscalendarTimeoutID1);clearInterval(jscalendarIntervalID1)'>&nbsp<IMG
id='changeLeft' src='"+jscalendarImgDir+"left1.gif' width=10 height=11 border=0>&nbsp</span>&#160;"
+		sHTML1+="<span id='spanRight' class='"+jscalendarThemePrefix+"-title-control-normal-style'
onmouseover='jscalendarSwapImage(\"changeRight\",\"right2.gif\");this.className=\""+jscalendarThemePrefix+"-title-control-select-style\";
window.status=\""+jscalendarScrollRightMessage+"\"' onmouseout='clearInterval(jscalendarIntervalID1);jscalendarSwapImage(\"changeRight\",\"right1.gif\");
this.className=\""+jscalendarThemePrefix+"-title-control-normal-style\"; window.status=\"\"'
onclick='jscalendarIncMonth()' onmousedown='clearTimeout(jscalendarTimeoutID1);jscalendarTimeoutID1=setTimeout(\"jscalendarStartIncMonth()\",500)'
onmouseup='clearTimeout(jscalendarTimeoutID1);clearInterval(jscalendarIntervalID1)'>&nbsp<IMG
id='changeRight' src='"+jscalendarImgDir+"right1.gif'	width=10 height=11 border=0>&nbsp</span>&nbsp"
 		sHTML1+="<span id='spanMonth' class='"+jscalendarThemePrefix+"-title-control-normal-style'
onmouseover='jscalendarSwapImage(\"changeMonth\",\"drop2.gif\"); this.className=\""+jscalendarThemePrefix+"-title-control-select-style\";
window.status=\""+jscalendarSelectMonthMessage+"\"' onmouseout='jscalendarSwapImage(\"changeMonth\",\"drop1.gif\");
this.className=\""+jscalendarThemePrefix+"-title-control-normal-style\"; window.status=\"\"'
onclick='jscalendarPopUpMonth()'></span>&#160;"
 		sHTML1+="<span id='spanYear'  class='"+jscalendarThemePrefix+"-title-control-normal-style'
onmouseover='jscalendarSwapImage(\"changeYear\",\"drop2.gif\");  this.className=\""+jscalendarThemePrefix+"-title-control-select-style\";
window.status=\""+jscalendarSelectYearMessage+"\"'	onmouseout='jscalendarSwapImage(\"changeYear\",\"drop1.gif\");
this.className=\""+jscalendarThemePrefix+"-title-control-normal-style\"; window.status=\"\"'
onclick='jscalendarPopUpYear()'></span>&#160;"
 



Mime
View raw message