author | mcimadamore |
Mon, 07 Nov 2016 11:16:23 +0000 | |
changeset 41942 | 260c724e5614 |
parent 35302 | e4d2275861c3 |
permissions | -rw-r--r-- |
25158
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
1 |
/* |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
4 |
* |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
10 |
* |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
15 |
* accompanied this code). |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
16 |
* |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
20 |
* |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
23 |
* questions. |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
24 |
*/ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
25 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
26 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
27 |
package build.tools.tzdb; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
28 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
29 |
import java.io.IOException; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
30 |
import java.nio.charset.StandardCharsets; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
31 |
import java.nio.file.Files; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
32 |
import java.nio.file.Path; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
33 |
import java.nio.file.Paths; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
34 |
import java.util.ArrayList; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
35 |
import java.util.Collections; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
36 |
import java.util.HashMap; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
37 |
import java.util.HashSet; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
38 |
import java.util.List; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
39 |
import java.util.Map; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
40 |
import java.util.Map.Entry; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
41 |
import java.util.NavigableMap; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
42 |
import java.util.Objects; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
43 |
import java.util.Set; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
44 |
import java.util.TreeMap; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
45 |
import java.util.TreeSet; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
46 |
import java.util.concurrent.ConcurrentHashMap; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
47 |
import java.time.*; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
48 |
import java.time.Year; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
49 |
import java.time.chrono.IsoChronology; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
50 |
import java.time.temporal.TemporalAdjusters; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
51 |
import java.time.zone.ZoneOffsetTransition; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
52 |
import java.time.zone.ZoneOffsetTransitionRule; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
53 |
import java.time.zone.ZoneOffsetTransitionRule.TimeDefinition; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
54 |
import java.time.zone.ZoneRulesException; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
55 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
56 |
/** |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
57 |
* Compile and build time-zone rules from IANA timezone data |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
58 |
* |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
59 |
* @author Xueming Shen |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
60 |
* @author Stephen Colebourne |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
61 |
* @author Michael Nascimento Santos |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
62 |
* |
35302
e4d2275861c3
8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents:
28094
diff
changeset
|
63 |
* @since 9 |
25158
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
64 |
*/ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
65 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
66 |
class TzdbZoneRulesProvider { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
67 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
68 |
/** |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
69 |
* Creates an instance. |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
70 |
* |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
71 |
* @throws ZoneRulesException if unable to load |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
72 |
*/ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
73 |
public TzdbZoneRulesProvider(List<Path> files) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
74 |
try { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
75 |
load(files); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
76 |
} catch (Exception ex) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
77 |
throw new ZoneRulesException("Unable to load TZDB time-zone rules", ex); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
78 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
79 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
80 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
81 |
public Set<String> getZoneIds() { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
82 |
return new TreeSet(regionIds); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
83 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
84 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
85 |
public Map<String, String> getAliasMap() { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
86 |
return links; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
87 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
88 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
89 |
public ZoneRules getZoneRules(String zoneId) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
90 |
Object obj = zones.get(zoneId); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
91 |
if (obj == null) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
92 |
String zoneId0 = zoneId; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
93 |
if (links.containsKey(zoneId)) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
94 |
zoneId = links.get(zoneId); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
95 |
obj = zones.get(zoneId); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
96 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
97 |
if (obj == null) { |
27726
34021e900889
8064914: tzdb.dat compilation failure when using tzdata2014j
aefimov
parents:
25158
diff
changeset
|
98 |
// Timezone link can be located in 'backward' file and it |
34021e900889
8064914: tzdb.dat compilation failure when using tzdata2014j
aefimov
parents:
25158
diff
changeset
|
99 |
// can refer to another link, so we need to check for |
34021e900889
8064914: tzdb.dat compilation failure when using tzdata2014j
aefimov
parents:
25158
diff
changeset
|
100 |
// link one more time, before throwing an exception |
34021e900889
8064914: tzdb.dat compilation failure when using tzdata2014j
aefimov
parents:
25158
diff
changeset
|
101 |
String zoneIdBack = zoneId; |
34021e900889
8064914: tzdb.dat compilation failure when using tzdata2014j
aefimov
parents:
25158
diff
changeset
|
102 |
if (links.containsKey(zoneId)) { |
34021e900889
8064914: tzdb.dat compilation failure when using tzdata2014j
aefimov
parents:
25158
diff
changeset
|
103 |
zoneId = links.get(zoneId); |
34021e900889
8064914: tzdb.dat compilation failure when using tzdata2014j
aefimov
parents:
25158
diff
changeset
|
104 |
obj = zones.get(zoneId); |
34021e900889
8064914: tzdb.dat compilation failure when using tzdata2014j
aefimov
parents:
25158
diff
changeset
|
105 |
} |
34021e900889
8064914: tzdb.dat compilation failure when using tzdata2014j
aefimov
parents:
25158
diff
changeset
|
106 |
if (obj == null) { |
34021e900889
8064914: tzdb.dat compilation failure when using tzdata2014j
aefimov
parents:
25158
diff
changeset
|
107 |
throw new ZoneRulesException("Unknown time-zone ID: " + zoneIdBack); |
34021e900889
8064914: tzdb.dat compilation failure when using tzdata2014j
aefimov
parents:
25158
diff
changeset
|
108 |
} |
25158
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
109 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
110 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
111 |
if (obj instanceof ZoneRules) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
112 |
return (ZoneRules)obj; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
113 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
114 |
try { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
115 |
ZoneRules zrules = buildRules(zoneId, (List<ZoneLine>)obj); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
116 |
zones.put(zoneId, zrules); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
117 |
return zrules; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
118 |
} catch (Exception ex) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
119 |
throw new ZoneRulesException( |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
120 |
"Invalid binary time-zone data: TZDB:" + zoneId, ex); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
121 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
122 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
123 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
124 |
////////////////////////////////////////////////////////////////////// |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
125 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
126 |
/** |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
127 |
* All the regions that are available. |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
128 |
*/ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
129 |
private List<String> regionIds = new ArrayList<>(600); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
130 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
131 |
/** |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
132 |
* Zone region to rules mapping |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
133 |
*/ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
134 |
private final Map<String, Object> zones = new ConcurrentHashMap<>(); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
135 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
136 |
/** |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
137 |
* compatibility list |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
138 |
*/ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
139 |
private static HashSet<String> excludedZones; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
140 |
static { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
141 |
// (1) exclude EST, HST and MST. They are supported |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
142 |
// via the short-id mapping |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
143 |
// (2) remove UTC and GMT |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
144 |
// (3) remove ROC, which is not supported in j.u.tz |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
145 |
excludedZones = new HashSet<>(10); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
146 |
excludedZones.add("EST"); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
147 |
excludedZones.add("HST"); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
148 |
excludedZones.add("MST"); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
149 |
excludedZones.add("GMT+0"); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
150 |
excludedZones.add("GMT-0"); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
151 |
excludedZones.add("ROC"); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
152 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
153 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
154 |
private Map<String, String> links = new HashMap<>(150); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
155 |
private Map<String, List<RuleLine>> rules = new HashMap<>(500); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
156 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
157 |
private void load(List<Path> files) throws IOException { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
158 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
159 |
for (Path file : files) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
160 |
List<ZoneLine> openZone = null; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
161 |
try { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
162 |
for (String line : Files.readAllLines(file, StandardCharsets.ISO_8859_1)) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
163 |
if (line.length() == 0 || line.charAt(0) == '#') { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
164 |
continue; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
165 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
166 |
//StringIterator itr = new StringIterator(line); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
167 |
String[] tokens = split(line); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
168 |
if (openZone != null && // continuing zone line |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
169 |
Character.isWhitespace(line.charAt(0)) && |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
170 |
tokens.length > 0) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
171 |
ZoneLine zLine = new ZoneLine(); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
172 |
openZone.add(zLine); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
173 |
if (zLine.parse(tokens, 0)) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
174 |
openZone = null; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
175 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
176 |
continue; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
177 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
178 |
if (line.startsWith("Zone")) { // parse Zone line |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
179 |
String name = tokens[1]; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
180 |
if (excludedZones.contains(name)){ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
181 |
continue; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
182 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
183 |
if (zones.containsKey(name)) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
184 |
throw new IllegalArgumentException( |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
185 |
"Duplicated zone name in file: " + name + |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
186 |
", line: [" + line + "]"); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
187 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
188 |
openZone = new ArrayList<>(10); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
189 |
zones.put(name, openZone); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
190 |
regionIds.add(name); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
191 |
ZoneLine zLine = new ZoneLine(); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
192 |
openZone.add(zLine); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
193 |
if (zLine.parse(tokens, 2)) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
194 |
openZone = null; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
195 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
196 |
} else if (line.startsWith("Rule")) { // parse Rule line |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
197 |
String name = tokens[1]; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
198 |
if (!rules.containsKey(name)) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
199 |
rules.put(name, new ArrayList<RuleLine>(10)); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
200 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
201 |
rules.get(name).add(new RuleLine().parse(tokens)); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
202 |
} else if (line.startsWith("Link")) { // parse link line |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
203 |
if (tokens.length >= 3) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
204 |
String realId = tokens[1]; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
205 |
String aliasId = tokens[2]; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
206 |
if (excludedZones.contains(aliasId)){ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
207 |
continue; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
208 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
209 |
links.put(aliasId, realId); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
210 |
regionIds.add(aliasId); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
211 |
} else { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
212 |
throw new IllegalArgumentException( |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
213 |
"Invalid Link line in file" + |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
214 |
file + ", line: [" + line + "]"); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
215 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
216 |
} else { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
217 |
// skip unknown line |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
218 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
219 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
220 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
221 |
} catch (Exception ex) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
222 |
throw new RuntimeException("Failed while processing file [" + file + |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
223 |
"]", ex); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
224 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
225 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
226 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
227 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
228 |
private String[] split(String str) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
229 |
int off = 0; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
230 |
int end = str.length(); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
231 |
ArrayList<String> list = new ArrayList<>(10); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
232 |
while (off < end) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
233 |
char c = str.charAt(off); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
234 |
if (c == '\t' || c == ' ') { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
235 |
off++; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
236 |
continue; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
237 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
238 |
if (c == '#') { // comment |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
239 |
break; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
240 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
241 |
int start = off; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
242 |
while (off < end) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
243 |
c = str.charAt(off); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
244 |
if (c == ' ' || c == '\t') { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
245 |
break; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
246 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
247 |
off++; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
248 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
249 |
if (start != off) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
250 |
list.add(str.substring(start, off)); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
251 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
252 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
253 |
return list.toArray(new String[list.size()]); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
254 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
255 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
256 |
/** |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
257 |
* Class representing a month-day-time in the TZDB file. |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
258 |
*/ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
259 |
private static abstract class MonthDayTime { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
260 |
/** The month of the cutover. */ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
261 |
Month month = Month.JANUARY; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
262 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
263 |
/** The day-of-month of the cutover. */ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
264 |
int dayOfMonth = 1; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
265 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
266 |
/** Whether to adjust forwards. */ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
267 |
boolean adjustForwards = true; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
268 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
269 |
/** The day-of-week of the cutover. */ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
270 |
DayOfWeek dayOfWeek; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
271 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
272 |
/** The time of the cutover, in second of day */ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
273 |
int secsOfDay = 0; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
274 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
275 |
/** Whether this is midnight end of day. */ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
276 |
boolean endOfDay; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
277 |
/** The time of the cutover. */ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
278 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
279 |
TimeDefinition timeDefinition = TimeDefinition.WALL; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
280 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
281 |
void adjustToForwards(int year) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
282 |
if (adjustForwards == false && dayOfMonth > 0) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
283 |
// weekDay<=monthDay case, don't have it in tzdb data for now |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
284 |
LocalDate adjustedDate = LocalDate.of(year, month, dayOfMonth).minusDays(6); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
285 |
dayOfMonth = adjustedDate.getDayOfMonth(); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
286 |
month = adjustedDate.getMonth(); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
287 |
adjustForwards = true; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
288 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
289 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
290 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
291 |
LocalDateTime toDateTime(int year) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
292 |
LocalDate date; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
293 |
if (dayOfMonth < 0) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
294 |
int monthLen = month.length(IsoChronology.INSTANCE.isLeapYear(year)); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
295 |
date = LocalDate.of(year, month, monthLen + 1 + dayOfMonth); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
296 |
if (dayOfWeek != null) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
297 |
date = date.with(TemporalAdjusters.previousOrSame(dayOfWeek)); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
298 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
299 |
} else { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
300 |
date = LocalDate.of(year, month, dayOfMonth); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
301 |
if (dayOfWeek != null) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
302 |
date = date.with(TemporalAdjusters.nextOrSame(dayOfWeek)); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
303 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
304 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
305 |
if (endOfDay) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
306 |
date = date.plusDays(1); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
307 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
308 |
return LocalDateTime.of(date, LocalTime.ofSecondOfDay(secsOfDay)); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
309 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
310 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
311 |
/** |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
312 |
* Parses the MonthDaytime segment of a tzdb line. |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
313 |
*/ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
314 |
private void parse(String[] tokens, int off) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
315 |
month = parseMonth(tokens[off++]); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
316 |
if (off < tokens.length) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
317 |
String dayRule = tokens[off++]; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
318 |
if (dayRule.startsWith("last")) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
319 |
dayOfMonth = -1; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
320 |
dayOfWeek = parseDayOfWeek(dayRule.substring(4)); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
321 |
adjustForwards = false; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
322 |
} else { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
323 |
int index = dayRule.indexOf(">="); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
324 |
if (index > 0) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
325 |
dayOfWeek = parseDayOfWeek(dayRule.substring(0, index)); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
326 |
dayRule = dayRule.substring(index + 2); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
327 |
} else { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
328 |
index = dayRule.indexOf("<="); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
329 |
if (index > 0) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
330 |
dayOfWeek = parseDayOfWeek(dayRule.substring(0, index)); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
331 |
adjustForwards = false; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
332 |
dayRule = dayRule.substring(index + 2); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
333 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
334 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
335 |
dayOfMonth = Integer.parseInt(dayRule); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
336 |
if (dayOfMonth < -28 || dayOfMonth > 31 || dayOfMonth == 0) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
337 |
throw new IllegalArgumentException( |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
338 |
"Day of month indicator must be between -28 and 31 inclusive excluding zero"); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
339 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
340 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
341 |
if (off < tokens.length) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
342 |
String timeStr = tokens[off++]; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
343 |
secsOfDay = parseSecs(timeStr); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
344 |
if (secsOfDay == 86400) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
345 |
// time must be midnight when end of day flag is true |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
346 |
endOfDay = true; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
347 |
secsOfDay = 0; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
348 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
349 |
timeDefinition = parseTimeDefinition(timeStr.charAt(timeStr.length() - 1)); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
350 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
351 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
352 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
353 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
354 |
int parseYear(String year, int defaultYear) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
355 |
switch (year.toLowerCase()) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
356 |
case "min": return 1900; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
357 |
case "max": return Year.MAX_VALUE; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
358 |
case "only": return defaultYear; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
359 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
360 |
return Integer.parseInt(year); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
361 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
362 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
363 |
Month parseMonth(String mon) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
364 |
switch (mon) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
365 |
case "Jan": return Month.JANUARY; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
366 |
case "Feb": return Month.FEBRUARY; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
367 |
case "Mar": return Month.MARCH; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
368 |
case "Apr": return Month.APRIL; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
369 |
case "May": return Month.MAY; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
370 |
case "Jun": return Month.JUNE; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
371 |
case "Jul": return Month.JULY; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
372 |
case "Aug": return Month.AUGUST; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
373 |
case "Sep": return Month.SEPTEMBER; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
374 |
case "Oct": return Month.OCTOBER; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
375 |
case "Nov": return Month.NOVEMBER; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
376 |
case "Dec": return Month.DECEMBER; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
377 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
378 |
throw new IllegalArgumentException("Unknown month: " + mon); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
379 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
380 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
381 |
DayOfWeek parseDayOfWeek(String dow) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
382 |
switch (dow) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
383 |
case "Mon": return DayOfWeek.MONDAY; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
384 |
case "Tue": return DayOfWeek.TUESDAY; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
385 |
case "Wed": return DayOfWeek.WEDNESDAY; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
386 |
case "Thu": return DayOfWeek.THURSDAY; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
387 |
case "Fri": return DayOfWeek.FRIDAY; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
388 |
case "Sat": return DayOfWeek.SATURDAY; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
389 |
case "Sun": return DayOfWeek.SUNDAY; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
390 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
391 |
throw new IllegalArgumentException("Unknown day-of-week: " + dow); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
392 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
393 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
394 |
String parseOptional(String str) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
395 |
return str.equals("-") ? null : str; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
396 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
397 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
398 |
static final boolean isDigit(char c) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
399 |
return c >= '0' && c <= '9'; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
400 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
401 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
402 |
private int parseSecs(String time) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
403 |
if (time.equals("-")) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
404 |
return 0; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
405 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
406 |
// faster hack |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
407 |
int secs = 0; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
408 |
int sign = 1; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
409 |
int off = 0; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
410 |
int len = time.length(); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
411 |
if (off < len && time.charAt(off) == '-') { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
412 |
sign = -1; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
413 |
off++; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
414 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
415 |
char c0, c1; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
416 |
if (off < len && isDigit(c0 = time.charAt(off++))) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
417 |
int hour = c0 - '0'; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
418 |
if (off < len && isDigit(c1 = time.charAt(off))) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
419 |
hour = hour * 10 + c1 - '0'; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
420 |
off++; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
421 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
422 |
secs = hour * 60 * 60; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
423 |
if (off < len && time.charAt(off++) == ':') { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
424 |
if (off + 1 < len && |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
425 |
isDigit(c0 = time.charAt(off++)) && |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
426 |
isDigit(c1 = time.charAt(off++))) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
427 |
// minutes |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
428 |
secs += ((c0 - '0') * 10 + c1 - '0') * 60; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
429 |
if (off < len && time.charAt(off++) == ':') { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
430 |
if (off + 1 < len && |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
431 |
isDigit(c0 = time.charAt(off++)) && |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
432 |
isDigit(c1 = time.charAt(off++))) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
433 |
// seconds |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
434 |
secs += ((c0 - '0') * 10 + c1 - '0'); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
435 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
436 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
437 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
438 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
439 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
440 |
return secs * sign; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
441 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
442 |
throw new IllegalArgumentException("[" + time + "]"); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
443 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
444 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
445 |
int parseOffset(String str) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
446 |
int secs = parseSecs(str); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
447 |
if (Math.abs(secs) > 18 * 60 * 60) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
448 |
throw new IllegalArgumentException( |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
449 |
"Zone offset not in valid range: -18:00 to +18:00"); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
450 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
451 |
return secs; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
452 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
453 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
454 |
int parsePeriod(String str) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
455 |
return parseSecs(str); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
456 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
457 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
458 |
TimeDefinition parseTimeDefinition(char c) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
459 |
switch (c) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
460 |
case 's': |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
461 |
case 'S': |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
462 |
// standard time |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
463 |
return TimeDefinition.STANDARD; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
464 |
case 'u': |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
465 |
case 'U': |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
466 |
case 'g': |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
467 |
case 'G': |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
468 |
case 'z': |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
469 |
case 'Z': |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
470 |
// UTC |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
471 |
return TimeDefinition.UTC; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
472 |
case 'w': |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
473 |
case 'W': |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
474 |
default: |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
475 |
// wall time |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
476 |
return TimeDefinition.WALL; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
477 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
478 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
479 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
480 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
481 |
/** |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
482 |
* Class representing a rule line in the TZDB file. |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
483 |
*/ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
484 |
private static class RuleLine extends MonthDayTime { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
485 |
/** The start year. */ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
486 |
int startYear; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
487 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
488 |
/** The end year. */ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
489 |
int endYear; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
490 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
491 |
/** The amount of savings, in seconds. */ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
492 |
int savingsAmount; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
493 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
494 |
/** The text name of the zone. */ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
495 |
String text; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
496 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
497 |
/** |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
498 |
* Converts this to a transition rule. |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
499 |
* |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
500 |
* @param standardOffset the active standard offset, not null |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
501 |
* @param savingsBeforeSecs the active savings before the transition in seconds |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
502 |
* @return the transition, not null |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
503 |
*/ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
504 |
ZoneOffsetTransitionRule toTransitionRule(ZoneOffset stdOffset, int savingsBefore) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
505 |
// rule shared by different zones, so don't change it |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
506 |
Month month = this.month; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
507 |
int dayOfMonth = this.dayOfMonth; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
508 |
DayOfWeek dayOfWeek = this.dayOfWeek; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
509 |
boolean endOfDay = this.endOfDay; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
510 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
511 |
// optimize stored format |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
512 |
if (dayOfMonth < 0) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
513 |
if (month != Month.FEBRUARY) { // not Month.FEBRUARY |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
514 |
dayOfMonth = month.maxLength() - 6; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
515 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
516 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
517 |
if (endOfDay && dayOfMonth > 0 && |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
518 |
(dayOfMonth == 28 && month == Month.FEBRUARY) == false) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
519 |
LocalDate date = LocalDate.of(2004, month, dayOfMonth).plusDays(1); // leap-year |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
520 |
month = date.getMonth(); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
521 |
dayOfMonth = date.getDayOfMonth(); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
522 |
if (dayOfWeek != null) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
523 |
dayOfWeek = dayOfWeek.plus(1); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
524 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
525 |
endOfDay = false; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
526 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
527 |
// build rule |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
528 |
return ZoneOffsetTransitionRule.of( |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
529 |
//month, dayOfMonth, dayOfWeek, time, endOfDay, timeDefinition, |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
530 |
month, dayOfMonth, dayOfWeek, |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
531 |
LocalTime.ofSecondOfDay(secsOfDay), endOfDay, timeDefinition, |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
532 |
stdOffset, |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
533 |
ZoneOffset.ofTotalSeconds(stdOffset.getTotalSeconds() + savingsBefore), |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
534 |
ZoneOffset.ofTotalSeconds(stdOffset.getTotalSeconds() + savingsAmount)); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
535 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
536 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
537 |
RuleLine parse(String[] tokens) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
538 |
startYear = parseYear(tokens[2], 0); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
539 |
endYear = parseYear(tokens[3], startYear); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
540 |
if (startYear > endYear) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
541 |
throw new IllegalArgumentException( |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
542 |
"Invalid <Rule> line/Year order invalid:" + startYear + " > " + endYear); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
543 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
544 |
//parseOptional(s.next()); // type is unused |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
545 |
super.parse(tokens, 5); // monthdaytime parsing |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
546 |
savingsAmount = parsePeriod(tokens[8]); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
547 |
//rule.text = parseOptional(s.next()); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
548 |
return this; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
549 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
550 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
551 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
552 |
/** |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
553 |
* Class representing a linked set of zone lines in the TZDB file. |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
554 |
*/ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
555 |
private static class ZoneLine extends MonthDayTime { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
556 |
/** The standard offset. */ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
557 |
int stdOffsetSecs; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
558 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
559 |
/** The fixed savings amount. */ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
560 |
int fixedSavingsSecs = 0; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
561 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
562 |
/** The savings rule. */ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
563 |
String savingsRule; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
564 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
565 |
/** The text name of the zone. */ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
566 |
String text; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
567 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
568 |
/** The cutover year */ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
569 |
int year = Year.MAX_VALUE; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
570 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
571 |
/** The cutover date time */ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
572 |
LocalDateTime ldt; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
573 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
574 |
/** The cutover date/time in epoch seconds/UTC */ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
575 |
long ldtSecs = Long.MIN_VALUE; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
576 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
577 |
LocalDateTime toDateTime() { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
578 |
if (ldt == null) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
579 |
ldt = toDateTime(year); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
580 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
581 |
return ldt; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
582 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
583 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
584 |
/** |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
585 |
* Creates the date-time epoch second in the wall offset for the local |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
586 |
* date-time at the end of the window. |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
587 |
* |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
588 |
* @param savingsSecs the amount of savings in use in seconds |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
589 |
* @return the created date-time epoch second in the wall offset, not null |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
590 |
*/ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
591 |
long toDateTimeEpochSecond(int savingsSecs) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
592 |
if (ldtSecs == Long.MIN_VALUE) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
593 |
ldtSecs = toDateTime().toEpochSecond(ZoneOffset.UTC); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
594 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
595 |
switch(timeDefinition) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
596 |
case UTC: return ldtSecs; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
597 |
case STANDARD: return ldtSecs - stdOffsetSecs; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
598 |
default: return ldtSecs - (stdOffsetSecs + savingsSecs); // WALL |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
599 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
600 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
601 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
602 |
boolean parse(String[] tokens, int off) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
603 |
stdOffsetSecs = parseOffset(tokens[off++]); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
604 |
savingsRule = parseOptional(tokens[off++]); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
605 |
if (savingsRule != null && savingsRule.length() > 0 && |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
606 |
(savingsRule.charAt(0) == '-' || isDigit(savingsRule.charAt(0)))) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
607 |
try { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
608 |
fixedSavingsSecs = parsePeriod(savingsRule); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
609 |
savingsRule = null; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
610 |
} catch (Exception ex) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
611 |
fixedSavingsSecs = 0; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
612 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
613 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
614 |
text = tokens[off++]; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
615 |
if (off < tokens.length) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
616 |
year = Integer.parseInt(tokens[off++]); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
617 |
if (off < tokens.length) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
618 |
super.parse(tokens, off); // MonthDayTime |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
619 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
620 |
return false; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
621 |
} else { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
622 |
return true; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
623 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
624 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
625 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
626 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
627 |
/** |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
628 |
* Class representing a rule line in the TZDB file for a particular year. |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
629 |
*/ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
630 |
private static class TransRule implements Comparable<TransRule> |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
631 |
{ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
632 |
private int year; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
633 |
private RuleLine rule; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
634 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
635 |
/** The trans date/time */ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
636 |
private LocalDateTime ldt; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
637 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
638 |
/** The trans date/time in epoch seconds (assume UTC) */ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
639 |
long ldtSecs; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
640 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
641 |
TransRule(int year, RuleLine rule) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
642 |
this.year = year; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
643 |
this.rule = rule; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
644 |
this.ldt = rule.toDateTime(year); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
645 |
this.ldtSecs = ldt.toEpochSecond(ZoneOffset.UTC); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
646 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
647 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
648 |
ZoneOffsetTransition toTransition(ZoneOffset standardOffset, int savingsBeforeSecs) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
649 |
// copy of code in ZoneOffsetTransitionRule to avoid infinite loop |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
650 |
ZoneOffset wallOffset = ZoneOffset.ofTotalSeconds( |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
651 |
standardOffset.getTotalSeconds() + savingsBeforeSecs); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
652 |
ZoneOffset offsetAfter = ZoneOffset.ofTotalSeconds( |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
653 |
standardOffset.getTotalSeconds() + rule.savingsAmount); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
654 |
LocalDateTime dt = rule.timeDefinition |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
655 |
.createDateTime(ldt, standardOffset, wallOffset); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
656 |
return ZoneOffsetTransition.of(dt, wallOffset, offsetAfter); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
657 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
658 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
659 |
long toEpochSecond(ZoneOffset stdOffset, int savingsBeforeSecs) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
660 |
switch(rule.timeDefinition) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
661 |
case UTC: return ldtSecs; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
662 |
case STANDARD: return ldtSecs - stdOffset.getTotalSeconds(); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
663 |
default: return ldtSecs - (stdOffset.getTotalSeconds() + savingsBeforeSecs); // WALL |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
664 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
665 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
666 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
667 |
/** |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
668 |
* Tests if this a real transition with the active savings in seconds |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
669 |
* |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
670 |
* @param savingsBefore the active savings in seconds |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
671 |
* @return true, if savings changes |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
672 |
*/ |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
673 |
boolean isTransition(int savingsBefore) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
674 |
return rule.savingsAmount != savingsBefore; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
675 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
676 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
677 |
public int compareTo(TransRule other) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
678 |
return (ldtSecs < other.ldtSecs)? -1 : ((ldtSecs == other.ldtSecs) ? 0 : 1); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
679 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
680 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
681 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
682 |
private ZoneRules buildRules(String zoneId, List<ZoneLine> zones) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
683 |
if (zones.isEmpty()) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
684 |
throw new IllegalStateException("No available zone window"); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
685 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
686 |
final List<ZoneOffsetTransition> standardTransitionList = new ArrayList<>(4); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
687 |
final List<ZoneOffsetTransition> transitionList = new ArrayList<>(256); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
688 |
final List<ZoneOffsetTransitionRule> lastTransitionRuleList = new ArrayList<>(2); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
689 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
690 |
final ZoneLine zone0 = zones.get(0); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
691 |
// initialize the standard offset, wallOffset and savings for loop |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
692 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
693 |
//ZoneOffset stdOffset = zone0.standardOffset; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
694 |
ZoneOffset stdOffset = ZoneOffset.ofTotalSeconds(zone0.stdOffsetSecs); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
695 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
696 |
int savings = zone0.fixedSavingsSecs; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
697 |
ZoneOffset wallOffset = ZoneOffset.ofTotalSeconds(stdOffset.getTotalSeconds() + savings); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
698 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
699 |
// start ldt of each zone window |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
700 |
LocalDateTime zoneStart = LocalDateTime.MIN; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
701 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
702 |
// first stanard offset |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
703 |
ZoneOffset firstStdOffset = stdOffset; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
704 |
// first wall offset |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
705 |
ZoneOffset firstWallOffset = wallOffset; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
706 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
707 |
for (ZoneLine zone : zones) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
708 |
// check if standard offset changed, update it if yes |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
709 |
ZoneOffset stdOffsetPrev = stdOffset; // for effectiveSavings check |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
710 |
if (zone.stdOffsetSecs != stdOffset.getTotalSeconds()) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
711 |
ZoneOffset stdOffsetNew = ZoneOffset.ofTotalSeconds(zone.stdOffsetSecs); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
712 |
standardTransitionList.add( |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
713 |
ZoneOffsetTransition.of( |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
714 |
LocalDateTime.ofEpochSecond(zoneStart.toEpochSecond(wallOffset), |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
715 |
0, |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
716 |
stdOffset), |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
717 |
stdOffset, |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
718 |
stdOffsetNew)); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
719 |
stdOffset = stdOffsetNew; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
720 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
721 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
722 |
LocalDateTime zoneEnd; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
723 |
if (zone.year == Year.MAX_VALUE) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
724 |
zoneEnd = LocalDateTime.MAX; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
725 |
} else { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
726 |
zoneEnd = zone.toDateTime(); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
727 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
728 |
if (zoneEnd.compareTo(zoneStart) < 0) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
729 |
throw new IllegalStateException("Windows must be in date-time order: " + |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
730 |
zoneEnd + " < " + zoneStart); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
731 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
732 |
// calculate effective savings at the start of the window |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
733 |
List<TransRule> trules = null; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
734 |
List<TransRule> lastRules = null; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
735 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
736 |
int effectiveSavings = zone.fixedSavingsSecs; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
737 |
if (zone.savingsRule != null) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
738 |
List<RuleLine> tzdbRules = rules.get(zone.savingsRule); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
739 |
if (tzdbRules == null) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
740 |
throw new IllegalArgumentException("<Rule> not found: " + |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
741 |
zone.savingsRule); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
742 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
743 |
trules = new ArrayList<>(256); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
744 |
lastRules = new ArrayList<>(2); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
745 |
int lastRulesStartYear = Year.MIN_VALUE; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
746 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
747 |
// merge the rules to transitions |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
748 |
for (RuleLine rule : tzdbRules) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
749 |
if (rule.startYear > zoneEnd.getYear()) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
750 |
// rules will not be used for this zone entry |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
751 |
continue; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
752 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
753 |
rule.adjustToForwards(2004); // irrelevant, treat as leap year |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
754 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
755 |
int startYear = rule.startYear; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
756 |
int endYear = rule.endYear; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
757 |
if (zoneEnd.equals(LocalDateTime.MAX)) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
758 |
if (endYear == Year.MAX_VALUE) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
759 |
endYear = startYear; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
760 |
lastRules.add(new TransRule(endYear, rule)); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
761 |
} |
28094
d0383a8fa398
8051641: Africa/Casablanca transitions is incorrectly calculated starting from 2027
aefimov
parents:
27726
diff
changeset
|
762 |
lastRulesStartYear = Math.max(startYear, lastRulesStartYear); |
25158
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
763 |
} else { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
764 |
if (endYear == Year.MAX_VALUE) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
765 |
//endYear = zoneEnd.getYear(); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
766 |
endYear = zone.year; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
767 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
768 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
769 |
int year = startYear; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
770 |
while (year <= endYear) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
771 |
trules.add(new TransRule(year, rule)); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
772 |
year++; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
773 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
774 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
775 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
776 |
// last rules, fill the gap years between different last rules |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
777 |
if (zoneEnd.equals(LocalDateTime.MAX)) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
778 |
lastRulesStartYear = Math.max(lastRulesStartYear, zoneStart.getYear()) + 1; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
779 |
for (TransRule rule : lastRules) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
780 |
if (rule.year <= lastRulesStartYear) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
781 |
int year = rule.year; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
782 |
while (year <= lastRulesStartYear) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
783 |
trules.add(new TransRule(year, rule.rule)); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
784 |
year++; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
785 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
786 |
rule.year = lastRulesStartYear; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
787 |
rule.ldt = rule.rule.toDateTime(year); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
788 |
rule.ldtSecs = rule.ldt.toEpochSecond(ZoneOffset.UTC); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
789 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
790 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
791 |
Collections.sort(lastRules); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
792 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
793 |
// sort the merged rules |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
794 |
Collections.sort(trules); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
795 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
796 |
effectiveSavings = 0; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
797 |
for (TransRule rule : trules) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
798 |
if (rule.toEpochSecond(stdOffsetPrev, savings) > |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
799 |
zoneStart.toEpochSecond(wallOffset)) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
800 |
// previous savings amount found, which could be the |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
801 |
// savings amount at the instant that the window starts |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
802 |
// (hence isAfter) |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
803 |
break; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
804 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
805 |
effectiveSavings = rule.rule.savingsAmount; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
806 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
807 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
808 |
// check if the start of the window represents a transition |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
809 |
ZoneOffset effectiveWallOffset = |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
810 |
ZoneOffset.ofTotalSeconds(stdOffset.getTotalSeconds() + effectiveSavings); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
811 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
812 |
if (!wallOffset.equals(effectiveWallOffset)) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
813 |
transitionList.add(ZoneOffsetTransition.of(zoneStart, |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
814 |
wallOffset, |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
815 |
effectiveWallOffset)); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
816 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
817 |
savings = effectiveSavings; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
818 |
// apply rules within the window |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
819 |
if (trules != null) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
820 |
long zoneStartEpochSecs = zoneStart.toEpochSecond(wallOffset); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
821 |
for (TransRule trule : trules) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
822 |
if (trule.isTransition(savings)) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
823 |
long epochSecs = trule.toEpochSecond(stdOffset, savings); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
824 |
if (epochSecs < zoneStartEpochSecs || |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
825 |
epochSecs >= zone.toDateTimeEpochSecond(savings)) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
826 |
continue; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
827 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
828 |
transitionList.add(trule.toTransition(stdOffset, savings)); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
829 |
savings = trule.rule.savingsAmount; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
830 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
831 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
832 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
833 |
if (lastRules != null) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
834 |
for (TransRule trule : lastRules) { |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
835 |
lastTransitionRuleList.add(trule.rule.toTransitionRule(stdOffset, savings)); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
836 |
savings = trule.rule.savingsAmount; |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
837 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
838 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
839 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
840 |
// finally we can calculate the true end of the window, passing it to the next window |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
841 |
wallOffset = ZoneOffset.ofTotalSeconds(stdOffset.getTotalSeconds() + savings); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
842 |
zoneStart = LocalDateTime.ofEpochSecond(zone.toDateTimeEpochSecond(savings), |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
843 |
0, |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
844 |
wallOffset); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
845 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
846 |
return new ZoneRules(firstStdOffset, |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
847 |
firstWallOffset, |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
848 |
standardTransitionList, |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
849 |
transitionList, |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
850 |
lastTransitionRuleList); |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
851 |
} |
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
852 |
|
e76154c2c239
8042369: Remove duplicated java.time classes in build.tools.tzdb
sherman
parents:
diff
changeset
|
853 |
} |