1 /*
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
215 int store = (int) ((epochSec + 4575744000L) / 900);
216 out.writeByte((store >>> 16) & 255);
217 out.writeByte((store >>> 8) & 255);
218 out.writeByte(store & 255);
219 } else {
220 out.writeByte(255);
221 out.writeLong(epochSec);
222 }
223 }
224
225 /**
226 * Writes the state of the transition rule to the stream.
227 *
228 * @param rule the transition rule, not null
229 * @param out the output stream, not null
230 * @throws IOException if an error occurs
231 */
232 static void writeRule(ZoneOffsetTransitionRule rule, DataOutput out) throws IOException {
233 int month = rule.getMonth().getValue();
234 byte dom = (byte)rule.getDayOfMonthIndicator();
235 int dow = rule.getDayOfWeek().getValue();
236 LocalTime time = rule.getLocalTime();
237 boolean timeEndOfDay = rule.isMidnightEndOfDay();
238 TimeDefinition timeDefinition = rule.getTimeDefinition();
239 ZoneOffset standardOffset = rule.getStandardOffset();
240 ZoneOffset offsetBefore = rule.getOffsetBefore();
241 ZoneOffset offsetAfter = rule.getOffsetAfter();
242
243 int timeSecs = (timeEndOfDay ? 86400 : time.toSecondOfDay());
244 int stdOffset = standardOffset.getTotalSeconds();
245 int beforeDiff = offsetBefore.getTotalSeconds() - stdOffset;
246 int afterDiff = offsetAfter.getTotalSeconds() - stdOffset;
247 int timeByte = (timeSecs % 3600 == 0 ? (timeEndOfDay ? 24 : time.getHour()) : 31);
248 int stdOffsetByte = (stdOffset % 900 == 0 ? stdOffset / 900 + 128 : 255);
249 int beforeByte = (beforeDiff == 0 || beforeDiff == 1800 || beforeDiff == 3600 ? beforeDiff / 1800 : 3);
250 int afterByte = (afterDiff == 0 || afterDiff == 1800 || afterDiff == 3600 ? afterDiff / 1800 : 3);
251 int dowByte = (dow == -1 ? 0 : dow);
252 int b = (month << 28) + // 4 bytes
253 ((dom + 32) << 22) + // 6 bytes
254 (dowByte << 19) + // 3 bytes
255 (timeByte << 14) + // 5 bytes
|
1 /*
2 * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
215 int store = (int) ((epochSec + 4575744000L) / 900);
216 out.writeByte((store >>> 16) & 255);
217 out.writeByte((store >>> 8) & 255);
218 out.writeByte(store & 255);
219 } else {
220 out.writeByte(255);
221 out.writeLong(epochSec);
222 }
223 }
224
225 /**
226 * Writes the state of the transition rule to the stream.
227 *
228 * @param rule the transition rule, not null
229 * @param out the output stream, not null
230 * @throws IOException if an error occurs
231 */
232 static void writeRule(ZoneOffsetTransitionRule rule, DataOutput out) throws IOException {
233 int month = rule.getMonth().getValue();
234 byte dom = (byte)rule.getDayOfMonthIndicator();
235 int dow = (rule.getDayOfWeek() == null ? -1 : rule.getDayOfWeek().getValue());
236 LocalTime time = rule.getLocalTime();
237 boolean timeEndOfDay = rule.isMidnightEndOfDay();
238 TimeDefinition timeDefinition = rule.getTimeDefinition();
239 ZoneOffset standardOffset = rule.getStandardOffset();
240 ZoneOffset offsetBefore = rule.getOffsetBefore();
241 ZoneOffset offsetAfter = rule.getOffsetAfter();
242
243 int timeSecs = (timeEndOfDay ? 86400 : time.toSecondOfDay());
244 int stdOffset = standardOffset.getTotalSeconds();
245 int beforeDiff = offsetBefore.getTotalSeconds() - stdOffset;
246 int afterDiff = offsetAfter.getTotalSeconds() - stdOffset;
247 int timeByte = (timeSecs % 3600 == 0 ? (timeEndOfDay ? 24 : time.getHour()) : 31);
248 int stdOffsetByte = (stdOffset % 900 == 0 ? stdOffset / 900 + 128 : 255);
249 int beforeByte = (beforeDiff == 0 || beforeDiff == 1800 || beforeDiff == 3600 ? beforeDiff / 1800 : 3);
250 int afterByte = (afterDiff == 0 || afterDiff == 1800 || afterDiff == 3600 ? afterDiff / 1800 : 3);
251 int dowByte = (dow == -1 ? 0 : dow);
252 int b = (month << 28) + // 4 bytes
253 ((dom + 32) << 22) + // 6 bytes
254 (dowByte << 19) + // 3 bytes
255 (timeByte << 14) + // 5 bytes
|