home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / java / util / SimpleTimeZone.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  7.9 KB  |  528 lines

  1. package java.util;
  2.  
  3. import java.io.IOException;
  4. import java.io.ObjectInputStream;
  5. import java.io.ObjectOutputStream;
  6.  
  7. public class SimpleTimeZone extends TimeZone {
  8.    private int startMonth;
  9.    private int startDay;
  10.    private int startDayOfWeek;
  11.    private int startTime;
  12.    private int startTimeMode;
  13.    private int endMonth;
  14.    private int endDay;
  15.    private int endDayOfWeek;
  16.    private int endTime;
  17.    private int endTimeMode;
  18.    private int startYear;
  19.    private int rawOffset;
  20.    private boolean useDaylight;
  21.    private static final int millisPerHour = 3600000;
  22.    private static final int millisPerDay = 86400000;
  23.    private final byte[] monthLength;
  24.    private static final byte[] staticMonthLength = new byte[]{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  25.    private static final byte[] staticLeapMonthLength = new byte[]{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  26.    private static GregorianCalendar internalCal = new GregorianCalendar();
  27.    private int startMode;
  28.    private int endMode;
  29.    private int dstSavings;
  30.    private static final int DOM_MODE = 1;
  31.    private static final int DOW_IN_MONTH_MODE = 2;
  32.    private static final int DOW_GE_DOM_MODE = 3;
  33.    private static final int DOW_LE_DOM_MODE = 4;
  34.    static final int WALL_TIME = 0;
  35.    static final int STANDARD_TIME = 1;
  36.    static final int UTC_TIME = 2;
  37.    static final long serialVersionUID = -403250971215465050L;
  38.    static final int currentSerialVersion = 2;
  39.    private int serialVersionOnStream;
  40.  
  41.    public SimpleTimeZone(int var1, String var2) {
  42.       this.useDaylight = false;
  43.       this.monthLength = staticMonthLength;
  44.       this.serialVersionOnStream = 2;
  45.       this.rawOffset = var1;
  46.       ((TimeZone)this).setID(var2);
  47.       this.dstSavings = 3600000;
  48.    }
  49.  
  50.    public SimpleTimeZone(int var1, String var2, int var3, int var4, int var5, int var6, int var7, int var8, int var9, int var10) {
  51.       this(var1, var2, var3, var4, var5, var6, 0, var7, var8, var9, var10, 0, 3600000);
  52.    }
  53.  
  54.    public SimpleTimeZone(int var1, String var2, int var3, int var4, int var5, int var6, int var7, int var8, int var9, int var10, int var11) {
  55.       this(var1, var2, var3, var4, var5, var6, 0, var7, var8, var9, var10, 0, var11);
  56.    }
  57.  
  58.    SimpleTimeZone(int var1, String var2, int var3, int var4, int var5, int var6, int var7, int var8, int var9, int var10, int var11, int var12, int var13) {
  59.       this.useDaylight = false;
  60.       this.monthLength = staticMonthLength;
  61.       this.serialVersionOnStream = 2;
  62.       ((TimeZone)this).setID(var2);
  63.       this.rawOffset = var1;
  64.       this.startMonth = var3;
  65.       this.startDay = var4;
  66.       this.startDayOfWeek = var5;
  67.       this.startTime = var6;
  68.       this.startTimeMode = var7;
  69.       this.endMonth = var8;
  70.       this.endDay = var9;
  71.       this.endDayOfWeek = var10;
  72.       this.endTime = var11;
  73.       this.endTimeMode = var12;
  74.       this.dstSavings = var13;
  75.       this.decodeRules();
  76.       if (var13 <= 0) {
  77.          throw new IllegalArgumentException("Illegal DST savings");
  78.       }
  79.    }
  80.  
  81.    public void setStartYear(int var1) {
  82.       this.startYear = var1;
  83.    }
  84.  
  85.    public void setStartRule(int var1, int var2, int var3, int var4) {
  86.       this.startMonth = var1;
  87.       this.startDay = var2;
  88.       this.startDayOfWeek = var3;
  89.       this.startTime = var4;
  90.       this.startTimeMode = 0;
  91.       this.decodeStartRule();
  92.    }
  93.  
  94.    public void setStartRule(int var1, int var2, int var3) {
  95.       this.setStartRule(var1, var2, 0, var3);
  96.    }
  97.  
  98.    public void setStartRule(int var1, int var2, int var3, int var4, boolean var5) {
  99.       if (var5) {
  100.          this.setStartRule(var1, var2, -var3, var4);
  101.       } else {
  102.          this.setStartRule(var1, -var2, -var3, var4);
  103.       }
  104.  
  105.    }
  106.  
  107.    public void setEndRule(int var1, int var2, int var3, int var4) {
  108.       this.endMonth = var1;
  109.       this.endDay = var2;
  110.       this.endDayOfWeek = var3;
  111.       this.endTime = var4;
  112.       this.endTimeMode = 0;
  113.       this.decodeEndRule();
  114.    }
  115.  
  116.    public void setEndRule(int var1, int var2, int var3) {
  117.       this.setEndRule(var1, var2, 0, var3);
  118.    }
  119.  
  120.    public void setEndRule(int var1, int var2, int var3, int var4, boolean var5) {
  121.       if (var5) {
  122.          this.setEndRule(var1, var2, -var3, var4);
  123.       } else {
  124.          this.setEndRule(var1, -var2, -var3, var4);
  125.       }
  126.  
  127.    }
  128.  
  129.    public int getOffset(int var1, int var2, int var3, int var4, int var5, int var6) {
  130.       if (var3 >= 0 && var3 <= 11) {
  131.          byte var7;
  132.          byte var8;
  133.          if (var1 == 1 && internalCal.isLeapYear(var2)) {
  134.             var7 = staticLeapMonthLength[var3];
  135.             var8 = var3 > 1 ? staticLeapMonthLength[var3 - 1] : 31;
  136.          } else {
  137.             var7 = staticMonthLength[var3];
  138.             var8 = var3 > 1 ? staticMonthLength[var3 - 1] : 31;
  139.          }
  140.  
  141.          return this.getOffset(var1, var2, var3, var4, var5, var6, var7, var8);
  142.       } else {
  143.          throw new IllegalArgumentException("Illegal month " + var3);
  144.       }
  145.    }
  146.  
  147.    int getOffset(int var1, int var2, int var3, int var4, int var5, int var6, int var7, int var8) {
  148.       if ((var1 == 1 || var1 == 0) && var3 >= 0 && var3 <= 11 && var4 >= 1 && var4 <= var7 && var5 >= 1 && var5 <= 7 && var6 >= 0 && var6 < 86400000 && var7 >= 28 && var7 <= 31 && var8 >= 28 && var8 <= 31) {
  149.          int var9 = this.rawOffset;
  150.          if (this.useDaylight && var2 >= this.startYear && var1 == 1) {
  151.             boolean var10 = this.startMonth > this.endMonth;
  152.             int var11 = compareToRule(var3, var7, var8, var4, var5, var6, this.startTimeMode == 2 ? -this.rawOffset : 0, this.startMode, this.startMonth, this.startDayOfWeek, this.startDay, this.startTime);
  153.             int var12 = 0;
  154.             if (var10 != var11 >= 0) {
  155.                var12 = compareToRule(var3, var7, var8, var4, var5, var6, this.endTimeMode == 0 ? this.dstSavings : (this.endTimeMode == 2 ? -this.rawOffset : 0), this.endMode, this.endMonth, this.endDayOfWeek, this.endDay, this.endTime);
  156.             }
  157.  
  158.             if (!var10 && var11 >= 0 && var12 < 0 || var10 && (var11 >= 0 || var12 < 0)) {
  159.                var9 += this.dstSavings;
  160.             }
  161.  
  162.             return var9;
  163.          } else {
  164.             return var9;
  165.          }
  166.       } else {
  167.          throw new IllegalArgumentException();
  168.       }
  169.    }
  170.  
  171.    private static int compareToRule(int var0, int var1, int var2, int var3, int var4, int var5, int var6, int var7, int var8, int var9, int var10, int var11) {
  172.       var5 += var6;
  173.  
  174.       while(var5 >= 86400000) {
  175.          var5 -= 86400000;
  176.          ++var3;
  177.          var4 = 1 + var4 % 7;
  178.          if (var3 > var1) {
  179.             var3 = 1;
  180.             ++var0;
  181.          }
  182.       }
  183.  
  184.       while(var5 < 0) {
  185.          var5 += 86400000;
  186.          --var3;
  187.          var4 = 1 + (var4 + 5) % 7;
  188.          if (var3 < 1) {
  189.             var3 = var2;
  190.             --var0;
  191.          }
  192.       }
  193.  
  194.       if (var0 < var8) {
  195.          return -1;
  196.       } else if (var0 > var8) {
  197.          return 1;
  198.       } else {
  199.          int var12 = 0;
  200.          switch (var7) {
  201.             case 1:
  202.                var12 = var10;
  203.                break;
  204.             case 2:
  205.                if (var10 > 0) {
  206.                   var12 = 1 + (var10 - 1) * 7 + (7 + var9 - (var4 - var3 + 1)) % 7;
  207.                } else {
  208.                   var12 = var1 + (var10 + 1) * 7 - (7 + (var4 + var1 - var3) - var9) % 7;
  209.                }
  210.                break;
  211.             case 3:
  212.                var12 = var10 + (49 + var9 - var10 - var4 + var3) % 7;
  213.                break;
  214.             case 4:
  215.                var12 = var10 - (49 - var9 + var10 + var4 - var3) % 7;
  216.          }
  217.  
  218.          if (var3 < var12) {
  219.             return -1;
  220.          } else if (var3 > var12) {
  221.             return 1;
  222.          } else if (var5 < var11) {
  223.             return -1;
  224.          } else if (var5 > var11) {
  225.             return 1;
  226.          } else {
  227.             return 0;
  228.          }
  229.       }
  230.    }
  231.  
  232.    public int getRawOffset() {
  233.       return this.rawOffset;
  234.    }
  235.  
  236.    public void setRawOffset(int var1) {
  237.       this.rawOffset = var1;
  238.    }
  239.  
  240.    public void setDSTSavings(int var1) {
  241.       if (var1 <= 0) {
  242.          throw new IllegalArgumentException("Illegal DST savings");
  243.       } else {
  244.          this.dstSavings = var1;
  245.       }
  246.    }
  247.  
  248.    public int getDSTSavings() {
  249.       return this.dstSavings;
  250.    }
  251.  
  252.    public boolean useDaylightTime() {
  253.       return this.useDaylight;
  254.    }
  255.  
  256.    public boolean inDaylightTime(Date var1) {
  257.       GregorianCalendar var2 = new GregorianCalendar(this);
  258.       ((Calendar)var2).setTime(var1);
  259.       return var2.inDaylightTime();
  260.    }
  261.  
  262.    public Object clone() {
  263.       return super.clone();
  264.    }
  265.  
  266.    public synchronized int hashCode() {
  267.       return this.startMonth ^ this.startDay ^ this.startDayOfWeek ^ this.startTime ^ this.endMonth ^ this.endDay ^ this.endDayOfWeek ^ this.endTime ^ this.rawOffset;
  268.    }
  269.  
  270.    public boolean equals(Object var1) {
  271.       if (this == var1) {
  272.          return true;
  273.       } else if (!(var1 instanceof SimpleTimeZone)) {
  274.          return false;
  275.       } else {
  276.          SimpleTimeZone var2 = (SimpleTimeZone)var1;
  277.          return ((TimeZone)this).getID().equals(((TimeZone)var2).getID()) && this.hasSameRules(var2);
  278.       }
  279.    }
  280.  
  281.    public boolean hasSameRules(TimeZone var1) {
  282.       if (this == var1) {
  283.          return true;
  284.       } else if (!(var1 instanceof SimpleTimeZone)) {
  285.          return false;
  286.       } else {
  287.          SimpleTimeZone var2 = (SimpleTimeZone)var1;
  288.          return this.rawOffset == var2.rawOffset && this.useDaylight == var2.useDaylight && (!this.useDaylight || this.dstSavings == var2.dstSavings && this.startMode == var2.startMode && this.startMonth == var2.startMonth && this.startDay == var2.startDay && this.startDayOfWeek == var2.startDayOfWeek && this.startTime == var2.startTime && this.startTimeMode == var2.startTimeMode && this.endMode == var2.endMode && this.endMonth == var2.endMonth && this.endDay == var2.endDay && this.endDayOfWeek == var2.endDayOfWeek && this.endTime == var2.endTime && this.endTimeMode == var2.endTimeMode && this.startYear == var2.startYear);
  289.       }
  290.    }
  291.  
  292.    public String toString() {
  293.       return this.getClass().getName() + "[id=" + ((TimeZone)this).getID() + ",offset=" + this.rawOffset + ",dstSavings=" + this.dstSavings + ",useDaylight=" + this.useDaylight + ",startYear=" + this.startYear + ",startMode=" + this.startMode + ",startMonth=" + this.startMonth + ",startDay=" + this.startDay + ",startDayOfWeek=" + this.startDayOfWeek + ",startTime=" + this.startTime + ",startTimeMode=" + this.startTimeMode + ",endMode=" + this.endMode + ",endMonth=" + this.endMonth + ",endDay=" + this.endDay + ",endDayOfWeek=" + this.endDayOfWeek + ",endTime=" + this.endTime + ",endTimeMode=" + this.endTimeMode + ']';
  294.    }
  295.  
  296.    private void decodeRules() {
  297.       this.decodeStartRule();
  298.       this.decodeEndRule();
  299.    }
  300.  
  301.    private void decodeStartRule() {
  302.       this.useDaylight = this.startDay != 0 && this.endDay != 0;
  303.       if (this.startDay != 0) {
  304.          if (this.startMonth < 0 || this.startMonth > 11) {
  305.             throw new IllegalArgumentException("Illegal start month " + this.startMonth);
  306.          }
  307.  
  308.          if (this.startTime < 0 || this.startTime >= 86400000) {
  309.             throw new IllegalArgumentException("Illegal start time " + this.startTime);
  310.          }
  311.  
  312.          if (this.startDayOfWeek == 0) {
  313.             this.startMode = 1;
  314.          } else {
  315.             if (this.startDayOfWeek > 0) {
  316.                this.startMode = 2;
  317.             } else {
  318.                this.startDayOfWeek = -this.startDayOfWeek;
  319.                if (this.startDay > 0) {
  320.                   this.startMode = 3;
  321.                } else {
  322.                   this.startDay = -this.startDay;
  323.                   this.startMode = 4;
  324.                }
  325.             }
  326.  
  327.             if (this.startDayOfWeek > 7) {
  328.                throw new IllegalArgumentException("Illegal start day of week " + this.startDayOfWeek);
  329.             }
  330.          }
  331.  
  332.          if (this.startMode == 2) {
  333.             if (this.startDay < -5 || this.startDay > 5) {
  334.                throw new IllegalArgumentException("Illegal start day of week in month " + this.startDay);
  335.             }
  336.          } else if (this.startDay < 1 || this.startDay > staticMonthLength[this.startMonth]) {
  337.             throw new IllegalArgumentException("Illegal start day " + this.startDay);
  338.          }
  339.       }
  340.  
  341.    }
  342.  
  343.    private void decodeEndRule() {
  344.       this.useDaylight = this.startDay != 0 && this.endDay != 0;
  345.       if (this.endDay != 0) {
  346.          if (this.endMonth < 0 || this.endMonth > 11) {
  347.             throw new IllegalArgumentException("Illegal end month " + this.endMonth);
  348.          }
  349.  
  350.          if (this.endTime < 0 || this.endTime >= 86400000) {
  351.             throw new IllegalArgumentException("Illegal end time " + this.endTime);
  352.          }
  353.  
  354.          if (this.endDayOfWeek == 0) {
  355.             this.endMode = 1;
  356.          } else {
  357.             if (this.endDayOfWeek > 0) {
  358.                this.endMode = 2;
  359.             } else {
  360.                this.endDayOfWeek = -this.endDayOfWeek;
  361.                if (this.endDay > 0) {
  362.                   this.endMode = 3;
  363.                } else {
  364.                   this.endDay = -this.endDay;
  365.                   this.endMode = 4;
  366.                }
  367.             }
  368.  
  369.             if (this.endDayOfWeek > 7) {
  370.                throw new IllegalArgumentException("Illegal end day of week " + this.endDayOfWeek);
  371.             }
  372.          }
  373.  
  374.          if (this.endMode == 2) {
  375.             if (this.endDay < -5 || this.endDay > 5) {
  376.                throw new IllegalArgumentException("Illegal end day of week in month " + this.endDay);
  377.             }
  378.          } else if (this.endDay < 1 || this.endDay > staticMonthLength[this.endMonth]) {
  379.             throw new IllegalArgumentException("Illegal end day " + this.endDay);
  380.          }
  381.       }
  382.  
  383.    }
  384.  
  385.    private void makeRulesCompatible() {
  386.       switch (this.startMode) {
  387.          case 1:
  388.             this.startDay = 1 + this.startDay / 7;
  389.             this.startDayOfWeek = 1;
  390.          case 2:
  391.          default:
  392.             break;
  393.          case 3:
  394.             if (this.startDay != 1) {
  395.                this.startDay = 1 + this.startDay / 7;
  396.             }
  397.             break;
  398.          case 4:
  399.             if (this.startDay >= 30) {
  400.                this.startDay = -1;
  401.             } else {
  402.                this.startDay = 1 + this.startDay / 7;
  403.             }
  404.       }
  405.  
  406.       switch (this.endMode) {
  407.          case 1:
  408.             this.endDay = 1 + this.endDay / 7;
  409.             this.endDayOfWeek = 1;
  410.          case 2:
  411.          default:
  412.             break;
  413.          case 3:
  414.             if (this.endDay != 1) {
  415.                this.endDay = 1 + this.endDay / 7;
  416.             }
  417.             break;
  418.          case 4:
  419.             if (this.endDay >= 30) {
  420.                this.endDay = -1;
  421.             } else {
  422.                this.endDay = 1 + this.endDay / 7;
  423.             }
  424.       }
  425.  
  426.       switch (this.startTimeMode) {
  427.          case 2:
  428.             this.startTime += this.rawOffset;
  429.       }
  430.  
  431.       while(this.startTime < 0) {
  432.          this.startTime += 86400000;
  433.          this.startDayOfWeek = 1 + (this.startDayOfWeek + 5) % 7;
  434.       }
  435.  
  436.       while(this.startTime >= 86400000) {
  437.          this.startTime -= 86400000;
  438.          this.startDayOfWeek = 1 + this.startDayOfWeek % 7;
  439.       }
  440.  
  441.       switch (this.endTimeMode) {
  442.          case 1:
  443.             this.endTime += this.dstSavings;
  444.             break;
  445.          case 2:
  446.             this.endTime += this.rawOffset + this.dstSavings;
  447.       }
  448.  
  449.       while(this.endTime < 0) {
  450.          this.endTime += 86400000;
  451.          this.endDayOfWeek = 1 + (this.endDayOfWeek + 5) % 7;
  452.       }
  453.  
  454.       while(this.endTime >= 86400000) {
  455.          this.endTime -= 86400000;
  456.          this.endDayOfWeek = 1 + this.endDayOfWeek % 7;
  457.       }
  458.  
  459.    }
  460.  
  461.    private byte[] packRules() {
  462.       byte[] var1 = new byte[]{(byte)this.startDay, (byte)this.startDayOfWeek, (byte)this.endDay, (byte)this.endDayOfWeek, (byte)this.startTimeMode, (byte)this.endTimeMode};
  463.       return var1;
  464.    }
  465.  
  466.    private void unpackRules(byte[] var1) {
  467.       this.startDay = var1[0];
  468.       this.startDayOfWeek = var1[1];
  469.       this.endDay = var1[2];
  470.       this.endDayOfWeek = var1[3];
  471.       if (var1.length >= 6) {
  472.          this.startTimeMode = var1[4];
  473.          this.endTimeMode = var1[5];
  474.       }
  475.  
  476.    }
  477.  
  478.    private int[] packTimes() {
  479.       int[] var1 = new int[]{this.startTime, this.endTime};
  480.       return var1;
  481.    }
  482.  
  483.    private void unpackTimes(int[] var1) {
  484.       this.startTime = var1[0];
  485.       this.endTime = var1[1];
  486.    }
  487.  
  488.    private void writeObject(ObjectOutputStream var1) throws IOException {
  489.       byte[] var2 = this.packRules();
  490.       int[] var3 = this.packTimes();
  491.       this.makeRulesCompatible();
  492.       var1.defaultWriteObject();
  493.       var1.writeInt(var2.length);
  494.       var1.write(var2);
  495.       var1.writeObject(var3);
  496.       this.unpackRules(var2);
  497.       this.unpackTimes(var3);
  498.    }
  499.  
  500.    private void readObject(ObjectInputStream var1) throws IOException, ClassNotFoundException {
  501.       var1.defaultReadObject();
  502.       if (this.serialVersionOnStream < 1) {
  503.          if (this.startDayOfWeek == 0) {
  504.             this.startDayOfWeek = 1;
  505.          }
  506.  
  507.          if (this.endDayOfWeek == 0) {
  508.             this.endDayOfWeek = 1;
  509.          }
  510.  
  511.          this.startMode = this.endMode = 2;
  512.          this.dstSavings = 3600000;
  513.       } else {
  514.          int var2 = var1.readInt();
  515.          byte[] var3 = new byte[var2];
  516.          var1.readFully(var3);
  517.          this.unpackRules(var3);
  518.       }
  519.  
  520.       if (this.serialVersionOnStream >= 2) {
  521.          int[] var4 = (int[])var1.readObject();
  522.          this.unpackTimes(var4);
  523.       }
  524.  
  525.       this.serialVersionOnStream = 2;
  526.    }
  527. }
  528.