home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 August / PCO0897.ISO / filesbbs / os2 / fp1os2.arj / OS2 / DATA / 49 / C / 0 / F_26836 / JScriptDateObject.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-05-15  |  4.3 KB  |  176 lines

  1. import java.util.Date;
  2.  
  3. public class JScriptDateObject extends JSbxObject implements JSbxPropertyInterface {
  4.    public static final String NAME = "Date";
  5.    private static final int DATE_ID_GETDATE = 1;
  6.    private static final int DATE_ID_GETDAY = 2;
  7.    private static final int DATE_ID_GETHOURS = 3;
  8.    private static final int DATE_ID_GETMINUTES = 4;
  9.    private static final int DATE_ID_GETMONTH = 5;
  10.    private static final int DATE_ID_GETSECONDS = 6;
  11.    private static final int DATE_ID_GETTIME = 7;
  12.    private static final int DATE_ID_GETTIMEZONEOFFSET = 8;
  13.    private static final int DATE_ID_GETYEAR = 9;
  14.    private static final int DATE_ID_SETDATE = 11;
  15.    private static final int DATE_ID_SETHOURS = 12;
  16.    private static final int DATE_ID_SETMINUTES = 13;
  17.    private static final int DATE_ID_SETMONTH = 14;
  18.    private static final int DATE_ID_SETSECONDS = 15;
  19.    private static final int DATE_ID_SETTIME = 16;
  20.    private static final int DATE_ID_SETYEAR = 17;
  21.    private static final int DATE_ID_TOGMTSTRING = 18;
  22.    private static final int DATE_ID_TOLOCALESTRING = 19;
  23.    private Date aDate = new Date();
  24.  
  25.    public void SetDate(Date var1) {
  26.       this.aDate = var1;
  27.    }
  28.  
  29.    public String GetString() {
  30.       return this.aDate.toString();
  31.    }
  32.  
  33.    public JScriptDateObject(JScriptConstructor var1) {
  34.       super(var1);
  35.  
  36.       try {
  37.          ((JSbxObject)this).Put(new JSbxObjectProperty("getDate", this, this, 1, false, true));
  38.          ((JSbxObject)this).Put(new JSbxObjectProperty("getDay", this, this, 2, false, true));
  39.          ((JSbxObject)this).Put(new JSbxObjectProperty("getHours", this, this, 3, false, true));
  40.          ((JSbxObject)this).Put(new JSbxObjectProperty("getMinutes", this, this, 4, false, true));
  41.          ((JSbxObject)this).Put(new JSbxObjectProperty("getMonth", this, this, 5, false, true));
  42.          ((JSbxObject)this).Put(new JSbxObjectProperty("getSeconds", this, this, 6, false, true));
  43.          ((JSbxObject)this).Put(new JSbxObjectProperty("getTime", this, this, 7, false, true));
  44.          ((JSbxObject)this).Put(new JSbxObjectProperty("getTimezoneOffset", this, this, 8, false, true));
  45.          ((JSbxObject)this).Put(new JSbxObjectProperty("getYear", this, this, 9, false, true));
  46.          ((JSbxObject)this).Put(new JSbxObjectProperty("setDate", this, this, 11, false, true));
  47.          ((JSbxObject)this).Put(new JSbxObjectProperty("setHours", this, this, 12, false, true));
  48.          ((JSbxObject)this).Put(new JSbxObjectProperty("setMinutes", this, this, 13, false, true));
  49.          ((JSbxObject)this).Put(new JSbxObjectProperty("setMonth", this, this, 14, false, true));
  50.          ((JSbxObject)this).Put(new JSbxObjectProperty("setSeconds", this, this, 15, false, true));
  51.          ((JSbxObject)this).Put(new JSbxObjectProperty("setTime", this, this, 16, false, true));
  52.          ((JSbxObject)this).Put(new JSbxObjectProperty("setYear", this, this, 17, false, true));
  53.          ((JSbxObject)this).Put(new JSbxObjectProperty("toGMTString", this, this, 18, false, true));
  54.          ((JSbxObject)this).Put(new JSbxObjectProperty("toLocaleString", this, this, 19, false, true));
  55.       } catch (JSbxException var2) {
  56.       }
  57.    }
  58.  
  59.    public JSbxValue PropertyCallFunction(JSbxObjectProperty var1, JScriptCallParam var2) throws JSbxExceptionBase {
  60.       JSbxVector var3 = var2.GetParamVector();
  61.       int var4 = var1.GetID();
  62.       String var5 = "";
  63.       double var6 = (double)0.0F;
  64.       boolean var8 = true;
  65.       boolean var9 = false;
  66.       switch (var4) {
  67.          case 1:
  68.             var6 = (double)this.aDate.getDate();
  69.             break;
  70.          case 2:
  71.             var6 = (double)this.aDate.getDay();
  72.             break;
  73.          case 3:
  74.             var6 = (double)this.aDate.getHours();
  75.             break;
  76.          case 4:
  77.             var6 = (double)this.aDate.getMinutes();
  78.             break;
  79.          case 5:
  80.             var6 = (double)this.aDate.getMonth();
  81.             break;
  82.          case 6:
  83.             var6 = (double)this.aDate.getSeconds();
  84.             break;
  85.          case 7:
  86.             var6 = (double)this.aDate.getTime();
  87.             break;
  88.          case 8:
  89.             var6 = (double)this.aDate.getTimezoneOffset();
  90.             if (var6 != (double)0.0F) {
  91.                var6 = Math.abs(var6) / var6 * (Math.abs(var6) + (double)1.0F);
  92.             }
  93.             break;
  94.          case 9:
  95.             var6 = (double)this.aDate.getYear();
  96.             if (var6 < (double)0.0F || var6 >= (double)100.0F) {
  97.                var6 += (double)1900.0F;
  98.             }
  99.          case 10:
  100.          default:
  101.             break;
  102.          case 11:
  103.             this.aDate.setDate((int)JScriptWindowObject.GetDoubleParam(var3, 0));
  104.             var9 = true;
  105.             break;
  106.          case 12:
  107.             this.aDate.setHours((int)JScriptWindowObject.GetDoubleParam(var3, 0));
  108.             var9 = true;
  109.             break;
  110.          case 13:
  111.             this.aDate.setMinutes((int)JScriptWindowObject.GetDoubleParam(var3, 0));
  112.             var9 = true;
  113.             break;
  114.          case 14:
  115.             this.aDate.setMonth((int)JScriptWindowObject.GetDoubleParam(var3, 0));
  116.             var9 = true;
  117.             break;
  118.          case 15:
  119.             this.aDate.setSeconds((int)JScriptWindowObject.GetDoubleParam(var3, 0));
  120.             var9 = true;
  121.             break;
  122.          case 16:
  123.             this.aDate.setTime((long)JScriptWindowObject.GetDoubleParam(var3, 0));
  124.             var9 = true;
  125.             break;
  126.          case 17:
  127.             int var10 = (int)JScriptWindowObject.GetDoubleParam(var3, 0);
  128.             if (var10 > 0) {
  129.                var10 -= 1900;
  130.             }
  131.  
  132.             this.aDate.setYear(var10);
  133.             var9 = true;
  134.             break;
  135.          case 18:
  136.             var5 = this.aDate.toGMTString();
  137.             var8 = false;
  138.             break;
  139.          case 19:
  140.             var5 = this.aDate.toLocaleString();
  141.             var8 = false;
  142.       }
  143.  
  144.       Object var11 = null;
  145.       JSbxValue var12;
  146.       if (var9) {
  147.          var12 = new JSbxValue();
  148.       } else if (var8) {
  149.          var12 = new JSbxValue(var6);
  150.       } else {
  151.          var12 = new JSbxValue(var5);
  152.       }
  153.  
  154.       var2.GetRuntimeParam().SetReturnValue(var12);
  155.       return var12;
  156.    }
  157.  
  158.    public void PropertyGet(JSbxObjectProperty var1, JSbxValue var2) throws JSbxException {
  159.    }
  160.  
  161.    public void PropertyPut(JSbxObjectProperty var1, JSbxValue var2) throws JSbxException {
  162.    }
  163.  
  164.    public String Property_GetJScript_typeofString(JSbxObjectProperty var1) {
  165.       return "dateobject";
  166.    }
  167.  
  168.    public String GetJScriptString(boolean var1) {
  169.       return this.aDate.toString();
  170.    }
  171.  
  172.    public JSbxValue GetJScriptValue() {
  173.       return new JSbxValue((double)this.aDate.getTime());
  174.    }
  175. }
  176.