/* GENERATED SOURCE. DO NOT MODIFY. */ // © 2016 and later: Unicode, Inc. and others. // License & terms of use: http://www.unicode.org/copyright.html /* ******************************************************************************* * Copyright (C) 2005-2016, International Business Machines Corporation and * others. All Rights Reserved. ******************************************************************************* */ package android.icu.util; import java.util.Date; import java.util.Locale; import android.icu.impl.CalendarUtil; import android.icu.util.ULocale.Category; /** * Implement the Ethiopic calendar system. *
* EthiopicCalendar usually should be instantiated using
* {@link android.icu.util.Calendar#getInstance(ULocale)} passing in a ULocale
* with the tag "@calendar=ethiopic"
.
EthiopicCalendar
using the current time
* in the default time zone with the default locale.
*/
public EthiopicCalendar() {
this(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT));
}
/**
* Constructs a EthiopicCalendar
based on the current time
* in the given time zone with the default locale.
*
* @param zone The time zone for the new calendar.
*/
public EthiopicCalendar(TimeZone zone) {
this(zone, ULocale.getDefault(Category.FORMAT));
}
/**
* Constructs a EthiopicCalendar
based on the current time
* in the default time zone with the given locale.
*
* @param aLocale The locale for the new calendar.
*/
public EthiopicCalendar(Locale aLocale) {
this(TimeZone.forLocaleOrDefault(aLocale), aLocale);
}
/**
* Constructs a EthiopicCalendar
based on the current time
* in the default time zone with the given locale.
*
* @param locale The icu locale for the new calendar.
*/
public EthiopicCalendar(ULocale locale) {
this(TimeZone.forULocaleOrDefault(locale), locale);
}
/**
* Constructs a EthiopicCalendar
based on the current time
* in the given time zone with the given locale.
*
* @param zone The time zone for the new calendar.
* @param aLocale The locale for the new calendar.
*/
public EthiopicCalendar(TimeZone zone, Locale aLocale) {
this(zone, ULocale.forLocale(aLocale));
}
/**
* Constructs a EthiopicCalendar
based on the current time
* in the given time zone with the given locale.
*
* @param zone The time zone for the new calendar.
* @param locale The icu locale for the new calendar.
*/
public EthiopicCalendar(TimeZone zone, ULocale locale) {
super(zone, locale);
setCalcTypeForLocale(locale);
}
/**
* Constructs a EthiopicCalendar
with the given date set
* in the default time zone with the default locale.
*
* @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 Meskerem.
* @param date The value used to set the calendar's {@link #DATE DATE} time field.
*/
public EthiopicCalendar(int year, int month, int date) {
super(year, month, date);
}
/**
* Constructs a EthiopicCalendar
with the given date set
* in the default time zone with the default locale.
*
* @param date The date to which the new calendar is set.
*/
public EthiopicCalendar(Date date) {
super(date);
}
/**
* Constructs a EthiopicCalendar
with the given date
* and time set for the default time zone with the default locale.
*
* @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 Meskerem.
* @param date The value used to set the calendar's {@link #DATE DATE} time field.
* @param hour The value used to set the calendar's {@link #HOUR_OF_DAY HOUR_OF_DAY} time field.
* @param minute The value used to set the calendar's {@link #MINUTE MINUTE} time field.
* @param second The value used to set the calendar's {@link #SECOND SECOND} time field.
*/
public EthiopicCalendar(int year, int month, int date, int hour,
int minute, int second)
{
super(year, month, date, hour, minute, second);
}
/**
* {@inheritDoc}
*/
@Override
public String getType() {
if (isAmeteAlemEra()) {
return "ethiopic-amete-alem";
}
return "ethiopic";
}
/**
* Set Alem or Mihret era.
*
* @param onOff Set Amete Alem era if true, otherwise set Amete Mihret era.
*/
public void setAmeteAlemEra(boolean onOff) {
eraType = onOff ? AMETE_ALEM_ERA : AMETE_MIHRET_ERA;
}
/**
* Return true if this calendar is set to the Amete Alem era.
*
* @return true if set to the Amete Alem era.
*/
public boolean isAmeteAlemEra() {
return (eraType == AMETE_ALEM_ERA);
}
/**
* {@inheritDoc}
* @deprecated This API is ICU internal only.
* @hide draft / provisional / internal are hidden on Android
*/
@Override
@Deprecated
protected int handleGetExtendedYear() {
// Ethiopic calendar uses EXTENDED_YEAR aligned to
// Amelete Mihret year always.
int eyear;
if (newerField(EXTENDED_YEAR, YEAR) == EXTENDED_YEAR) {
eyear = internalGet(EXTENDED_YEAR, 1); // Default to year 1
} else if (isAmeteAlemEra()){
eyear = internalGet(YEAR, 1 + AMETE_MIHRET_DELTA)
- AMETE_MIHRET_DELTA; // Default to year 1 of Amelete Mihret
} else {
// The year defaults to the epoch start, the era to AMETE_MIHRET
int era = internalGet(ERA, AMETE_MIHRET);
if (era == AMETE_MIHRET) {
eyear = internalGet(YEAR, 1); // Default to year 1
} else {
eyear = internalGet(YEAR, 1) - AMETE_MIHRET_DELTA;
}
}
return eyear;
}
/**
* {@inheritDoc}
* @deprecated This API is ICU internal only.
* @hide draft / provisional / internal are hidden on Android
*/
@Override
@Deprecated
protected void handleComputeFields(int julianDay) {
int era, year;
int[] fields = new int[3];
jdToCE(julianDay, getJDEpochOffset(), fields);
// fields[0] eyear
// fields[1] month
// fields[2] day
if (isAmeteAlemEra()) {
era = AMETE_ALEM;
year = fields[0] + AMETE_MIHRET_DELTA;
} else {
if (fields[0] > 0) {
era = AMETE_MIHRET;
year = fields[0];
} else {
era = AMETE_ALEM;
year = fields[0] + AMETE_MIHRET_DELTA;
}
}
internalSet(EXTENDED_YEAR, fields[0]);
internalSet(ERA, era);
internalSet(YEAR, year);
internalSet(MONTH, fields[1]);
internalSet(ORDINAL_MONTH, fields[1]);
internalSet(DAY_OF_MONTH, fields[2]);
internalSet(DAY_OF_YEAR, (30 * fields[1]) + fields[2]);
}
/**
* {@inheritDoc}
* @deprecated This API is ICU internal only.
* @hide draft / provisional / internal are hidden on Android
*/
@Override
@Deprecated
protected int handleGetLimit(int field, int limitType) {
if (isAmeteAlemEra() && field == ERA) {
return 0; // Only one era in this mode, era is always 0
}
return super.handleGetLimit(field, limitType);
}
/**
* {@inheritDoc}
* @deprecated This API is ICU internal only.
* @hide draft / provisional / internal are hidden on Android
*/
@Override
@Deprecated
protected int getJDEpochOffset() {
return JD_EPOCH_OFFSET_AMETE_MIHRET;
}
/**
* Convert an Ethiopic year, month, and day to a Julian day.
*
* @param year the year
* @param month the month
* @param date the day
*
* @hide draft / provisional / internal are hidden on Android
*/
// The equivalent operation can be done by public Calendar API.
// This API was accidentally marked as @draft, but we have no good
// reason to keep this. For now, we leave it as is, but may be
// removed in future. 2008-03-21 yoshito
public static int EthiopicToJD(long year, int month, int date) {
return ceToJD(year, month, date, JD_EPOCH_OFFSET_AMETE_MIHRET);
}
/**
* set type based on locale
*/
private void setCalcTypeForLocale(ULocale locale) {
String localeCalType = CalendarUtil.getCalendarType(locale);
if("ethiopic-amete-alem".equals(localeCalType)) {
setAmeteAlemEra(true);
} else {
setAmeteAlemEra(false); // default - Amete Mihret
}
}
}