Skip to content

Commit

Permalink
fixed testExtractDatePartWithTimeType
Browse files Browse the repository at this point in the history
Signed-off-by: Kenrick Yap <[email protected]>
  • Loading branch information
kenrickyap committed Jan 14, 2025
1 parent b127352 commit 67b81f1
Showing 1 changed file with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

package org.opensearch.sql.expression.datetime;

import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_YEAR;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.opensearch.sql.data.type.ExprCoreType.LONG;

import java.time.LocalDate;
import java.time.temporal.WeekFields;
import java.util.Locale;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -96,15 +97,8 @@ public void testExtractDatePartWithTimeType() {

datePartWithTimeArgQuery("DAY", timeInput, now.getDayOfMonth());

// To avoid flaky test, skip the testing in December and January because the WEEK is ISO 8601
// week-of-week-based-year which is considered to start on a Monday and week 1 is the first week
// with >3 days. it is possible for early-January dates to be part of the 52nd or 53rd week of
// the previous year, and for late-December dates to be part of the first week of the next year.
// For example, 2005-01-02 is part of the 53rd week of year 2004, while 2012-12-31 is part of
// the first week of 2013
if (now.getMonthValue() != 1 && now.getMonthValue() != 12) {
datePartWithTimeArgQuery("WEEK", datetimeInput, now.get(ALIGNED_WEEK_OF_YEAR));
}
datePartWithTimeArgQuery(
"WEEK", timeInput, now.get(WeekFields.of(Locale.ENGLISH).weekOfYear()));

datePartWithTimeArgQuery("MONTH", timeInput, now.getMonthValue());

Expand Down

0 comments on commit 67b81f1

Please sign in to comment.