/*
 * Java GPX Library (@__identifier__@).
 * Copyright (c) @__year__@ Franz Wilhelmstötter
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Author:
 *    Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com)
 */
package io.jenetics.jpx;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Objects;

/**
 * @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>
 * @version 1.2
 * @since 1.2
 */
final class ZonedDateTimes {

	private ZonedDateTimes() {
	}

	static void write(final ZonedDateTime time, final DataOutput out)
		throws IOException
	{
		IO.writeLong(time.toEpochSecond(), out);
		writeZoneOffset(time.getOffset(), out);
	}

	private static
	void writeZoneOffset(final ZoneOffset os, final DataOutput out)
		throws IOException
	{
		final int offsetSecs = os.getTotalSeconds();
		int offsetByte = offsetSecs%900 == 0 ? offsetSecs/900 : 127;
		out.writeByte(offsetByte);
		if (offsetByte == 127) {
			IO.writeInt(offsetSecs, out);
		}
	}

	static ZonedDateTime read(final DataInput in) throws IOException {
		final long seconds = IO.readLong(in);
		final ZoneOffset offset = readZoneOffset(in);
		return ZonedDateTime.ofInstant(Instant.ofEpochSecond(seconds), offset);
	}

	private static ZoneOffset readZoneOffset(final DataInput in)
		throws IOException
	{
		int offsetByte = in.readByte();
		return offsetByte == 127
			? ZoneOffset.ofTotalSeconds(IO.readInt(in))
			: ZoneOffset.ofTotalSeconds(offsetByte*900);
	}

	static int hashCode(final ZonedDateTime a) {
		final Instant i = a != null
			? a.toInstant().truncatedTo(ChronoUnit.SECONDS)
			: null;
		return Objects.hashCode(i);
	}

	/**
	 * Tests if the given date times represents the same point on the time-line.
	 *
	 * @param a the first date time
	 * @param b the second date time
	 * @return {@code true} if the two date times represents the same point on
	 *         the time-line, {@code false} otherwise
	 */
	static boolean equals(final ZonedDateTime a, final ZonedDateTime b) {
		final Instant i1 = a != null
			? a.toInstant().truncatedTo(ChronoUnit.SECONDS)
			: null;
		final Instant i2 = b != null
			? b.toInstant().truncatedTo(ChronoUnit.SECONDS)
			: null;

		return Objects.equals(i1, i2);
	}

}

@@ -1083,19 +1083,19 @@
 version 
-1.2
+2.0
 %0A * @sin
@@ -2144,74 +2144,476 @@
 %7D%0A%0A%09
-static int hashCode(final ZonedDateTime a) %7B%0A%09%09final Instant i = a
+/**%0A%09 * Return the hash code of the given date time object. Actually the hash%0A%09 * code of its %7B@link Instant%7D, truncated to seconds, is returned. The%0A%09 * argument may be %7B@code null%7D.%0A%09 *%0A%09 * @param a the date time, for which the hash code is calculated%0A%09 * @return the %3Cem%3Etruncated%3C/em%3E hash code%0A%09 */%0A%09static int hashCode(final ZonedDateTime a) %7B%0A%09%09return Objects.hashCode(toInstant(a));%0A%09%7D%0A%0A%09private static Instant toInstant(final ZonedDateTime zdt) %7B%0A%09%09return zdt
  != 
@@ -2614,33 +2614,35 @@
 dt != null%0A%09%09%09? 
-a
+zdt
 .toInstant().tru
@@ -2685,38 +2685,8 @@
 ll;%0A
-%09%09return Objects.hashCode(i);%0A
 %09%7D%0A%0A
@@ -2768,16 +2768,257 @@
 e-line.%0A
+%09 * The used resolution for comparision is %3Cem%3Eseconds%3C/em%3E. If two%0A%09 * %7B@link ZonedDateTime%7D objects are equal to its seconds, they are treated%0A%09 * as equal, even if the milli-second part is different. The argument may be%0A%09 * %7B@code null%7D.%0A
 %09 *%0A%09 * 
@@ -3289,223 +3289,56 @@
 %7B%0A%09%09
-final Instant i1 = a != null%0A%09%09%09? a.toInstant().truncatedTo(ChronoUnit.SECONDS)%0A%09%09%09: null;%0A%09%09final Instant i2 = b != null%0A%09%09%09? b.toInstant().truncatedTo(ChronoUnit.SECONDS)%0A%09%09%09: null;%0A%0A%09%09return Objects.equals(i1, i2
+return Objects.equals(toInstant(a), toInstant(b)
 );%0A%09

Simplify 'hashCode' and 'equals' method.