Skip to content

Commit 22181ee

Browse files
committed
ICU-23102 Remove unused code
1 parent b6c7d64 commit 22181ee

File tree

4 files changed

+13
-76
lines changed

4 files changed

+13
-76
lines changed

icu4c/source/i18n/calendar.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,9 +1529,15 @@ void Calendar::computeGregorianFields(int32_t julianDay, UErrorCode& ec) {
15291529
ec = U_ILLEGAL_ARGUMENT_ERROR;
15301530
return;
15311531
}
1532+
int8_t dayOfWeek;
15321533
Grego::dayToFields(julianDay, fGregorianYear, fGregorianMonth,
15331534
fGregorianDayOfMonth,
1535+
dayOfWeek,
15341536
fGregorianDayOfYear, ec);
1537+
if (U_FAILURE(ec)) {
1538+
return;
1539+
}
1540+
internalSet(UCAL_DAY_OF_WEEK, dayOfWeek);
15351541
}
15361542

15371543
/**
@@ -1560,8 +1566,7 @@ void Calendar::computeWeekFields(UErrorCode &ec) {
15601566
}
15611567

15621568
// Compute day of week: JD 0 = Monday
1563-
int32_t dayOfWeek = julianDayToDayOfWeek(fFields[UCAL_JULIAN_DAY]);
1564-
internalSet(UCAL_DAY_OF_WEEK, dayOfWeek);
1569+
int32_t dayOfWeek = fFields[UCAL_DAY_OF_WEEK];
15651570
int32_t firstDayOfWeek = getFirstDayOfWeek();
15661571
// Calculate 1-based localized day of week
15671572
int32_t dowLocal = dayOfWeek - firstDayOfWeek + 1;

icu4c/source/i18n/gregoimp.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,6 @@ int32_t Grego::dayToYear(int32_t day, int16_t& doy, UErrorCode& status) {
176176
return year;
177177
}
178178

179-
void Grego::dayToFields(int32_t day, int32_t& year, int8_t& month,
180-
int8_t& dom, int8_t& dow, UErrorCode& status) {
181-
int16_t unusedDOY;
182-
dayToFields(day, year, month, dom, dow, unusedDOY, status);
183-
}
184-
185-
void Grego::dayToFields(int32_t day, int32_t& year, int8_t& month,
186-
int8_t& dom, int16_t& doy, UErrorCode& status) {
187-
int8_t unusedDOW;
188-
dayToFields(day, year, month, dom, unusedDOW, doy, status);
189-
}
190-
191179
void Grego::timeToFields(UDate time, int32_t& year, int8_t& month,
192180
int8_t& dom, int32_t& mid, UErrorCode& status) {
193181
int8_t unusedDOW;

icu4c/source/i18n/gregoimp.h

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -213,32 +213,6 @@ class Grego {
213213
static void dayToFields(int32_t day, int32_t& year, int8_t& month,
214214
int8_t& dom, int8_t& dow, int16_t& doy, UErrorCode& status);
215215

216-
/**
217-
* Convert a 1970-epoch day number to proleptic Gregorian year,
218-
* month, day-of-month, and day-of-week.
219-
* @param day 1970-epoch day
220-
* @param year output parameter to receive year
221-
* @param month output parameter to receive month (0-based, 0==Jan)
222-
* @param dom output parameter to receive day-of-month (1-based)
223-
* @param doy output parameter to receive day-of-year (1-based)
224-
* @param status error code.
225-
*/
226-
static void dayToFields(int32_t day, int32_t& year, int8_t& month,
227-
int8_t& dom, int16_t& doy, UErrorCode& status);
228-
229-
/**
230-
* Convert a 1970-epoch day number to proleptic Gregorian year,
231-
* month, day-of-month, and day-of-week.
232-
* @param day 1970-epoch day
233-
* @param year output parameter to receive year
234-
* @param month output parameter to receive month (0-based, 0==Jan)
235-
* @param dom output parameter to receive day-of-month (1-based)
236-
* @param dow output parameter to receive day-of-week (1-based, 1==Sun)
237-
* @param status error code.
238-
*/
239-
static void dayToFields(int32_t day, int32_t& year, int8_t& month,
240-
int8_t& dom, int8_t& dow, UErrorCode& status);
241-
242216
/**
243217
* Convert a 1970-epoch day number to proleptic Gregorian year.
244218
* @param day 1970-epoch day

icu4j/main/core/src/main/java/com/ibm/icu/util/Calendar.java

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import com.ibm.icu.impl.CalType;
2222
import com.ibm.icu.impl.CalendarUtil;
23+
import com.ibm.icu.impl.Grego;
2324
import com.ibm.icu.impl.ICUCache;
2425
import com.ibm.icu.impl.ICUData;
2526
import com.ibm.icu.impl.ICUResourceBundle;
@@ -5322,42 +5323,11 @@ private final void computeGregorianAndDOWFields(int julianDay) {
53225323
* @stable ICU 2.0
53235324
*/
53245325
protected final void computeGregorianFields(int julianDay) {
5325-
int year, month, dayOfMonth, dayOfYear;
5326-
5327-
// The Gregorian epoch day is zero for Monday January 1, year 1.
5328-
long gregorianEpochDay = julianDay - JAN_1_1_JULIAN_DAY;
5329-
5330-
// Here we convert from the day number to the multiple radix
5331-
// representation. We use 400-year, 100-year, and 4-year cycles.
5332-
// For example, the 4-year cycle has 4 years + 1 leap day; giving
5333-
// 1461 == 365*4 + 1 days.
5334-
int[] rem = new int[1];
5335-
int n400 = floorDivide(gregorianEpochDay, 146097, rem); // 400-year cycle length
5336-
int n100 = floorDivide(rem[0], 36524, rem); // 100-year cycle length
5337-
int n4 = floorDivide(rem[0], 1461, rem); // 4-year cycle length
5338-
int n1 = floorDivide(rem[0], 365, rem);
5339-
year = 400*n400 + 100*n100 + 4*n4 + n1;
5340-
dayOfYear = rem[0]; // zero-based day of year
5341-
if (n100 == 4 || n1 == 4) {
5342-
dayOfYear = 365; // Dec 31 at end of 4- or 400-yr cycle
5343-
} else {
5344-
++year;
5345-
}
5346-
5347-
boolean isLeap = ((year&0x3) == 0) && // equiv. to (year%4 == 0)
5348-
(year%100 != 0 || year%400 == 0);
5349-
5350-
int correction = 0;
5351-
int march1 = isLeap ? 60 : 59; // zero-based DOY for March 1
5352-
if (dayOfYear >= march1) correction = isLeap ? 1 : 2;
5353-
month = (12 * (dayOfYear + correction) + 6) / 367; // zero-based month
5354-
dayOfMonth = dayOfYear -
5355-
GREGORIAN_MONTH_COUNT[month][isLeap?3:2] + 1; // one-based DOM
5356-
5357-
gregorianYear = year;
5358-
gregorianMonth = month; // 0-based already
5359-
gregorianDayOfMonth = dayOfMonth; // 1-based already
5360-
gregorianDayOfYear = dayOfYear + 1; // Convert from 0-based to 1-based
5326+
int[] gregorian = Grego.dayToFields(julianDay - EPOCH_JULIAN_DAY, null);
5327+
gregorianYear = gregorian[0];
5328+
gregorianMonth = gregorian[1];
5329+
gregorianDayOfMonth = gregorian[2];
5330+
gregorianDayOfYear = gregorian[4];
53615331
}
53625332

53635333
/**

0 commit comments

Comments
 (0)