# HG changeset patch # User rchamyal # Date 1477041724 -19800 # Node ID 5abb663b1ca48ad73bb6b48126056559ec26c3d5 # Parent 68e4aa084dd6ef1f98fdf46a23bd4d8a055ae1f9 8163330: HijrahDate aligned day of week incorrect Reviewed-by: rriggs, scolebourne Contributed-by: anubhav.meena@oracle.com diff -r 68e4aa084dd6 -r 5abb663b1ca4 jdk/src/java.base/share/classes/java/time/chrono/HijrahDate.java --- a/jdk/src/java.base/share/classes/java/time/chrono/HijrahDate.java Fri Oct 21 11:33:37 2016 +0900 +++ b/jdk/src/java.base/share/classes/java/time/chrono/HijrahDate.java Fri Oct 21 14:52:04 2016 +0530 @@ -368,7 +368,7 @@ if (field instanceof ChronoField) { switch ((ChronoField) field) { case DAY_OF_WEEK: return getDayOfWeek(); - case ALIGNED_DAY_OF_WEEK_IN_MONTH: return ((getDayOfWeek() - 1) % 7) + 1; + case ALIGNED_DAY_OF_WEEK_IN_MONTH: return ((dayOfMonth - 1) % 7) + 1; case ALIGNED_DAY_OF_WEEK_IN_YEAR: return ((getDayOfYear() - 1) % 7) + 1; case DAY_OF_MONTH: return this.dayOfMonth; case DAY_OF_YEAR: return this.getDayOfYear(); diff -r 68e4aa084dd6 -r 5abb663b1ca4 jdk/test/java/time/test/java/time/chrono/TestUmmAlQuraChronology.java --- a/jdk/test/java/time/test/java/time/chrono/TestUmmAlQuraChronology.java Fri Oct 21 11:33:37 2016 +0900 +++ b/jdk/test/java/time/test/java/time/chrono/TestUmmAlQuraChronology.java Fri Oct 21 14:52:04 2016 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -624,7 +624,7 @@ @Test public void test_chronoFields() { ChronoLocalDate hdate = HijrahChronology.INSTANCE.date(1434, 6, 28); - assertEquals(hdate.get(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), 3); + assertEquals(hdate.get(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), 7); assertEquals(hdate.get(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), 7); assertEquals(hdate.get(ChronoField.ALIGNED_WEEK_OF_MONTH), 4); assertEquals(hdate.get(ChronoField.ALIGNED_WEEK_OF_YEAR), 25); @@ -785,4 +785,32 @@ public void test_hijrahToJapanese(HijrahDate hijrah, String japanese) { assertEquals(JapaneseChronology.INSTANCE.date(hijrah).toString(), japanese); } + + @DataProvider(name="alignedDayOfWeekInMonthTestDates") + Object[][] data_alignedDayOfWeekInMonth() { + return new Object[][] { + {1437, 9, 1, 1, 1}, + {1437, 10, 1, 1, 1}, + {1437, 10, 11, 2, 4}, + {1437, 10, 29, 5, 1}, + }; + } + + //----------------------------------------------------------------------- + // Test for aligned-week-of-month calculation based on the day-of-month + //----------------------------------------------------------------------- + @Test(dataProvider="alignedDayOfWeekInMonthTestDates") + public void test_alignedWeekOfMonth(int year, int month, int dom, int wom, int dowm) { + HijrahDate date = HijrahChronology.INSTANCE.date(year, month, dom); + assertEquals(date.getLong(ChronoField.ALIGNED_WEEK_OF_MONTH), wom); + } + + //----------------------------------------------------------------------- + // Test for aligned-day-of-week calculation based on the day-of-month + //----------------------------------------------------------------------- + @Test(dataProvider="alignedDayOfWeekInMonthTestDates") + public void test_alignedDayOfWeekInMonth(int year, int month, int dom, int wom, int dowm) { + HijrahDate date = HijrahChronology.INSTANCE.date(year, month, dom); + assertEquals(date.getLong(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), dowm); + } }