Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

java.util.calendar

  Asked By: Bailey    Date: May 04    Category: Java    Views: 1469
  

I want to implement a persian calendar that extends
java.util.Calendar.

below there is a java code that conver persian date to Julian day and
reverse.
but i need an implemntation or java caledar htat perfomrs this
conversion.
can you help me?

======================SIMPLE CONVERSION============================
class MyConvertor{
...
.

private static boolean leap_persian(int year)
{
return ((((((year - ((year > 0) ? 474 : 473)) % 2820) + 474)
+ 38) * 682) % 2816) < 682;
}

// PERSIAN_TO_JD -- Determine Julian day from Persian date

private static double PERSIAN_EPOCH = 1948320.5;

private static double persian_to_jd(int year, int month, int day)
{
int epbase, epyear;

epbase = year - ((year >= 0) ? 474 : 473);
epyear = 474 + mod(epbase, 2820);

return day +
((month <= 7) ?
((month - 1) * 31) :
(((month - 1) * 30) + 6)
) +
Math.floor(((epyear * 682) - 110) / 2816) +
(epyear - 1) * 365 +
Math.floor(epbase / 2820) * 1029983 +
(PERSIAN_EPOCH - 1);
}

// JD_TO_PERSIAN -- Calculate Persian date from Julian day

private static int[] jd_to_persian(double jd)
{
double year, month, day, depoch, cycle, cyear, ycycle,
aux1, aux2, yday;


jd = Math.floor(jd) + 0.5;

depoch = jd - persian_to_jd(475, 1, 1);
cycle = Math.floor(depoch / 1029983);
cyear = mod(depoch, 1029983);
if (cyear == 1029982) {
ycycle = 2820;
} else {
aux1 = Math.floor(cyear / 366);
aux2 = mod(cyear, 366);
ycycle = Math.floor(((2134 * aux1) + (2816 * aux2) +
2815) / 1028522) +
aux1 + 1;
}
year = ycycle + (2820 * cycle) + 474;
if (year <= 0) {
year--;
}
yday = (jd - persian_to_jd((int)year, 1, 1)) + 1;
month = (yday <= 186) ? Math.ceil(yday / 31) : Math.ceil
((yday - 6) / 30);
day = (jd - persian_to_jd((int)year, (int)month, 1)) + 1;
int[] result = new int[3];
result[0] = (int)year;
result[1] = (int)month;
result[2] = (int)day;
return result;
}

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on java.util.calendar Or get search suggestion and latest updates.




Tagged: