jdk/make/tools/src/build/tools/javazic/Zoneinfo.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 7782 edfd4b1cd078
child 10110 75674d930b1f
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 7782
diff changeset
     2
 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package build.tools.javazic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.BufferedReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.FileReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.FileNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * Zoneinfo provides javazic compiler front-end functionality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
class Zoneinfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private static final int minYear = 1900;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private static final int maxYear = 2037;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private static final long minTime = Time.getLocalTime(minYear, Month.JANUARY, 1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static int startYear = minYear;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private static int endYear = maxYear;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * True if javazic should generate a list of SimpleTimeZone
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * instances for the SimpleTimeZone-based time zone support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    static boolean isYearForTimeZoneDataSpecified = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * Zone name to Zone mappings
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private Map<String,Zone> zones;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * Rule name to Rule mappings
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private Map<String,Rule> rules;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * Alias name to real name mappings
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private Map<String,String> aliases;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Constracts a Zoneinfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    Zoneinfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        zones = new HashMap<String,Zone>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        rules = new HashMap<String,Rule>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        aliases = new HashMap<String,String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * Adds the given zone to the list of Zones.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @param zone Zone to be added to the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    void add(Zone zone) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        String name = zone.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        zones.put(name, zone);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Adds the given rule to the list of Rules.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @param rule Rule to be added to the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    void add(Rule rule) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        String name = rule.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        rules.put(name, rule);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Puts the specifid name pair to the alias table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @param name1 an alias time zone name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @param name2 the real time zone of the alias name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    void putAlias(String name1, String name2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        aliases.put(name1, name2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * Sets the given year for SimpleTimeZone list output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * This method is called when the -S option is specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @param year the year for which SimpleTimeZone list should be generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    static void setYear(int year) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        setStartYear(year);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        setEndYear(year);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        isYearForTimeZoneDataSpecified = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Sets the start year.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @param year the start year value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @throws IllegalArgumentException if the specified year value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * smaller than the minimum year or greater than the end year.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    static void setStartYear(int year) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        if (year < minYear || year > endYear) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            throw new IllegalArgumentException("invalid start year specified: " + year);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        startYear = year;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @return the start year value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    static int getStartYear() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        return startYear;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Sets the end year.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @param year the end year value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @throws IllegalArgumentException if the specified year value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * smaller than the start year or greater than the maximum year.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    static void setEndYear(int year) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        if (year < startYear || year > maxYear) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        endYear = year;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @return the end year value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    static int getEndYear() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        return endYear;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @return the minimum year value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    static int getMinYear() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        return minYear;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * @return the maximum year value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    static int getMaxYear() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        return maxYear;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @return the alias table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    Map<String,String> getAliases() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        return aliases;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @return the Zone list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    Map<String,Zone> getZones() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        return zones;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @return a Zone specified by name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @param name a zone name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    Zone getZone(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return zones.get(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @return a Rule specified by name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @param name a rule name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    Rule getRule(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        return rules.get(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    private static String line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    private static int lineNum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * Parses the specified time zone data file and creates a Zoneinfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * that has all Rules, Zones and Links (aliases) information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @param fname the time zone data file name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @return a Zoneinfo object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    static Zoneinfo parse(String fname) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        BufferedReader in = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            FileReader fr = new FileReader(fname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            in = new BufferedReader(fr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        } catch (FileNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            panic("can't open file: "+fname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        Zoneinfo zi = new Zoneinfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        boolean continued = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        Zone zone = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        String l;
7782
edfd4b1cd078 7007905: javazic produces wrong line numbers
okutsu
parents: 5506
diff changeset
   225
        lineNum = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            while ((line = in.readLine()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                lineNum++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                // skip blank and comment lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                if (line.length() == 0 || line.charAt(0) == '#') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                // trim trailing comments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                int rindex = line.lastIndexOf('#');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                if (rindex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    // take the data part of the line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    l = line.substring(0, rindex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    l = line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                StringTokenizer tokens = new StringTokenizer(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                if (!tokens.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                String token = tokens.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                if (continued || "Zone".equals(token)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                    if (zone == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                        if (!tokens.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                            panic("syntax error: zone no more token");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                        token = tokens.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                        // if the zone name is in "GMT+hh" or "GMT-hh"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                        // format, ignore it due to spec conflict.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                        if (token.startsWith("GMT+") || token.startsWith("GMT-")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                        zone = new Zone(token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                        // no way to push the current token back...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                        tokens = new StringTokenizer(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                    ZoneRec zrec = ZoneRec.parse(tokens);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                    zrec.setLine(line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                    zone.add(zrec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                    if ((continued = zrec.hasUntil()) == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                        if (Zone.isTargetZone(zone.getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                            // zone.resolve(zi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                            zi.add(zone);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                        zone = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                } else if ("Rule".equals(token)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                    if (!tokens.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                        panic("syntax error: rule no more token");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                    token = tokens.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                    Rule rule = zi.getRule(token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                    if (rule == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                        rule = new Rule(token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                        zi.add(rule);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                    RuleRec rrec = RuleRec.parse(tokens);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                    rrec.setLine(line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                    rule.add(rrec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                } else if ("Link".equals(token)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                    // Link <newname> <oldname>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                        String name1 = tokens.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                        String name2 = tokens.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                        // if the zone name is in "GMT+hh" or "GMT-hh"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                        // format, ignore it due to spec conflict with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                        // custom time zones. Also, ignore "ROC" for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                        // PC-ness.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                        if (name2.startsWith("GMT+") || name2.startsWith("GMT-")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                            || "ROC".equals(name2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                        zi.putAlias(name2, name1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                    } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                        panic("syntax error: no more token for Link");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            in.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        } catch (IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            panic("IO error: " + ex.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        return zi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * Interprets a zone and constructs a Timezone object that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * contains enough information on GMT offsets and DST schedules to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * generate a zone info database.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @param zoneName the zone name for which a Timezone object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * constructed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * @return a Timezone object that contains all GMT offsets and DST
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * rules information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    Timezone phase2(String zoneName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        Timezone tz = new Timezone(zoneName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        Zone zone = getZone(zoneName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        zone.resolve(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        // TODO: merge phase2's for the regular and SimpleTimeZone ones.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        if (isYearForTimeZoneDataSpecified) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            ZoneRec zrec = zone.get(zone.size()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            tz.setLastZoneRec(zrec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            tz.setRawOffset(zrec.getGmtOffset());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            if (zrec.hasRuleReference()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                 * This part assumes that the specified year is covered by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                 * the rules referred to by the last zone record.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                List<RuleRec> rrecs = zrec.getRuleRef().getRules(startYear);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                if (rrecs.size() == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                    // make sure that one is a start rule and the other is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                    // an end rule.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                    RuleRec r0 = rrecs.get(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                    RuleRec r1 = rrecs.get(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                    if (r0.getSave() == 0 && r1.getSave() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                        rrecs.set(0, r1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                        rrecs.set(1, r0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                    } else if (!(r0.getSave() > 0 && r1.getSave() == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                        rrecs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                        Main.error(zoneName + ": rules for " +  startYear + " not found.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                    rrecs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                if (rrecs != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                    tz.setLastRules(rrecs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            return tz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        int gmtOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        int year = minYear;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        int fromYear = year;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        long fromTime = Time.getLocalTime(startYear,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                                          Month.JANUARY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                                          1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        // take the index 0 for the GMT offset of the last zone record
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        ZoneRec zrec = zone.get(zone.size()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        tz.getOffsetIndex(zrec.getGmtOffset());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        int currentSave = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        boolean usedZone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        for (int zindex = 0; zindex < zone.size(); zindex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            zrec = zone.get(zindex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            usedZone = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            gmtOffset = zrec.getGmtOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            int stdOffset = zrec.getDirectSave();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            // If this is the last zone record, take the last rule info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            if (!zrec.hasUntil()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                tz.setRawOffset(gmtOffset, fromTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                if (zrec.hasRuleReference()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                    tz.setLastRules(zrec.getRuleRef().getLastRules());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                } else if (stdOffset != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                    // in case the last rule is all year round DST-only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                    // (Asia/Amman once announced this rule.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                    tz.setLastDSTSaving(stdOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            if (!zrec.hasRuleReference()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                if (!zrec.hasUntil() || zrec.getUntilTime(stdOffset) >= fromTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                    tz.addTransition(fromTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                                     tz.getOffsetIndex(gmtOffset+stdOffset),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                                     tz.getDstOffsetIndex(stdOffset));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                    usedZone = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                currentSave = stdOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                // optimization in case the last rule is fixed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                if (!zrec.hasUntil()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                    if (tz.getNTransitions() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                        if (stdOffset == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                            tz.setDSTType(tz.X_DST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                            tz.setDSTType(tz.LAST_DST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                        long time = Time.getLocalTime(maxYear,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                                                      Month.JANUARY, 1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                        time -= zrec.getGmtOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                        tz.addTransition(time,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                                         tz.getOffsetIndex(gmtOffset+stdOffset),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                                         tz.getDstOffsetIndex(stdOffset));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                        tz.addUsedRec(zrec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                        tz.setDSTType(tz.NO_DST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                Rule rule = zrec.getRuleRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                boolean fromTimeUsed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                currentSave = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            year_loop:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                for (year = getMinYear(); year <= endYear; year++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                    if (zrec.hasUntil() && year > zrec.getUntilYear()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                    List<RuleRec> rules = rule.getRules(year);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                    if (rules.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                        for (int i = 0; i < rules.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                            RuleRec rrec = rules.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                            long transition = rrec.getTransitionTime(year,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                                                                     gmtOffset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                                                                     currentSave);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                            if (zrec.hasUntil()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                                if (transition >= zrec.getUntilTime(currentSave)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                                    break year_loop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                            if (fromTimeUsed == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                                if (fromTime <= transition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                                    fromTimeUsed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                                    if (fromTime != minTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                                        int prevsave;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                                        ZoneRec prevzrec = zone.get(zindex - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                                        // See if until time in the previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                                        // ZoneRec is the same thing as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                                        // local time in the next rule.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                                        // (examples are Asia/Ashkhabad in 1991,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                                        // Europe/Riga in 1989)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                                        if (i > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                                            prevsave = rules.get(i-1).getSave();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                                            List<RuleRec> prevrules = rule.getRules(year-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                                            if (prevrules.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                                                prevsave = prevrules.get(prevrules.size()-1).getSave();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                                                prevsave = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                                        if (rrec.isSameTransition(prevzrec, prevsave, gmtOffset)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                                            currentSave = rrec.getSave();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                                            tz.addTransition(fromTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                                                         tz.getOffsetIndex(gmtOffset+currentSave),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                                                         tz.getDstOffsetIndex(currentSave));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                                            tz.addUsedRec(rrec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                                            usedZone = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                                            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                                        if (!prevzrec.hasRuleReference()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                                            || rule != prevzrec.getRuleRef()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                                            || (rule == prevzrec.getRuleRef()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                                                && gmtOffset != prevzrec.getGmtOffset())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                                            int save = (fromTime == transition) ? rrec.getSave() : currentSave;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                                            tz.addTransition(fromTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                                                         tz.getOffsetIndex(gmtOffset+save),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                                                         tz.getDstOffsetIndex(save));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                                            tz.addUsedRec(rrec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                                            usedZone = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                                        int save = rrec.getSave();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                                        tz.addTransition(fromTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                                                         tz.getOffsetIndex(gmtOffset+save),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                                                         tz.getDstOffsetIndex(save));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                                        tz.addUsedRec(rrec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                                        usedZone = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                                } else if (year == fromYear && i == rules.size()-1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                                    int save = rrec.getSave();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                                    tz.addTransition(fromTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                                                     tz.getOffsetIndex(gmtOffset+save),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                                                     tz.getDstOffsetIndex(save));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                            currentSave = rrec.getSave();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                            if (fromTime < transition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                                tz.addTransition(transition,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                                                 tz.getOffsetIndex(gmtOffset+currentSave),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                                                 tz.getDstOffsetIndex(currentSave));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                                tz.addUsedRec(rrec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                                usedZone = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                        if (year == fromYear) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                            tz.addTransition(fromTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                                             tz.getOffsetIndex(gmtOffset+currentSave),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                                             tz.getDstOffsetIndex(currentSave));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                            fromTimeUsed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                        if (year == endYear && !zrec.hasUntil()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                            if (tz.getNTransitions() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                                // Assume that this Zone stopped DST
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                                tz.setDSTType(tz.X_DST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                                long time = Time.getLocalTime(maxYear, Month.JANUARY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                                                              1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                                time -= zrec.getGmtOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                                tz.addTransition(time,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                                                 tz.getOffsetIndex(gmtOffset),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                                                 tz.getDstOffsetIndex(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                                usedZone = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                                tz.setDSTType(tz.NO_DST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            if (usedZone) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                tz.addUsedRec(zrec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            if (zrec.hasUntil() && zrec.getUntilTime(currentSave) > fromTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                fromTime = zrec.getUntilTime(currentSave);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                fromYear = zrec.getUntilYear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                year = zrec.getUntilYear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        if (tz.getDSTType() == tz.UNDEF_DST) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            tz.setDSTType(tz.DST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        tz.optimize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        tz.checksum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        return tz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    private static void panic(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        Main.panic(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
}