ICU-4082 Initial checkin of Indian Calendar.
X-SVN-Rev: 22016
This commit is contained in:
parent
2e968367ed
commit
da2d29fbc1
@ -67,7 +67,7 @@ ucurr.o digitlst.o fmtable_cnv.o \
|
||||
choicfmt.o datefmt.o smpdtfmt.o reldtfmt.o dtfmtsym.o udat.o \
|
||||
nfrs.o nfrule.o nfsubs.o rbnf.o ucsdet.o \
|
||||
ucal.o calendar.o gregocal.o timezone.o simpletz.o olsontz.o \
|
||||
astro.o taiwncal.o buddhcal.o persncal.o islamcal.o japancal.o gregoimp.o hebrwcal.o \
|
||||
astro.o taiwncal.o buddhcal.o persncal.o islamcal.o japancal.o gregoimp.o hebrwcal.o indiancal.o \
|
||||
coleitr.o coll.o tblcoll.o sortkey.o bocsu.o ucoleitr.o \
|
||||
ucol.o ucol_res.o ucol_bld.o ucol_sit.o ucol_tok.o ucol_wgt.o ucol_cnt.o ucol_elm.o \
|
||||
strmatch.o usearch.o search.o stsearch.o \
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1997-2006, International Business Machines Corporation and *
|
||||
* Copyright (C) 1997-2007, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
@ -36,6 +36,7 @@
|
||||
#include "islamcal.h"
|
||||
#include "hebrwcal.h"
|
||||
#include "persncal.h"
|
||||
#include "indiancal.h"
|
||||
//#include "chnsecal.h"
|
||||
#include "unicode/calendar.h"
|
||||
#include "cpputils.h"
|
||||
@ -140,6 +141,7 @@ static const char * const gCalendarKeywords[] = {
|
||||
"islamic",
|
||||
"hebrew",
|
||||
"chinese",
|
||||
"indian",
|
||||
NULL
|
||||
};
|
||||
|
||||
@ -196,6 +198,8 @@ static Calendar *createStandardCalendar(char *calType, const Locale &canLoc, UEr
|
||||
return new PersianCalendar(canLoc, status);
|
||||
//} else if(!uprv_strcmp(calType, "chinese")) {
|
||||
//return new ChineseCalendar(canLoc, status);
|
||||
} else if(!uprv_strcmp(calType, "indian")) {
|
||||
return new IndianCalendar(canLoc, status);
|
||||
} else {
|
||||
status = U_UNSUPPORTED_ERROR;
|
||||
return NULL;
|
||||
|
@ -530,14 +530,6 @@
|
||||
RelativePath=".\unicode\basictz.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\taiwncal.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\taiwncal.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\buddhcal.cpp"
|
||||
>
|
||||
@ -898,6 +890,14 @@
|
||||
RelativePath=".\hebrwcal.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\indiancal.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\indiancal.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\islamcal.cpp"
|
||||
>
|
||||
@ -1178,6 +1178,14 @@
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\taiwncal.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\taiwncal.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\timezone.cpp"
|
||||
>
|
||||
|
445
icu4c/source/i18n/indiancal.cpp
Normal file
445
icu4c/source/i18n/indiancal.cpp
Normal file
@ -0,0 +1,445 @@
|
||||
/*
|
||||
* Copyright (C) 2003-2007, International Business Machines Corporation
|
||||
* and others. All Rights Reserved.
|
||||
******************************************************************************
|
||||
*
|
||||
* File INDIANCAL.CPP
|
||||
*****************************************************************************
|
||||
*/
|
||||
|
||||
#include "indiancal.h"
|
||||
#include <stdlib.h>
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "mutex.h"
|
||||
#include <float.h>
|
||||
#include "gregoimp.h" // Math
|
||||
#include "astro.h" // CalendarAstronomer
|
||||
#include "uhash.h"
|
||||
#include "ucln_in.h"
|
||||
|
||||
// Debugging
|
||||
#ifdef U_DEBUG_INDIANCAL
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#endif
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
// Implementation of the IndianCalendar class
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Constructors...
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
|
||||
Calendar* IndianCalendar::clone() const {
|
||||
return new IndianCalendar(*this);
|
||||
}
|
||||
|
||||
IndianCalendar::IndianCalendar(const Locale& aLocale, UErrorCode& success)
|
||||
: Calendar(TimeZone::createDefault(), aLocale, success)
|
||||
{
|
||||
setTimeInMillis(getNow(), success); // Call this again now that the vtable is set up properly.
|
||||
}
|
||||
|
||||
IndianCalendar::IndianCalendar(const IndianCalendar& other) : Calendar(other) {
|
||||
}
|
||||
|
||||
IndianCalendar::~IndianCalendar()
|
||||
{
|
||||
}
|
||||
const char *IndianCalendar::getType() const {
|
||||
return "indian";
|
||||
}
|
||||
|
||||
static const int32_t LIMITS[UCAL_FIELD_COUNT][4] = {
|
||||
// Minimum Greatest Least Maximum
|
||||
// Minimum Maximum
|
||||
{ 0, 0, 0, 0 }, // ERA
|
||||
{ 1, 1, 5000000, 5000000 }, // YEAR
|
||||
{ 0, 0, 11, 11 }, // MONTH
|
||||
{ 1, 1, 52, 53 }, // WEEK_OF_YEAR
|
||||
{ 0, 0, 5, 6 }, // WEEK_OF_MONTH
|
||||
{ 1, 1, 30, 31 }, // DAY_OF_MONTH
|
||||
{ 1, 1, 365, 366 }, // DAY_OF_YEAR
|
||||
{/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DAY_OF_WEEK
|
||||
{ -1, -1, 4, 6 }, // DAY_OF_WEEK_IN_MONTH
|
||||
{/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // AM_PM
|
||||
{/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // HOUR
|
||||
{/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // HOUR_OF_DAY
|
||||
{/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MINUTE
|
||||
{/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // SECOND
|
||||
{/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MILLISECOND
|
||||
{/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // ZONE_OFFSET
|
||||
{/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DST_OFFSET
|
||||
{ 1, 1, 5000001, 5000001}, // YEAR_WOY
|
||||
{/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DOW_LOCAL
|
||||
{ 1, 1, 5000000, 5000000}, // EXTENDED_YEAR
|
||||
{/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // JULIAN_DAY
|
||||
{/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1} // MILLISECONDS_IN_DAY
|
||||
};
|
||||
|
||||
static const double JULIAN_EPOCH = 1721425.5;
|
||||
static const int32_t INDIAN_ERA_START = 78;
|
||||
static const int32_t INDIAN_YEAR_START = 80;
|
||||
|
||||
int32_t IndianCalendar::handleGetLimit(UCalendarDateFields field, ELimitType limitType) const {
|
||||
return LIMITS[field][limitType];
|
||||
}
|
||||
|
||||
/*
|
||||
* Determine whether the given gregorian year is a Leap year
|
||||
*/
|
||||
static UBool isGregorianLeap(int32_t year)
|
||||
{
|
||||
return ((year % 4) == 0) && (!(((year % 100) == 0) && ((year % 400) != 0)));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Calendar framework
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* Return the length (in days) of the given month.
|
||||
*
|
||||
* @param eyear The year in Saka Era
|
||||
* @param month The month(0-based) in Indian calendar
|
||||
*/
|
||||
int32_t IndianCalendar::handleGetMonthLength(int32_t eyear, int32_t month) const {
|
||||
if (month < 0 || month > 11) {
|
||||
eyear += Math::floorDivide(month, 12, month);
|
||||
}
|
||||
|
||||
if (isGregorianLeap(eyear + INDIAN_ERA_START) && month == 0) {
|
||||
return 31;
|
||||
}
|
||||
|
||||
if (month >= 1 && month <= 5) {
|
||||
return 31;
|
||||
}
|
||||
|
||||
return 30;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the number of days in the given Indian year
|
||||
*
|
||||
* @param eyear The year in Saka Era.
|
||||
*/
|
||||
int32_t IndianCalendar::handleGetYearLength(int32_t eyear) const {
|
||||
return isGregorianLeap(eyear + INDIAN_ERA_START) ? 366 : 365;
|
||||
}
|
||||
/*
|
||||
* Returns the Julian Day corresponding to gregorian date
|
||||
*
|
||||
* @param year The Gregorian year
|
||||
* @param month The month in Gregorian Year
|
||||
* @param date The date in Gregorian day in month
|
||||
*/
|
||||
static double gregorianToJD(int32_t year, int32_t month, int32_t date) {
|
||||
double julianDay = (JULIAN_EPOCH - 1) +
|
||||
(365 * (year - 1)) +
|
||||
uprv_floor((year - 1) / 4) +
|
||||
(-uprv_floor((year - 1) / 100)) +
|
||||
uprv_floor((year - 1) / 400) +
|
||||
uprv_floor((((367 * month) - 362) / 12) +
|
||||
((month <= 2) ? 0 :
|
||||
(isGregorianLeap(year) ? -1 : -2)
|
||||
) +
|
||||
date);
|
||||
|
||||
return julianDay;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the Gregorian Date corresponding to a given Julian Day
|
||||
* @param jd The Julian Day
|
||||
*/
|
||||
static int32_t* jdToGregorian(double jd, int32_t gregorianDate[3]) {
|
||||
double wjd, depoch, quadricent, dqc, cent, dcent, quad, dquad, yindex, yearday, leapadj;
|
||||
int32_t year, month, day;
|
||||
wjd = uprv_floor(jd - 0.5) + 0.5;
|
||||
depoch = wjd - JULIAN_EPOCH;
|
||||
quadricent = uprv_floor(depoch / 146097);
|
||||
dqc = (int32_t)uprv_floor(depoch) % 146097;
|
||||
cent = uprv_floor(dqc / 36524);
|
||||
dcent = (int32_t)uprv_floor(dqc) % 36524;
|
||||
quad = uprv_floor(dcent / 1461);
|
||||
dquad = (int32_t)uprv_floor(dcent) % 1461;
|
||||
yindex = uprv_floor(dquad / 365);
|
||||
year = (int32_t)((quadricent * 400) + (cent * 100) + (quad * 4) + yindex);
|
||||
if (!((cent == 4) || (yindex == 4))) {
|
||||
year++;
|
||||
}
|
||||
yearday = wjd - gregorianToJD(year, 1, 1);
|
||||
leapadj = ((wjd < gregorianToJD(year, 3, 1)) ? 0
|
||||
:
|
||||
(isGregorianLeap(year) ? 1 : 2)
|
||||
);
|
||||
month = (int32_t)uprv_floor((((yearday + leapadj) * 12) + 373) / 367);
|
||||
day = (int32_t)(wjd - gregorianToJD(year, month, 1)) + 1;
|
||||
|
||||
gregorianDate[0] = year;
|
||||
gregorianDate[1] = month;
|
||||
gregorianDate[2] = day;
|
||||
|
||||
return gregorianDate;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Functions for converting from field values to milliseconds....
|
||||
//-------------------------------------------------------------------------
|
||||
static double IndianToJD(int32_t year, int32_t month, int32_t date) {
|
||||
int32_t leapMonth, gyear, m;
|
||||
double start, jd;
|
||||
|
||||
gyear = year + INDIAN_ERA_START;
|
||||
|
||||
|
||||
if(isGregorianLeap(gyear)) {
|
||||
leapMonth = 31;
|
||||
start = gregorianToJD(gyear, 3, 21);
|
||||
}
|
||||
else {
|
||||
leapMonth = 30;
|
||||
start = gregorianToJD(gyear, 3, 22);
|
||||
}
|
||||
|
||||
if (month == 1) {
|
||||
jd = start + (date - 1);
|
||||
} else {
|
||||
jd = start + leapMonth;
|
||||
m = month - 2;
|
||||
|
||||
//m = Math.min(m, 5);
|
||||
if (m > 5) {
|
||||
m = 5;
|
||||
}
|
||||
|
||||
jd += m * 31;
|
||||
|
||||
if (month >= 8) {
|
||||
m = month - 7;
|
||||
jd += m * 30;
|
||||
}
|
||||
jd += date - 1;
|
||||
}
|
||||
|
||||
return jd;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return JD of start of given month/year of Indian Calendar
|
||||
* @param eyear The year in Indian Calendar measured from Saka Era (78 AD).
|
||||
* @param month The month in Indian calendar
|
||||
*/
|
||||
int32_t IndianCalendar::handleComputeMonthStart(int32_t eyear, int32_t month, UBool useMonth) const {
|
||||
|
||||
//month is 0 based; converting it to 1-based
|
||||
int32_t imonth;
|
||||
|
||||
// If the month is out of range, adjust it into range, and adjust the extended eyar accordingly
|
||||
if (month < 0 || month > 11) {
|
||||
eyear += (int32_t)Math::floorDivide(month, 12, month);
|
||||
}
|
||||
|
||||
if(month == 12){
|
||||
imonth = 1;
|
||||
} else {
|
||||
imonth = month + 1;
|
||||
}
|
||||
|
||||
double jd = IndianToJD(eyear ,imonth, 1);
|
||||
|
||||
return (int32_t)jd;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Functions for converting from milliseconds to field values
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
int32_t IndianCalendar::handleGetExtendedYear() {
|
||||
int32_t year;
|
||||
|
||||
if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) {
|
||||
year = internalGet(UCAL_EXTENDED_YEAR, 1); // Default to year 1
|
||||
} else {
|
||||
year = internalGet(UCAL_YEAR, 1); // Default to year 1
|
||||
}
|
||||
|
||||
return year;
|
||||
}
|
||||
|
||||
/*
|
||||
* Override Calendar to compute several fields specific to the Indian
|
||||
* calendar system. These are:
|
||||
*
|
||||
* <ul><li>ERA
|
||||
* <li>YEAR
|
||||
* <li>MONTH
|
||||
* <li>DAY_OF_MONTH
|
||||
* <li>EXTENDED_YEAR</ul>
|
||||
*
|
||||
* The DAY_OF_WEEK and DOW_LOCAL fields are already set when this
|
||||
* method is called. The getGregorianXxx() methods return Gregorian
|
||||
* calendar equivalents for the given Julian day.
|
||||
*/
|
||||
void IndianCalendar::handleComputeFields(int32_t julianDay, UErrorCode& status) {
|
||||
double jdAtStartOfGregYear;
|
||||
int32_t leapMonth, IndianYear, yday, IndianMonth, IndianDayOfMonth, mday;
|
||||
int32_t gregorianYear; // Stores gregorian date corresponding to Julian day;
|
||||
int32_t gd[3];
|
||||
|
||||
gregorianYear = jdToGregorian(julianDay, gd)[0]; // Gregorian date for Julian day
|
||||
IndianYear = gregorianYear - INDIAN_ERA_START; // Year in Saka era
|
||||
jdAtStartOfGregYear = gregorianToJD(gregorianYear, 1, 1); // JD at start of Gregorian year
|
||||
yday = (int32_t)(julianDay - jdAtStartOfGregYear); // Day number in Gregorian year (starting from 0)
|
||||
leapMonth = isGregorianLeap(gregorianYear) ? 31 : 30; // Days in leapMonth this year
|
||||
|
||||
if (yday < INDIAN_YEAR_START) {
|
||||
// Day is at the end of the preceding Saka year
|
||||
IndianYear -= 1;
|
||||
yday += leapMonth + (31 * 5) + (30 * 3) + 10 + INDIAN_YEAR_START;
|
||||
}
|
||||
|
||||
yday -= INDIAN_YEAR_START;
|
||||
if (yday < leapMonth) {
|
||||
IndianMonth = 0;
|
||||
IndianDayOfMonth = yday + 1;
|
||||
} else {
|
||||
mday = yday - leapMonth;
|
||||
if (mday < (31 * 5)) {
|
||||
IndianMonth = (int32_t)uprv_floor(mday / 31) + 1;
|
||||
IndianDayOfMonth = (mday % 31) + 1;
|
||||
} else {
|
||||
mday -= 31 * 5;
|
||||
IndianMonth = (int32_t)uprv_floor(mday / 30) + 6;
|
||||
IndianDayOfMonth = (mday % 30) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
internalSet(UCAL_ERA, 0);
|
||||
internalSet(UCAL_EXTENDED_YEAR, IndianYear);
|
||||
internalSet(UCAL_YEAR, IndianYear);
|
||||
internalSet(UCAL_MONTH, IndianMonth);
|
||||
internalSet(UCAL_DAY_OF_MONTH, IndianDayOfMonth );
|
||||
}
|
||||
|
||||
UBool
|
||||
IndianCalendar::inDaylightTime(UErrorCode& status) const
|
||||
{
|
||||
// copied from GregorianCalendar
|
||||
if (U_FAILURE(status) || !getTimeZone().useDaylightTime()) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Force an update of the state of the Calendar.
|
||||
((IndianCalendar*)this)->complete(status); // cast away const
|
||||
|
||||
return (UBool)(U_SUCCESS(status) ? (internalGet(UCAL_DST_OFFSET) != 0) : FALSE);
|
||||
}
|
||||
|
||||
// default century
|
||||
const UDate IndianCalendar::fgSystemDefaultCentury = DBL_MIN;
|
||||
const int32_t IndianCalendar::fgSystemDefaultCenturyYear = -1;
|
||||
|
||||
UDate IndianCalendar::fgSystemDefaultCenturyStart = DBL_MIN;
|
||||
int32_t IndianCalendar::fgSystemDefaultCenturyStartYear = -1;
|
||||
|
||||
|
||||
UBool IndianCalendar::haveDefaultCentury() const
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
UDate IndianCalendar::defaultCenturyStart() const
|
||||
{
|
||||
return internalGetDefaultCenturyStart();
|
||||
}
|
||||
|
||||
int32_t IndianCalendar::defaultCenturyStartYear() const
|
||||
{
|
||||
return internalGetDefaultCenturyStartYear();
|
||||
}
|
||||
|
||||
UDate
|
||||
IndianCalendar::internalGetDefaultCenturyStart() const
|
||||
{
|
||||
// lazy-evaluate systemDefaultCenturyStart
|
||||
UBool needsUpdate;
|
||||
{
|
||||
Mutex m;
|
||||
needsUpdate = (fgSystemDefaultCenturyStart == fgSystemDefaultCentury);
|
||||
}
|
||||
|
||||
if (needsUpdate) {
|
||||
initializeSystemDefaultCentury();
|
||||
}
|
||||
|
||||
// use defaultCenturyStart unless it's the flag value;
|
||||
// then use systemDefaultCenturyStart
|
||||
|
||||
return fgSystemDefaultCenturyStart;
|
||||
}
|
||||
|
||||
int32_t
|
||||
IndianCalendar::internalGetDefaultCenturyStartYear() const
|
||||
{
|
||||
// lazy-evaluate systemDefaultCenturyStartYear
|
||||
UBool needsUpdate;
|
||||
{
|
||||
Mutex m;
|
||||
|
||||
needsUpdate = (fgSystemDefaultCenturyStart == fgSystemDefaultCentury);
|
||||
}
|
||||
|
||||
if (needsUpdate) {
|
||||
initializeSystemDefaultCentury();
|
||||
}
|
||||
|
||||
// use defaultCenturyStart unless it's the flag value;
|
||||
// then use systemDefaultCenturyStartYear
|
||||
|
||||
return fgSystemDefaultCenturyStartYear;
|
||||
}
|
||||
|
||||
void
|
||||
IndianCalendar::initializeSystemDefaultCentury()
|
||||
{
|
||||
// initialize systemDefaultCentury and systemDefaultCenturyYear based
|
||||
// on the current time. They'll be set to 80 years before
|
||||
// the current time.
|
||||
// No point in locking as it should be idempotent.
|
||||
if (fgSystemDefaultCenturyStart == fgSystemDefaultCentury) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
||||
IndianCalendar calendar(Locale("@calendar=Indian"),status);
|
||||
if (U_SUCCESS(status)) {
|
||||
calendar.setTime(Calendar::getNow(), status);
|
||||
calendar.add(UCAL_YEAR, -80, status);
|
||||
|
||||
UDate newStart = calendar.getTime(status);
|
||||
int32_t newYear = calendar.get(UCAL_YEAR, status);
|
||||
|
||||
{
|
||||
Mutex m;
|
||||
|
||||
fgSystemDefaultCenturyStart = newStart;
|
||||
fgSystemDefaultCenturyStartYear = newYear;
|
||||
}
|
||||
}
|
||||
|
||||
// We have no recourse upon failure unless we want to propagate the failure
|
||||
// out.
|
||||
}
|
||||
}
|
||||
|
||||
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(IndianCalendar)
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
371
icu4c/source/i18n/indiancal.h
Normal file
371
icu4c/source/i18n/indiancal.h
Normal file
@ -0,0 +1,371 @@
|
||||
/*
|
||||
* Copyright (C) 2003-2007, International Business Machines Corporation
|
||||
* and others. All Rights Reserved.
|
||||
******************************************************************************
|
||||
*
|
||||
* File INDIANCAL.H
|
||||
*****************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef INDIANCAL_H
|
||||
#define INDIANCAL_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/calendar.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* Concrete class which provides the Indian calendar.
|
||||
* <P>
|
||||
* <code>IndianCalendar</code> is a subclass of <code>Calendar</code>
|
||||
* that numbers years since the begining of SAKA ERA. This is the civil calendar
|
||||
* which is accepted by government of India as Indian National Calendar.
|
||||
* The two calendars most widely used in India today are the Vikrama calendar
|
||||
* followed in North India and the Shalivahana or Saka calendar which is followed
|
||||
* in South India and Maharashtra.
|
||||
|
||||
* A variant of the Shalivahana Calendar was reformed and standardized as the
|
||||
* Indian National calendar in 1957.
|
||||
* <p>
|
||||
* Some details of Indian National Calendar (to be implemented) :
|
||||
* The Months
|
||||
* Month Length Start date (Gregorian)
|
||||
* =================================================
|
||||
* 1 Chaitra 30/31 March 22*
|
||||
* 2 Vaisakha 31 April 21
|
||||
* 3 Jyaistha 31 May 22
|
||||
* 4 Asadha 31 June 22
|
||||
* 5 Sravana 31 July 23
|
||||
* 6 Bhadra 31 August 23
|
||||
* 7 Asvina 30 September 23
|
||||
* 8 Kartika 30 October 23
|
||||
* 9 Agrahayana 30 November 22
|
||||
* 10 Pausa 30 December 22
|
||||
* 11 Magha 30 January 21
|
||||
* 12 Phalguna 30 February 20
|
||||
|
||||
* In leap years, Chaitra has 31 days and starts on March 21 instead.
|
||||
* The leap years of Gregorian calendar and Indian National Calendar are in synchornization.
|
||||
* So When its a leap year in Gregorian calendar then Chaitra has 31 days.
|
||||
*
|
||||
* The Years
|
||||
* Years are counted in the Saka Era, which starts its year 0 in 78AD (by gregorian calendar).
|
||||
* So for eg. 9th June 2006 by Gregorian Calendar, is same as 19th of Jyaistha in 1928 of Saka
|
||||
* era by Indian National Calendar.
|
||||
* <p>
|
||||
* The Indian Calendar has only one allowable era: <code>Saka Era</code>. If the
|
||||
* calendar is not in lenient mode (see <code>setLenient</code>), dates before
|
||||
* 1/1/1 Saka Era are rejected with an <code>IllegalArgumentException</code>.
|
||||
* <p>
|
||||
* @internal
|
||||
*/
|
||||
|
||||
|
||||
class U_I18N_API IndianCalendar : public Calendar {
|
||||
public:
|
||||
/**
|
||||
* Useful constants for IndianCalendar.
|
||||
* @internal
|
||||
*/
|
||||
enum EEras {
|
||||
/**
|
||||
* Constant for Chaitra, the 1st month of the Indian year.
|
||||
*/
|
||||
CHAITRA,
|
||||
|
||||
/**
|
||||
* Constant for Vaisakha, the 2nd month of the Indian year.
|
||||
*/
|
||||
VAISAKHA,
|
||||
|
||||
/**
|
||||
* Constant for Jyaistha, the 3rd month of the Indian year.
|
||||
*/
|
||||
JYAISTHA,
|
||||
|
||||
/**
|
||||
* Constant for Asadha, the 4th month of the Indian year.
|
||||
*/
|
||||
ASADHA,
|
||||
|
||||
/**
|
||||
* Constant for Sravana, the 5th month of the Indian year.
|
||||
*/
|
||||
SRAVANA,
|
||||
|
||||
/**
|
||||
* Constant for Bhadra the 6th month of the Indian year
|
||||
*/
|
||||
BHADRA,
|
||||
|
||||
/**
|
||||
* Constant for the Asvina, the 7th month of the Indian year.
|
||||
*/
|
||||
ASVINA,
|
||||
|
||||
/**
|
||||
* Constant for Kartika, the 8th month of the Indian year.
|
||||
*/
|
||||
KARTIKA,
|
||||
|
||||
/**
|
||||
* Constant for Agrahayana, the 9th month of the Indian year.
|
||||
*/
|
||||
AGRAHAYANA,
|
||||
|
||||
/**
|
||||
* Constant for Pausa, the 10th month of the Indian year.
|
||||
*/
|
||||
PAUSA,
|
||||
|
||||
/**
|
||||
* Constant for Magha, the 11th month of the Indian year.
|
||||
*/
|
||||
MAGHA,
|
||||
|
||||
/**
|
||||
* Constant for Phalguna, the 12th month of the Indian year.
|
||||
*/
|
||||
PHALGUNA
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Constructors...
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs an IndianCalendar based on the current time in the default time zone
|
||||
* with the given locale.
|
||||
*
|
||||
* @param aLocale The given locale.
|
||||
* @param success Indicates the status of IndianCalendar object construction.
|
||||
* Returns U_ZERO_ERROR if constructed successfully.
|
||||
* @param beCivil Whether the calendar should be civil (default-TRUE) or religious (FALSE)
|
||||
* @internal
|
||||
*/
|
||||
IndianCalendar(const Locale& aLocale, UErrorCode &success);
|
||||
|
||||
/**
|
||||
* Copy Constructor
|
||||
* @internal
|
||||
*/
|
||||
IndianCalendar(const IndianCalendar& other);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @internal
|
||||
*/
|
||||
virtual ~IndianCalendar();
|
||||
|
||||
/**
|
||||
* Determines whether this object uses the fixed-cycle Indian civil calendar
|
||||
* or an approximation of the religious, astronomical calendar.
|
||||
*
|
||||
* @param beCivil <code>CIVIL</code> to use the civil calendar,
|
||||
* <code>ASTRONOMICAL</code> to use the astronomical calendar.
|
||||
* @internal
|
||||
*/
|
||||
//void setCivil(ECivil beCivil, UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if this object is using the fixed-cycle civil
|
||||
* calendar, or <code>false</code> if using the religious, astronomical
|
||||
* calendar.
|
||||
* @internal
|
||||
*/
|
||||
//UBool isCivil();
|
||||
|
||||
|
||||
// TODO: copy c'tor, etc
|
||||
|
||||
// clone
|
||||
virtual Calendar* clone() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Determine whether a year is the gregorian year a leap year
|
||||
*/
|
||||
//static UBool isGregorianLeap(int32_t year);
|
||||
//----------------------------------------------------------------------
|
||||
// Calendar framework
|
||||
//----------------------------------------------------------------------
|
||||
protected:
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
|
||||
|
||||
/**
|
||||
* Return the length (in days) of the given month.
|
||||
*
|
||||
* @param year The year in Saka era
|
||||
* @param year The month(0-based) in Indian year
|
||||
* @internal
|
||||
*/
|
||||
virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const;
|
||||
|
||||
/**
|
||||
* Return the number of days in the given Indian year
|
||||
* @internal
|
||||
*/
|
||||
virtual int32_t handleGetYearLength(int32_t extendedYear) const;
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Functions for converting from field values to milliseconds....
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
// Return JD of start of given month/year
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month, UBool useMonth) const;
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Functions for converting from milliseconds to field values
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
virtual int32_t handleGetExtendedYear();
|
||||
|
||||
/**
|
||||
* Override Calendar to compute several fields specific to the Indian
|
||||
* calendar system. These are:
|
||||
*
|
||||
* <ul><li>ERA
|
||||
* <li>YEAR
|
||||
* <li>MONTH
|
||||
* <li>DAY_OF_MONTH
|
||||
* <li>DAY_OF_YEAR
|
||||
* <li>EXTENDED_YEAR</ul>
|
||||
*
|
||||
* The DAY_OF_WEEK and DOW_LOCAL fields are already set when this
|
||||
* method is called. The getGregorianXxx() methods return Gregorian
|
||||
* calendar equivalents for the given Julian day.
|
||||
* @internal
|
||||
*/
|
||||
virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
|
||||
|
||||
// UObject stuff
|
||||
public:
|
||||
/**
|
||||
* @return The class ID for this object. All objects of a given class have the
|
||||
* same class ID. Objects of other classes have different class IDs.
|
||||
* @internal
|
||||
*/
|
||||
virtual UClassID getDynamicClassID(void) const;
|
||||
|
||||
/**
|
||||
* Return the class ID for this class. This is useful only for comparing to a return
|
||||
* value from getDynamicClassID(). For example:
|
||||
*
|
||||
* Base* polymorphic_pointer = createPolymorphicObject();
|
||||
* if (polymorphic_pointer->getDynamicClassID() ==
|
||||
* Derived::getStaticClassID()) ...
|
||||
*
|
||||
* @return The class ID for all objects of this class.
|
||||
* @internal
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID(void);
|
||||
|
||||
/**
|
||||
* return the calendar type, "buddhist".
|
||||
*
|
||||
* @return calendar type
|
||||
* @internal
|
||||
*/
|
||||
virtual const char * getType() const;
|
||||
|
||||
private:
|
||||
IndianCalendar(); // default constructor not implemented
|
||||
|
||||
// Default century.
|
||||
protected:
|
||||
|
||||
/**
|
||||
* (Overrides Calendar) Return true if the current date for this Calendar is in
|
||||
* Daylight Savings Time. Recognizes DST_OFFSET, if it is set.
|
||||
*
|
||||
* @param status Fill-in parameter which receives the status of this operation.
|
||||
* @return True if the current date for this Calendar is in Daylight Savings Time,
|
||||
* false, otherwise.
|
||||
* @internal
|
||||
*/
|
||||
virtual UBool inDaylightTime(UErrorCode& status) const;
|
||||
|
||||
|
||||
/**
|
||||
* Returns TRUE because the Indian Calendar does have a default century
|
||||
* @internal
|
||||
*/
|
||||
virtual UBool haveDefaultCentury() const;
|
||||
|
||||
/**
|
||||
* Returns the date of the start of the default century
|
||||
* @return start of century - in milliseconds since epoch, 1970
|
||||
* @internal
|
||||
*/
|
||||
virtual UDate defaultCenturyStart() const;
|
||||
|
||||
/**
|
||||
* Returns the year in which the default century begins
|
||||
* @internal
|
||||
*/
|
||||
virtual int32_t defaultCenturyStartYear() const;
|
||||
|
||||
private: // default century stuff.
|
||||
/**
|
||||
* The system maintains a static default century start date. This is initialized
|
||||
* the first time it is used. Before then, it is set to SYSTEM_DEFAULT_CENTURY to
|
||||
* indicate an uninitialized state. Once the system default century date and year
|
||||
* are set, they do not change.
|
||||
*/
|
||||
static UDate fgSystemDefaultCenturyStart;
|
||||
|
||||
/**
|
||||
* See documentation for systemDefaultCenturyStart.
|
||||
*/
|
||||
static int32_t fgSystemDefaultCenturyStartYear;
|
||||
|
||||
/**
|
||||
* Default value that indicates the defaultCenturyStartYear is unitialized
|
||||
*/
|
||||
static const int32_t fgSystemDefaultCenturyYear;
|
||||
|
||||
/**
|
||||
* start of default century, as a date
|
||||
*/
|
||||
static const UDate fgSystemDefaultCentury;
|
||||
|
||||
/**
|
||||
* Returns the beginning date of the 100-year window that dates
|
||||
* with 2-digit years are considered to fall within.
|
||||
*/
|
||||
UDate internalGetDefaultCenturyStart(void) const;
|
||||
|
||||
/**
|
||||
* Returns the first year of the 100-year window that dates with
|
||||
* 2-digit years are considered to fall within.
|
||||
*/
|
||||
int32_t internalGetDefaultCenturyStartYear(void) const;
|
||||
|
||||
/**
|
||||
* Initializes the 100-year window that dates with 2-digit years
|
||||
* are considered to fall within so that its start date is 80 years
|
||||
* before the current time.
|
||||
*/
|
||||
static void initializeSystemDefaultCentury(void);
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user