mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-16 10:17:23 +00:00
ICU-7602 Add era to ChineseCalendar constructors. ICU4J
X-SVN-Rev: 28074
This commit is contained in:
parent
50d9837e92
commit
6dce030d93
2 changed files with 105 additions and 0 deletions
|
@ -218,6 +218,80 @@ public class ChineseCalendar extends Calendar {
|
|||
this.set(SECOND, second);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>ChineseCalendar</code> with the given date set
|
||||
* in the default time zone with the default locale.
|
||||
*
|
||||
* @param era The value used to set the calendar's {@link #ERA ERA} time field.
|
||||
* @param year The value used to set the calendar's {@link #YEAR YEAR} time field.
|
||||
* @param month The value used to set the calendar's {@link #MONTH MONTH} time field.
|
||||
* The value is 0-based. e.g., 0 for January.
|
||||
* @param isLeapMonth The value used to set the Chinese calendar's (@link #IS_LEAP_MONTH)
|
||||
* time field.
|
||||
* @param date The value used to set the calendar's {@link #DATE DATE} time field.
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
public ChineseCalendar(int era, int year, int month, int isLeapMonth, int date)
|
||||
{
|
||||
super(TimeZone.getDefault(), ULocale.getDefault());
|
||||
|
||||
// We need to set the current time once to initialize the ChineseCalendar's
|
||||
// ERA field to be the current era.
|
||||
setTimeInMillis(System.currentTimeMillis());
|
||||
|
||||
// Then we need to clean up time fields
|
||||
this.set(MILLISECONDS_IN_DAY, 0);
|
||||
|
||||
// Then set the given field values.
|
||||
this.set(ERA, era);
|
||||
this.set(YEAR, year);
|
||||
this.set(MONTH, month);
|
||||
this.set(IS_LEAP_MONTH, isLeapMonth);
|
||||
this.set(DATE, date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>ChineseCalendar</code> with the given date
|
||||
* and time set for the default time zone with the default locale.
|
||||
*
|
||||
* @param era the value used to set the calendar's {@link #ERA ERA} time field.
|
||||
* @param year the value used to set the {@link #YEAR YEAR} time field in the calendar.
|
||||
* @param month the value used to set the {@link #MONTH MONTH} time field in the calendar.
|
||||
* Note that the month value is 0-based. e.g., 0 for January.
|
||||
* @param isLeapMonth the value used to set the {@link #IS_LEAP_MONTH} time field
|
||||
* in the calendar.
|
||||
* @param date the value used to set the {@link #DATE DATE} time field in the calendar.
|
||||
* @param hour the value used to set the {@link #HOUR_OF_DAY HOUR_OF_DAY} time field
|
||||
* in the calendar.
|
||||
* @param minute the value used to set the {@link #MINUTE MINUTE} time field
|
||||
* in the calendar.
|
||||
* @param second the value used to set the {@link #SECOND SECOND} time field
|
||||
* in the calendar.
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
public ChineseCalendar(int era, int year, int month, int isLeapMonth, int date, int hour,
|
||||
int minute, int second)
|
||||
{
|
||||
super(TimeZone.getDefault(), ULocale.getDefault());
|
||||
|
||||
// We need to set the current time once to initialize the ChineseCalendar's
|
||||
// ERA field to be the current era.
|
||||
setTimeInMillis(System.currentTimeMillis());
|
||||
|
||||
// Then set 0 to millisecond field
|
||||
this.set(MILLISECOND, 0);
|
||||
|
||||
// Then, set the given field values.
|
||||
this.set(ERA, era);
|
||||
this.set(YEAR, year);
|
||||
this.set(MONTH, month);
|
||||
this.set(IS_LEAP_MONTH, isLeapMonth);
|
||||
this.set(DATE, date);
|
||||
this.set(HOUR_OF_DAY, hour);
|
||||
this.set(MINUTE, minute);
|
||||
this.set(SECOND, second);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>ChineseCalendar</code> based on the current time
|
||||
* in the default time zone with the given locale.
|
||||
|
|
|
@ -13,6 +13,7 @@ import com.ibm.icu.text.DateFormatSymbols;
|
|||
import com.ibm.icu.util.Calendar;
|
||||
import com.ibm.icu.util.ChineseCalendar;
|
||||
import com.ibm.icu.util.GregorianCalendar;
|
||||
import com.ibm.icu.text.SimpleDateFormat;
|
||||
import com.ibm.icu.util.TimeZone;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
|
@ -688,4 +689,34 @@ public class ChineseTest extends CalendarTest {
|
|||
assertEquals("chinese and gregorian date should match", target, result);
|
||||
}
|
||||
|
||||
public void Test6510()
|
||||
{
|
||||
Calendar gregorianCalendar;
|
||||
ChineseCalendar chineseCalendar, chineseCalendar2;
|
||||
ChineseDateFormat dateFormat;
|
||||
SimpleDateFormat simpleDateFormat;
|
||||
|
||||
simpleDateFormat = new com.ibm.icu.text.SimpleDateFormat("MM/dd/yyyy G 'at' HH:mm:ss vvvv", Locale.US);
|
||||
dateFormat = new com.ibm.icu.text.ChineseDateFormat("MM/dd/yyyy(G) HH:mm:ss", Locale.CHINA);
|
||||
|
||||
// lunar to gregorian
|
||||
chineseCalendar = new ChineseCalendar(77, 26, Calendar.JANUARY, 0, 6, 0, 0, 0);
|
||||
gregorianCalendar = Calendar.getInstance(Locale.US);
|
||||
gregorianCalendar.setTime(chineseCalendar.getTime());
|
||||
|
||||
// gregorian to lunar
|
||||
chineseCalendar2 = new ChineseCalendar();
|
||||
chineseCalendar2.setTimeInMillis(gregorianCalendar.getTimeInMillis());
|
||||
|
||||
// validate roundtrip
|
||||
if (chineseCalendar.getTimeInMillis() != chineseCalendar2.getTimeInMillis())
|
||||
{
|
||||
errln("time1: " + chineseCalendar.getTimeInMillis());
|
||||
errln("time2: " + chineseCalendar2.getTimeInMillis());
|
||||
errln("Lunar [MM/dd/y(G) HH:mm:ss] " + dateFormat.format(chineseCalendar));
|
||||
errln("**PROBLEM Grego [MM/dd/y(G) HH:mm:ss] " + simpleDateFormat.format(gregorianCalendar));
|
||||
errln("Grego [MM/dd/y(G) HH:mm:ss] " + simpleDateFormat.format(gregorianCalendar));
|
||||
errln("Lunar [MM/dd/y(G) HH:mm:ss] " + dateFormat.format(chineseCalendar2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue