Skip to content

Commit

Permalink
ICU-22407 Implement Java Temporal Calendar API
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankYFTang committed Jul 27, 2023
1 parent 2238f1c commit 1e84249
Show file tree
Hide file tree
Showing 16 changed files with 1,594 additions and 30 deletions.
2 changes: 0 additions & 2 deletions icu4c/source/i18n/calendar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,6 @@ void Calendar::roll(UCalendarDateFields field, int32_t amount, UErrorCode& statu
}
set(field, newYear);
pinField(UCAL_MONTH,status);
pinField(UCAL_ORDINAL_MONTH,status);
pinField(UCAL_DAY_OF_MONTH,status);
return;
}
Expand All @@ -1836,7 +1835,6 @@ void Calendar::roll(UCalendarDateFields field, int32_t amount, UErrorCode& statu
// Rolling the year can involve pinning the DAY_OF_MONTH.
set(field, internalGet(field) + amount);
pinField(UCAL_MONTH,status);
pinField(UCAL_ORDINAL_MONTH,status);
pinField(UCAL_DAY_OF_MONTH,status);
return;

Expand Down
4 changes: 1 addition & 3 deletions icu4j/main/classes/core/src/com/ibm/icu/impl/CalType.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public enum CalType {
ISLAMIC_UMALQURA("islamic-umalqura"),
JAPANESE("japanese"),
PERSIAN("persian"),
ROC("roc"),

UNKNOWN("unknown");
ROC("roc");

String id;

Expand Down
47 changes: 47 additions & 0 deletions icu4j/main/classes/core/src/com/ibm/icu/util/CECalendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ abstract class CECalendar extends Calendar {
{ -5000000, -5000000, 5000000, 5000000 }, // EXTENDED_YEAR
{/* */}, // JULIAN_DAY
{/* */}, // MILLISECONDS_IN_DAY
{/* */}, // IS_LEAP_YEAR
{ 0, 0, 12, 12 }, // ORDINAL_MONTH
};

//-------------------------------------------------------------------------
Expand Down Expand Up @@ -273,4 +275,49 @@ public static void jdToCE(int julianDay, int jdEpochOffset, int[] fields) {
// day
fields[2] = (doy % 30) + 1; // 1-based days in a month
}


//-------------------------------------------------------------------------
// Temporal Calendar API.
//-------------------------------------------------------------------------
private static String [] gTemporalMonthCodes = {
"M01", "M02", "M03", "M04", "M05", "M06", "M07", "M08", "M09", "M10", "M11", "M12"
};

/**
* Gets The Temporal monthCode value corresponding to the month for the date.
* The value is a string identifier that starts with the literal grapheme
* "M" followed by two graphemes representing the zero-padded month number
* of the current month in a normal (non-leap) year. For the short thirteen
* month in each year in the CECalendar, the value is "M13".
*
* @return One of 13 possible strings in {"M01".. "M12", "M13"}.
* @draft ICU 74
*/
public String getTemporalMonthCode() {
if (get(MONTH) == 12) return "M13";
return super.getTemporalMonthCode();
}

/**
* Sets The Temporal monthCode which is a string identifier that starts
* with the literal grapheme "M" followed by two graphemes representing
* the zero-padded month number of the current month in a normal
* (non-leap) year. For CECalendar calendar, the values are "M01" .. "M13"
* while the "M13" is represent the short thirteen month in each year.
* @param temporalMonth One of 13 possible strings in {"M01".. "M12", "M13"}.
* @draft ICU 74
*/
public void setTemporalMonthCode( String temporalMonth ) {
if (temporalMonth.equals("M13")) {
set(MONTH, 12);
set(IS_LEAP_MONTH, 0);
return;
}
super.setTemporalMonthCode(temporalMonth);
}

//-------------------------------------------------------------------------
// End of Temporal Calendar API
//-------------------------------------------------------------------------
}
Loading

0 comments on commit 1e84249

Please sign in to comment.