/*
 * Licensed to Elasticsearch under one or more contributor
 * license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright
 * ownership. Elasticsearch licenses this file to you 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.
 */
package org.elasticsearch.common.rounding;

import org.elasticsearch.test.ESTestCase;
import org.joda.time.DateTimeZone;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;

import static org.elasticsearch.common.rounding.DateTimeUnit.DAY_OF_MONTH;
import static org.elasticsearch.common.rounding.DateTimeUnit.HOUR_OF_DAY;
import static org.elasticsearch.common.rounding.DateTimeUnit.MINUTES_OF_HOUR;
import static org.elasticsearch.common.rounding.DateTimeUnit.MONTH_OF_YEAR;
import static org.elasticsearch.common.rounding.DateTimeUnit.QUARTER;
import static org.elasticsearch.common.rounding.DateTimeUnit.SECOND_OF_MINUTE;
import static org.elasticsearch.common.rounding.DateTimeUnit.WEEK_OF_WEEKYEAR;
import static org.elasticsearch.common.rounding.DateTimeUnit.YEAR_OF_CENTURY;
import static org.hamcrest.Matchers.is;

public class DateTimeUnitTests extends ESTestCase {

    /**
     * test that we don't accidentally change enum ids
     */
    public void testEnumIds() {
        assertEquals(1, WEEK_OF_WEEKYEAR.id());
        assertEquals(WEEK_OF_WEEKYEAR, DateTimeUnit.resolve((byte) 1));

        assertEquals(2, YEAR_OF_CENTURY.id());
        assertEquals(YEAR_OF_CENTURY, DateTimeUnit.resolve((byte) 2));

        assertEquals(3, QUARTER.id());
        assertEquals(QUARTER, DateTimeUnit.resolve((byte) 3));

        assertEquals(4, MONTH_OF_YEAR.id());
        assertEquals(MONTH_OF_YEAR, DateTimeUnit.resolve((byte) 4));

        assertEquals(5, DAY_OF_MONTH.id());
        assertEquals(DAY_OF_MONTH, DateTimeUnit.resolve((byte) 5));

        assertEquals(6, HOUR_OF_DAY.id());
        assertEquals(HOUR_OF_DAY, DateTimeUnit.resolve((byte) 6));

        assertEquals(7, MINUTES_OF_HOUR.id());
        assertEquals(MINUTES_OF_HOUR, DateTimeUnit.resolve((byte) 7));

        assertEquals(8, SECOND_OF_MINUTE.id());
        assertEquals(SECOND_OF_MINUTE, DateTimeUnit.resolve((byte) 8));
    }

    @AwaitsFix( bugUrl = "https://github.com/elastic/elasticsearch/issues/39617")
    public void testConversion() {
        long millis = randomLongBetween(0, Instant.now().toEpochMilli());
        DateTimeZone zone = randomDateTimeZone();
        ZoneId zoneId = zone.toTimeZone().toZoneId();

        int offsetSeconds = zoneId.getRules().getOffset(Instant.ofEpochMilli(millis)).getTotalSeconds();
        long parsedMillisJavaTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(millis), zoneId)
            .minusSeconds(offsetSeconds).toInstant().toEpochMilli();

        long parsedMillisJodaTime = zone.convertLocalToUTC(millis, true);
        assertThat(parsedMillisJavaTime, is(parsedMillisJodaTime));
    }
}

@@ -871,127 +871,8 @@
 ase;
-%0Aimport org.joda.time.DateTimeZone;%0A%0Aimport java.time.Instant;%0Aimport java.time.ZoneId;%0Aimport java.time.ZonedDateTime;
 %0A%0Aim
@@ -1481,48 +1481,8 @@
 URY;
-%0Aimport static org.hamcrest.Matchers.is;
 %0A%0Apu
@@ -2476,32 +2476,32 @@
 F_MINUTE.id());%0A
+
         assertEq
@@ -2565,725 +2565,7 @@
    %7D
-%0A%0A    @AwaitsFix( bugUrl = %22https://github.com/elastic/elasticsearch/issues/39617%22)%0A    public void testConversion() %7B%0A        long millis = randomLongBetween(0, Instant.now().toEpochMilli());%0A        DateTimeZone zone = randomDateTimeZone();%0A        ZoneId zoneId = zone.toTimeZone().toZoneId();%0A%0A        int offsetSeconds = zoneId.getRules().getOffset(Instant.ofEpochMilli(millis)).getTotalSeconds();%0A        long parsedMillisJavaTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(millis), zoneId)%0A            .minusSeconds(offsetSeconds).toInstant().toEpochMilli();%0A%0A        long parsedMillisJodaTime = zone.convertLocalToUTC(millis, true);%0A        assertThat(parsedMillisJavaTime, is(parsedMillisJodaTime));%0A    %7D
 %0A%7D%0A

Remove the test which is testing java and joda api (#41493)