/* ******************************************************************************* * Copyright (C) 2005-2008, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ package com.ibm.icu.util; import java.util.Date; import java.util.Locale; /** * Implement the Ethiopic calendar system. *
* EthiopicCalendar usually should be instantiated using
* {@link com.ibm.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.
* @stable ICU 3.4
*/
public EthiopicCalendar() {
super();
}
/**
* 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.
* @stable ICU 3.4
*/
public EthiopicCalendar(TimeZone zone) {
super(zone);
}
/**
* 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.
* @stable ICU 3.4
*/
public EthiopicCalendar(Locale aLocale) {
super(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.
* @stable ICU 3.4
*/
public EthiopicCalendar(ULocale locale) {
super(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.
* @stable ICU 3.4
*/
public EthiopicCalendar(TimeZone zone, Locale aLocale) {
super(zone, 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.
* @stable ICU 3.4
*/
public EthiopicCalendar(TimeZone zone, ULocale locale) {
super(zone, 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.
* @stable ICU 3.4
*/
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.
* @stable ICU 3.4
*/
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.
* @stable ICU 3.4
*/
public EthiopicCalendar(int year, int month, int date, int hour,
int minute, int second)
{
super(year, month, date, hour, minute, second);
}
/**
* {@inheritDoc}
* @return type of calendar
* @stable ICU 3.8
*/
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.
* @stable ICU 3.4
*/
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.
* @stable ICU 3.4
*/
public boolean isAmeteAlemEra() {
return (eraType == AMETE_ALEM_ERA);
}
/**
* {@inheritDoc}
* @internal
* @deprecated This API is ICU internal only.
*/
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}
* @internal
* @deprecated This API is ICU internal only.
*/
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(DAY_OF_MONTH, fields[2]);
internalSet(DAY_OF_YEAR, (30 * fields[1]) + fields[2]);
}
/**
* {@inheritDoc}
* @internal
* @deprecated This API is ICU internal only.
*/
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}
* @internal
* @deprecated This API is ICU internal only.
*/
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
*
* @draft ICU 3.4 (retain)
* @provisional This API might change or be removed in a future release.
*/
// 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);
}
}