Revision: 4181
          http://vexi.svn.sourceforge.net/vexi/?rev=4181&view=rev
Author:   clrg
Date:     2011-07-08 01:46:27 +0000 (Fri, 08 Jul 2011)

Log Message:
-----------
Fix.  Correct license on JSDate (implemented from scratch by Mike, but had 
header from ECMADate).

Modified Paths:
--------------
    trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/JSDate.jpp

Modified: trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/JSDate.jpp
===================================================================
--- trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/JSDate.jpp       
2011-07-08 01:45:36 UTC (rev 4180)
+++ trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/JSDate.jpp       
2011-07-08 01:46:27 UTC (rev 4181)
@@ -1,38 +1,6 @@
-/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * The contents of this file are subject to the Netscape Public
- * License Version 1.1 (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.mozilla.org/NPL/
- *
- * Software distributed under the License is distributed on an "AS
- * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
- * implied. See the License for the specific language governing
- * rights and limitations under the License.
- *
- * The Original Code is Rhino code, released
- * May 6, 1999.
- *
- * The Initial Developer of the Original Code is Netscape
- * Communications Corporation.  Portions created by Netscape are
- * Copyright (C) 1997-1999 Netscape Communications Corporation. All
- * Rights Reserved.
- *
- * Contributor(s):
- * Norris Boyd
- * Mike McCabe
- *
- * Alternatively, the contents of this file may be used under the
- * terms of the GNU Public License (the "GPL"), in which case the
- * provisions of the GPL are applicable instead of those above.
- * If you wish to allow use of your version of this file only
- * under the terms of the GPL and not to allow others to use your
- * version of this file under the NPL, indicate your decision by
- * deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL.  If you do not delete
- * the provisions above, a recipient may use your version of this
- * file under either the NPL or the GPL.
- */
+// Copyright 2000-2011 the Contributors, as shown in the revision logs.
+// Licensed under the Apache Software License 2.0 ("the License").
+// You may not use this file except in compliance with the License.
 
 package org.ibex.js;
 
@@ -41,39 +9,43 @@
 import java.util.GregorianCalendar;
 
 /**
-  <p>Represents a date. Using the gregorian calendar.</p> 
- 
-  <p>year-month-day hour:minute:second:millis</p>
- 
-  <p>Precision is variable i.e. every part except year is optional.
-
-  <p>Does not represent an instant. A date is an abstract notion which does 
not necessarily correspond to a
-     particular instant in time. Instant depends on timezone and also assuming 
values for date parts which are not provided.
-     (i.e when is 2011/Dec in milliseconds?).
-     These are not kept as part of the date since they are not meaningful.
-  </p>
-  
-  <p>Although it is (or will be, not currently implemented) possible to 
seconds and millis generally when this accuracy is
-     required it is more common to be refering to instances/points in time, in 
which case the date is probably not the
-     right representation.
-  </p>
+ * <p>Represents a date. Using the gregorian calendar.</p> 
+ *
+ * <p>Formatted: year-month-day hour:minute:second:millis</p>
+ *
+ * <p>Precision is variable i.e. every part except year is optional.</p>
+ *
+ * <p><b>Does not represent an instant.</b></p>
+ * 
+ * <p>A date is an abstract notion which does not necessarily correspond to a 
particular
+ *    instant in time. An instant depends on timezone and also assuming values 
for date
+ *    parts which are not provided - i.e when is 2011/Dec in milliseconds?
+ *    These are not kept as part of the date since they are not meaningful.
+ * </p>
+ * 
+ * <p>Although it is (or will be, not currently implemented) possible to 
convert to seconds
+ *    and millis generally when this accuracy is required, it is more common 
to be refering
+ *    to instants/points in time, in which case JSDate is probably not the 
right representation.
+ * </p>
+ * 
+ * @author Mike Goodwin
  */
  
 public class JSDate extends JS.Immutable {
 
     static public int getIntArg(JS[] args, int index, int default_) throws 
JSExn {  
         JS r = JSU.getArg(args, index);
-        if(r==null) return default_;
+        if (r==null) return default_;
         return JSU.toInt(r);
     }
     static public JS toIntOrNull(int value) {
-        if(value==-1) return null;
+        if (value==-1) return null;
         return JSU.N(value);
     }
     
-    static private JSDate expectDate(JS[] args, int i) throws JSExn{
+    static private JSDate expectDate(JS[] args, int i) throws JSExn {
         JS arg = JSU.expectArg(args, i);
-        if(arg==null || !(arg instanceof JSDate)) 
+        if (arg==null || !(arg instanceof JSDate)) 
             throw new JSExn("Argument "+i+" expected date, got: 
"+JSU.toString(arg));
         return (JSDate)arg;
     }
@@ -85,15 +57,15 @@
     static final int PART_DAY = 2;
     
     static private int expectPartIndex(String period) throws JSExn { 
-        for(int i=0; i<PART_NAMES.length; i++){
-            if(PART_NAMES[i].equals(period)) return i;
+        for (int i=0; i<PART_NAMES.length; i++) {
+            if (PART_NAMES[i].equals(period)) return i;
         }
         throw new JSExn("Unknown period: "+period);
     }
     
-    static int getCalendarPart(Calendar c, int index){
+    static int getCalendarPart(Calendar c, int index) {
         int r = c.get(index);
-        if(index == Calendar.MONTH) r = r +1;
+        if (index == Calendar.MONTH) r = r +1;
         return r;
     }
 
@@ -102,7 +74,7 @@
             int[] parts = new int[args.length];
             parts[0] = getIntArg(args, 0, 0);  // year
             
-            for(int i=1; i<args.length; i++){
+            for (int i=1; i<args.length; i++) {
                 parts[i] = getIntArg(args, i, -1); 
             }
             return new JSDate(parts);
@@ -133,7 +105,7 @@
                     case "tryParseString":
                         String[] ss = JSU.toString(args[0]).split("-");
                         int[] ii = new int[ss.length];
-                        for(int i=0; i<ss.length; i++){
+                        for (int i=0; i<ss.length; i++) {
                             ii[i] = Integer.parseInt(ss[i]);
                         }
                         return new JSDate(ii);
@@ -152,68 +124,68 @@
         }
 
     };
-    public boolean instanceOf(JS constructor){ return 
constructor==Constructor; }
+    public boolean instanceOf(JS constructor) { return 
constructor==Constructor; }
     public void addConstructor(JS constructor) throws JSExn {throw new 
JSExn("Attemted to add constructor to date"); }
 
 
     final int[] parts;
     
-    public JSDate(int[] parts) throws JSExn{
+    public JSDate(int[] parts) throws JSExn {
         this.parts = parts;
-        if(parts.length>3) throw new JSExn("Currently date only supports 
year/month/day, got part "+parts.length);
+        if (parts.length>3) throw new JSExn("Currently date only supports 
year/month/day, got part "+parts.length);
         checkValidity();
     }
 
     
-    private JSExn invalid(int part, int value){
+    private JSExn invalid(int part, int value) {
         return new JSExn("Invalid "+PART_NAMES[part]+": "+value);
     }
     
     private void checkValidity() throws JSExn{
-        if(!hasPart(PART_MONTH)) return;
+        if (!hasPart(PART_MONTH)) return;
         int month = parts[PART_MONTH];
-        if(month<1 || month>12) throw invalid(PART_MONTH, month); 
-        if(!hasPart(PART_DAY)) return;
+        if (month<1 || month>12) throw invalid(PART_MONTH, month); 
+        if (!hasPart(PART_DAY)) return;
         int day = parts[PART_DAY];
         // HACK should check day
-        if(day<1 || month>31) throw invalid(PART_DAY, day); 
+        if (day<1 || month>31) throw invalid(PART_DAY, day); 
     }
     
-    private boolean hasPart(int index){
+    private boolean hasPart(int index) {
         return parts.length>index;
     }
-    private int getPart(int index, int default_){ 
-        if(index>=parts.length) return default_;
+    private int getPart(int index, int default_) { 
+        if (index>=parts.length) return default_;
         return parts[index]; 
     }
-    private int getPart(int index){ 
-        if(index>=parts.length) throw new RuntimeException("No value for part: 
"+PART_NAMES[index]);
+    private int getPart(int index) { 
+        if (index>=parts.length) throw new RuntimeException("No value for 
part: "+PART_NAMES[index]);
         return parts[index]; 
     }
     
-    private JS getPartJS(int index){ 
-        if(index>=parts.length) return null;
+    private JS getPartJS(int index) { 
+        if (index>=parts.length) return null;
         return JSU.N(parts[index]); 
     }
-//    private JS getPart(int index, int default_){ 
+//    private JS getPart(int index, int default_) { 
 //        int r = getPart(index, -1);
-//        if(r==-1)
+//        if (r==-1)
 //            
-//        if(index>=parts.length) return default_;
+//        if (index>=parts.length) return default_;
 //        return parts[index]; 
 //    }
-    private String padZero(int n){
-        if(n<10) return "0"+n;
+    private String padZero(int n) {
+        if (n<10) return "0"+n;
         return ""+n;
     }
     
     public String coerceToString() { 
         StringBuffer r = new StringBuffer(64);
         r.append(""+getPart(PART_YEAR));
-        if(hasPart(PART_MONTH)){
+        if (hasPart(PART_MONTH)) {
             r.append("-");
             r.append(padZero(getPart(PART_MONTH)));
-            if(hasPart(PART_DAY)){
+            if (hasPart(PART_DAY)) {
                 r.append("-");
                 r.append(padZero(getPart(PART_DAY)));
             }
@@ -223,7 +195,7 @@
     
     public JS type() { return SC_date; }
 
-    public GregorianCalendar asCalendar(){ 
+    public GregorianCalendar asCalendar() { 
         return new GregorianCalendar(
             getPart(PART_YEAR),
             getPart(PART_MONTH,1)-1,
@@ -237,9 +209,9 @@
         case "year": return getPartJS(PART_YEAR);
         case "month": return getPartJS((PART_MONTH));
         case "day": return getPartJS((PART_DAY));
-        case "hours": 
-        case "minutes": 
-        case "seconds": 
+        case "hours":
+        case "minutes":
+        case "seconds":
             throw new JSExn("Unsupported: "+key);
             
         case "addPeriod": return METHOD;
@@ -252,12 +224,12 @@
 
     private JSDate with(int part, int value) throws JSExn { 
         int[] r;
-        if(part>parts.length){
+        if (part>parts.length) {
             throw new JSExn("Cannot set "+PART_NAMES[part]+" when 
"+PART_NAMES[part-1]+" unset.");
         }
-        if(part==parts.length){
+        if (part==parts.length) {
             r = new int[parts.length+1];
-        }else{
+        } else {
             r = new int[parts.length];
         }
         System.arraycopy(parts, 0, r, 0, parts.length);
@@ -280,7 +252,7 @@
                     Calendar c = asCalendar();
                     c.add(CALENDAR_PART[period], amount);
                     int[] r = new int[parts.length];
-                    for(int i=0; i<parts.length; i++){
+                    for (int i=0; i<parts.length; i++) {
                         r[i] = getCalendarPart(c,CALENDAR_PART[i]);
                     }
                     return new JSDate(r);
@@ -289,20 +261,20 @@
                     String periodStr = JSU.toString(args[0]);
                     int period = expectPartIndex(periodStr);
                     JSDate date = expectDate(args,1);
-                    if(period==PART_MONTH){
+                    if (period==PART_MONTH) {
                         int years = getPart(PART_YEAR, 0) - 
date.getPart(PART_YEAR, 0);
                         int months = getPart(PART_MONTH, 1) - 
date.getPart(PART_MONTH, 1);
                         return JSU.N(years*12 +months);
-                    }else{
+                    } else {
                         throw new JSExn("Unsupported "+periodStr);
                     }
                 }
                 case "withPart": {   
                     int period = expectPartIndex(JSU.toString(args[0]));
                     JS amount = args[1];
-                    if(amount==null){
+                    if (amount==null) {
                         return without(period);    
-                    }else{
+                    } else {
                         return with(period, JSU.toInt(amount));
                     }
                 }
@@ -312,23 +284,23 @@
         return super.callMethod(this_, method, args);
     }
     
-    public boolean equals(Object o){
-        if(!(o instanceof JSDate)) return false;
+    public boolean equals(Object o) {
+        if (!(o instanceof JSDate)) return false;
         JSDate b = (JSDate)o;
-        if(parts.length!=b.parts.length) return false;
-        for(int i=0; i<parts.length; i++){
-            if(parts[i]!=b.parts[i]) return false;
+        if (parts.length!=b.parts.length) return false;
+        for (int i=0; i<parts.length; i++) {
+            if (parts[i]!=b.parts[i]) return false;
         }
         return true;
     }
     
-    public int compareTo(JSDate b){
+    public int compareTo(JSDate b) {
         int l = Math.max(parts.length, b.parts.length);
-        for(int i=0; i<l; i++){
+        for (int i=0; i<l; i++) {
             int pa = getPart(i, -1);
             int pb = b.getPart(i, -1);
-            if(pa>pb) return 1;
-            if(pb>pa) return -1;
+            if (pa>pb) return 1;
+            if (pb>pa) return -1;
         }
         return 0;
     }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security 
threats, fraudulent activity, and more. Splunk takes this data and makes 
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to