diff options
author | Santhosh Thottingal <santhosh.thottingal@gmail.com> | 2008-12-13 11:04:06 +0530 |
---|---|---|
committer | Santhosh Thottingal <santhosh.thottingal@gmail.com> | 2008-12-13 11:04:06 +0530 |
commit | ffd8c66d49633752d9484e6c3a2482c8589800c6 (patch) | |
tree | 1b188e3fa72930be26344a88e50f8b62a8488fe0 | |
parent | dcd609cac5443ce7844ef8b48d71acd8a3f3bb8e (diff) | |
download | Rachana.git-ffd8c66d49633752d9484e6c3a2482c8589800c6.tar.gz Rachana.git-ffd8c66d49633752d9484e6c3a2482c8589800c6.tar.xz Rachana.git-ffd8c66d49633752d9484e6c3a2482c8589800c6.zip |
Adding the caledar code
17 files changed, 2949 insertions, 0 deletions
diff --git a/calendar/java/src/org/panchanga/common/FixedVector.java b/calendar/java/src/org/panchanga/common/FixedVector.java new file mode 100755 index 0000000..52329bc --- /dev/null +++ b/calendar/java/src/org/panchanga/common/FixedVector.java @@ -0,0 +1,40 @@ +/*jadclipse*/// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
+// Jad home page: http://www.kpdus.com/jad.html
+// Decompiler options: packimports(3) radix(10) lradix(10)
+// Source File Name: FixedVector.java
+
+package org.panchanga.common;
+
+import java.util.Vector;
+
+public class FixedVector extends Vector
+{
+
+ public FixedVector(int initialCapacity, int capacityIncrement)
+ {
+ super(initialCapacity, capacityIncrement);
+ }
+
+ public FixedVector(int initialCapacity)
+ {
+ super(initialCapacity);
+ }
+
+ public FixedVector()
+ {
+ }
+
+ public final synchronized void addFixed(int fixed)
+ {
+ super.addElement(new Integer(fixed));
+ }
+
+ public final synchronized int fixedAt(int index)
+ {
+ return ((Integer)super.elementAt(index)).intValue();
+ }
+}
+
+
+
+
\ No newline at end of file diff --git a/calendar/java/src/org/panchanga/common/ISO.java b/calendar/java/src/org/panchanga/common/ISO.java new file mode 100755 index 0000000..4da84b0 --- /dev/null +++ b/calendar/java/src/org/panchanga/common/ISO.java @@ -0,0 +1,82 @@ +
+package org.panchanga.common;
+
+import org.panchanga.common.exception.BogusDateException;
+import org.panchanga.gregorian.Gregorian;
+
+
+// Referenced classes of package calendrica:
+// Date, BogusDateException, Gregorian, ProtoDate
+
+public class ISO extends Date
+{
+
+ public ISO()
+ {
+ }
+
+ public ISO(int date)
+ {
+ super(date);
+ }
+
+ public ISO(Date date)
+ throws BogusDateException
+ {
+ super(date);
+ }
+
+ public ISO(int week, int day, int year)
+ {
+ this.week = week;
+ this.day = day;
+ this.year = year;
+ }
+
+ public static int toFixed(int week, int day, int year)
+ {
+ return ProtoDate.nthKDay(week, 0, Gregorian.toFixed(12, 28, year - 1)) + day;
+ }
+
+ public int toFixed()
+ {
+ return toFixed(week, day, year);
+ }
+
+ public void fromFixed(int date)
+ {
+ int approx = Gregorian.yearFromFixed(date - 3);
+ year = date < toFixed(1, 1, approx + 1) ? approx : approx + 1;
+ week = ProtoDate.quotient(date - toFixed(1, 1, year), 7D) + 1;
+ day = ProtoDate.adjustedMod(date, 7);
+ }
+
+ public void fromArray(int a[])
+ {
+ week = a[0];
+ day = a[1];
+ year = a[2];
+ }
+
+ protected String toStringFields()
+ {
+ return "week=" + week + ",day=" + day + ",year=" + year;
+ }
+
+ public boolean equals(Object obj)
+ {
+ if(this == obj)
+ return true;
+ if(!(obj instanceof ISO))
+ return false;
+ ISO o = (ISO)obj;
+ return o.week == week && o.day == day && o.year == year;
+ }
+
+ public int week;
+ public int day;
+ public int year;
+}
+
+
+
\ No newline at end of file diff --git a/calendar/java/src/org/panchanga/common/Julian.java b/calendar/java/src/org/panchanga/common/Julian.java new file mode 100755 index 0000000..d00e7db --- /dev/null +++ b/calendar/java/src/org/panchanga/common/Julian.java @@ -0,0 +1,125 @@ +
+package org.panchanga.common;
+
+import org.panchanga.common.exception.BogusDateException;
+import org.panchanga.gregorian.Gregorian;
+
+
+// Referenced classes of package calendrica:
+// StandardDate, Gregorian, BogusDateException, ProtoDate,
+// FixedVector, Date
+
+public class Julian extends StandardDate
+{
+
+ public Julian()
+ {
+ }
+
+ public Julian(int date)
+ {
+ super(date);
+ }
+
+ public Julian(Date date)
+ throws BogusDateException
+ {
+ super(date);
+ }
+
+ public Julian(int month, int day, int year)
+ {
+ super(month, day, year);
+ }
+
+ public static int toFixed(int month, int day, int year)
+ {
+ int y = year >= 0 ? year : year + 1;
+ return (EPOCH - 1) + 365 * (y - 1) + ProtoDate.quotient(y - 1, 4D) + ProtoDate.quotient(367 * month - 362, 12D) + (month > 2 ? isLeapYear(year) ? -1 : -2 : 0) + day;
+ }
+
+ public int toFixed()
+ {
+ return toFixed(super.month, super.day, super.year);
+ }
+
+ public void fromFixed(int date)
+ {
+ int approx = ProtoDate.quotient(4 * (date - EPOCH) + 1464, 1461D);
+ super.year = approx > 0 ? approx : approx - 1;
+ int priorDays = date - toFixed(1, 1, super.year);
+ int correction = date >= toFixed(3, 1, super.year) ? ((int) (isLeapYear(super.year) ? 1 : 2)) : 0;
+ super.month = ProtoDate.quotient(12 * (priorDays + correction) + 373, 367D);
+ super.day = (date - toFixed(super.month, 1, super.year)) + 1;
+ }
+
+ public static int BCE(int n)
+ {
+ return -n;
+ }
+
+ public static int CE(int n)
+ {
+ return n;
+ }
+
+ public static boolean isLeapYear(int jYear)
+ {
+ return ProtoDate.mod(jYear, 4) == (jYear <= 0 ? 3 : 0);
+ }
+
+ public static int nicaeanRuleEaster(int jYear)
+ {
+ int shiftedEpact = ProtoDate.mod(14 + 11 * ProtoDate.mod(jYear, 19), 30);
+ int paschalMoon = toFixed(4, 19, jYear) - shiftedEpact;
+ return ProtoDate.kDayAfter(paschalMoon, 0);
+ }
+
+ public static int easter(int gYear)
+ {
+ int century = 1 + ProtoDate.quotient(gYear, 100D);
+ int shiftedEpact = ProtoDate.mod(((14 + 11 * ProtoDate.mod(gYear, 19)) - ProtoDate.quotient(3 * century, 4D)) + ProtoDate.quotient(5 + 8 * century, 25D), 30);
+ int adjustedEpact = shiftedEpact != 0 && (shiftedEpact != 1 || 10 >= ProtoDate.mod(gYear, 19)) ? shiftedEpact : shiftedEpact + 1;
+ int paschalMoon = Gregorian.toFixed(4, 19, gYear) - adjustedEpact;
+ return ProtoDate.kDayAfter(paschalMoon, 0);
+ }
+
+ public static int pentecost(int gYear)
+ {
+ return easter(gYear) + 49;
+ }
+
+ public static FixedVector inGregorian(int jMonth, int jDay, int gYear)
+ {
+ int jan1 = Gregorian.toFixed(1, 1, gYear);
+ int dec31 = Gregorian.toFixed(12, 31, gYear);
+ int y = ((StandardDate) (new Julian(jan1))).year;
+ int date1 = toFixed(jMonth, jDay, y);
+ int date2 = toFixed(jMonth, jDay, y + 1);
+ FixedVector result = new FixedVector(1, 1);
+ if(jan1 <= date1 && date1 <= dec31)
+ result.addFixed(date1);
+ if(jan1 <= date2 && date2 <= dec31)
+ result.addFixed(date2);
+ return result;
+ }
+
+ public static FixedVector easternOrthodoxChristmas(int gYear)
+ {
+ return inGregorian(12, 25, gYear);
+ }
+
+ public boolean equals(Object obj)
+ {
+ if(!(obj instanceof Julian))
+ return false;
+ else
+ return internalEquals(obj);
+ }
+
+ public static final int EPOCH = Gregorian.toFixed(12, 30, 0);
+
+}
+
+
+
\ No newline at end of file diff --git a/calendar/java/src/org/panchanga/common/ProtoDate.java b/calendar/java/src/org/panchanga/common/ProtoDate.java new file mode 100755 index 0000000..d872a5c --- /dev/null +++ b/calendar/java/src/org/panchanga/common/ProtoDate.java @@ -0,0 +1,793 @@ +/*jadclipse*/// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
+// Jad home page: http://www.kpdus.com/jad.html
+// Decompiler options: packimports(3) radix(10) lradix(10)
+// Source File Name: ProtoDate.java
+
+package org.panchanga.common;
+
+import java.io.Serializable;
+
+import org.panchanga.common.exception.BogusDateException;
+import org.panchanga.gregorian.Gregorian;
+
+// Referenced classes of package calendrica:
+// Gregorian, BogusDateException, Date, StandardDate
+
+public abstract class ProtoDate
+ implements Cloneable, Serializable
+{
+ private static class ec
+ {
+
+ private static final double coeff19th[] = {
+ -2.0000000000000002E-005D, 0.00029700000000000001D, 0.025184000000000002D, -0.18113299999999999D, 0.55303999999999998D, -0.86193799999999998D, 0.67706599999999995D, -0.212591D
+ };
+ private static final double coeff18th[] = {
+ -9.0000000000000002E-006D, 0.0038440000000000002D, 0.083562999999999998D, 0.86573599999999995D, 4.8675750000000004D, 15.845535D, 31.332267000000002D, 38.291998999999997D, 28.316289000000001D, 11.636203999999999D,
+ 2.0437940000000001D
+ };
+ private static final double coeff17th[] = {
+ 196.58332999999999D, -4.0674999999999999D, 0.021916700000000001D
+ };
+
+
+
+
+
+ ec()
+ {
+ }
+ }
+
+ private static class et
+ {
+
+ private static final double coeffLongitude[] = {
+ 280.46645000000001D, 36000.769829999997D, 0.0003032D
+ };
+ private static final double coeffAnomaly[] = {
+ 357.52910000000003D, 35999.050300000003D, -0.00015589999999999999D, -4.7999999999999996E-007D
+ };
+ private static final double coeffInclination[] = {
+ 23.439291109999999D, -0.013004167000000001D, -1.6388999999999999E-007D, 5.0360000000000004E-007D
+ };
+ private static final double coeffEccentricity[] = {
+ 0.016708616999999999D, -4.2036999999999997E-005D, -1.236E-007D
+ };
+
+
+
+
+
+
+ et()
+ {
+ }
+ }
+
+ private static class sl
+ {
+
+ private static final int coefficients[] = {
+ 403406, 195207, 119433, 112392, 3891, 2819, 1721, 0, 660, 350,
+ 334, 314, 268, 242, 234, 158, 132, 129, 114, 99,
+ 93, 86, 78, 72, 68, 64, 46, 38, 37, 32,
+ 29, 28, 27, 27, 25, 24, 21, 21, 20, 18,
+ 17, 14, 13, 13, 13, 12, 10, 10, 10, 10
+ };
+ private static final double multipliers[] = {
+ 0.016210430000000001D, 628.30348067D, 628.30821523999998D, 628.29634301999999D, 1256.605691D, 1256.6098400000001D, 628.32476599999995D, 0.0081300000000000001D, 1256.5931D, 575.33849999999995D,
+ -0.33931D, 7771.3771500000003D, 786.04191000000003D, 0.054120000000000001D, 393.02098000000001D, -0.34860999999999998D, 1150.67698D, 157.74337D, 52.966700000000003D, 588.49270000000001D,
+ 52.961100000000002D, -39.807000000000002D, 522.37689999999998D, 550.76469999999995D, 2.6107999999999998D, 157.73849999999999D, 1884.9103D, -77.5655D, 2.6488999999999998D, 1179.0626999999999D,
+ 550.75750000000005D, -79.613900000000001D, 1884.8981000000001D, 21.321899999999999D, 1097.7103D, 548.68560000000002D, 254.4393D, -557.3143D, 606.97739999999999D, 21.3279D,
+ 1097.7163D, -77.528199999999998D, 1884.9191000000001D, 2.0781000000000001D, 294.24630000000002D, -0.079899999999999999D, 469.41140000000001D, -0.68289999999999995D, 214.63249999999999D, 1572.0840000000001D
+ };
+ private static final double addends[] = {
+ 4.7219639999999998D, 5.9374580000000003D, 1.1155889999999999D, 5.7816159999999996D, 5.5473999999999997D, 1.512D, 4.1897000000000002D, 1.163D, 5.415D, 4.3150000000000004D,
+ 4.5529999999999999D, 5.1980000000000004D, 5.9889999999999999D, 2.911D, 1.423D, 0.060999999999999999D, 2.3170000000000002D, 3.1930000000000001D, 2.8279999999999998D, 0.52000000000000002D,
+ 4.6500000000000004D, 4.3499999999999996D, 2.75D, 4.5D, 3.23D, 1.22D, 0.14000000000000001D, 3.4399999999999999D, 4.3700000000000001D, 1.1399999999999999D,
+ 2.8399999999999999D, 5.96D, 5.0899999999999999D, 1.72D, 2.5600000000000001D, 1.9199999999999999D, 0.089999999999999997D, 5.9800000000000004D, 4.0300000000000002D, 4.4699999999999998D,
+ 0.79000000000000004D, 4.2400000000000002D, 2.0099999999999998D, 2.6499999999999999D, 4.9800000000000004D, 0.93000000000000005D, 2.21D, 3.5899999999999999D, 1.5D, 2.5499999999999998D
+ };
+
+
+
+
+
+ sl()
+ {
+ }
+ }
+
+ private static class nu
+ {
+
+ private static final double coeffa[] = {
+ 124.90000000000001D, -1934.134D, 0.0020630000000000002D
+ };
+ private static final double coeffb[] = {
+ 201.11000000000001D, 72001.537700000001D, 0.00056999999999999998D
+ };
+
+
+
+
+ nu()
+ {
+ }
+ }
+
+ private static class ll
+ {
+
+ private static final double coeffMeanMoon[] = {
+ 218.3164591D, 481267.88134235999D, -0.0013267999999999999D, 1.855835023689734E-006D, -1.5338834862103876E-008D
+ };
+ private static final double coeffElongation[] = {
+ 297.85020420000001D, 445267.11151680001D, -0.0016299999999999999D, 1.8319447192361523E-006D, -8.8444699951355417E-009D
+ };
+ private static final double coeffSolarAnomaly[] = {
+ 357.52910919999999D, 35999.050290899999D, -0.00015359999999999999D, 4.0832993058391183E-008D
+ };
+ private static final double coeffLunarAnomaly[] = {
+ 134.96341140000001D, 477198.8676313D, 0.0089969999999999998D, 1.4347408140719379E-005D, -6.7971723762914631E-008D
+ };
+ private static final double coeffMoonFromNode[] = {
+ 93.272099299999994D, 483202.01752729999D, -0.0034028999999999999D, -2.8360748723766307E-007D, 1.1583324645839848E-009D
+ };
+ private static final double coeffE[] = {
+ 1.0D, -0.002516D, -7.4000000000000003E-006D
+ };
+ private static final byte argsLunarElongation[] = {
+ 0, 2, 2, 0, 0, 0, 2, 2, 2, 2,
+ 0, 1, 0, 2, 0, 0, 4, 0, 4, 2,
+ 2, 1, 1, 2, 2, 4, 2, 0, 2, 2,
+ 1, 2, 0, 0, 2, 2, 2, 4, 0, 3,
+ 2, 4, 0, 2, 2, 2, 4, 0, 4, 1,
+ 2, 0, 1, 3, 4, 2, 0, 1, 2, 2
+ };
+ private static final byte argsSolarAnomaly[] = {
+ 0, 0, 0, 0, 1, 0, 0, -1, 0, -1,
+ 1, 0, 1, 0, 0, 0, 0, 0, 0, 1,
+ 1, 0, 1, -1, 0, 0, 0, 1, 0, -1,
+ 0, -2, 1, 2, -2, 0, 0, -1, 0, 0,
+ 1, -1, 2, 2, 1, -1, 0, 0, -1, 0,
+ 1, 0, 1, 0, 0, -1, 2, 1, 0, 0
+ };
+ private static final byte argsLunarAnomaly[] = {
+ 1, -1, 0, 2, 0, 0, -2, -1, 1, 0,
+ -1, 0, 1, 0, 1, 1, -1, 3, -2, -1,
+ 0, -1, 0, 1, 2, 0, -3, -2, -1, -2,
+ 1, 0, 2, 0, -1, 1, 0, -1, 2, -1,
+ 1, -2, -1, -1, -2, 0, 1, 4, 0, -2,
+ 0, 2, 1, -2, -3, 2, 1, -1, 3, -1
+ };
+ private static final byte argsMoonFromNode[] = {
+ 0, 0, 0, 0, 0, 2, 0, 0, 0, 0,
+ 0, 0, 0, -2, 2, -2, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 2, 0,
+ 0, 0, 0, 0, 0, -2, 2, 0, 2, 0,
+ 0, 0, 0, 0, 0, -2, 0, 0, 0, 0,
+ -2, -2, 0, 0, 0, 0, 0, 0, 0, -2
+ };
+ private static final int sineCoefficients[] = {
+ 6288774, 1274027, 658314, 213618, -185116, -114332, 58793, 57066, 53322, 45758,
+ -40923, -34720, -30383, 15327, -12528, 10980, 10675, 10034, 8548, -7888,
+ -6766, -5163, 4987, 4036, 3994, 3861, 3665, -2689, -2602, 2390,
+ -2348, 2236, -2120, -2069, 2048, -1773, -1595, 1215, -1110, -892,
+ -810, 759, -713, -700, 691, 596, 549, 537, 520, -487,
+ -399, -381, 351, -340, 330, 327, -323, 299, 294, 0
+ };
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ll()
+ {
+ }
+ }
+
+ private static class nm
+ {
+
+ private static final double coeffJDE[] = {
+ 2451550.0976499999D, 36524.908822833051D, 0.0001337D, -1.4999999999999999E-007D, 7.2999999999999996E-010D
+ };
+ private static final double coeffE[] = {
+ 1.0D, -0.002516D, -7.4000000000000003E-006D
+ };
+ private static final double coeffSolarAnomaly[] = {
+ 2.5533999999999999D, 35998.960422026496D, -2.1800000000000001E-005D, -1.1000000000000001E-007D
+ };
+ private static final double coeffLunarAnomaly[] = {
+ 201.5643D, 477197.67640106793D, 0.0107438D, 1.239E-005D, -5.8000000000000003E-008D
+ };
+ private static final double coeffMoonArgument[] = {
+ 160.71080000000001D, 483200.81131396897D, -0.0016341000000000001D, -2.2699999999999999E-006D, 1.0999999999999999E-008D
+ };
+ private static final double coeffOmega[] = {
+ 124.77460000000001D, -1934.1313612299998D, 0.0020690999999999999D, 2.1500000000000002E-006D
+ };
+ private static final byte eFactor[] = {
+ 0, 1, 0, 0, 1, 1, 2, 0, 0, 1,
+ 0, 1, 1, 1, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0
+ };
+ private static final byte solarCoeff[] = {
+ 0, 1, 0, 0, -1, 1, 2, 0, 0, 1,
+ 0, 1, 1, -1, 2, 0, 3, 1, 0, 1,
+ -1, -1, 1, 0
+ };
+ private static final byte lunarCoeff[] = {
+ 1, 0, 2, 0, 1, 1, 0, 1, 1, 2,
+ 3, 0, 0, 2, 1, 2, 0, 1, 2, 1,
+ 1, 1, 3, 4
+ };
+ private static final byte moonCoeff[] = {
+ 0, 0, 0, 2, 0, 0, 0, -2, 2, 0,
+ 0, 2, -2, 0, 0, -2, 0, -2, 2, 2,
+ 2, -2, 0, 0
+ };
+ private static final double sineCoeff[] = {
+ -0.40720000000000001D, 0.17241000000000001D, 0.016080000000000001D, 0.01039D, 0.0073899999999999999D, -0.0051399999999999996D, 0.0020799999999999998D, -0.0011100000000000001D, -0.00056999999999999998D, 0.00055999999999999995D,
+ -0.00042000000000000002D, 0.00042000000000000002D, 0.00038000000000000002D, -0.00024000000000000001D, -6.9999999999999994E-005D, 4.0000000000000003E-005D, 4.0000000000000003E-005D, 3.0000000000000001E-005D, 3.0000000000000001E-005D, -3.0000000000000001E-005D,
+ 3.0000000000000001E-005D, -2.0000000000000002E-005D, -2.0000000000000002E-005D, 2.0000000000000002E-005D
+ };
+ private static final double addConst[] = {
+ 299.76999999999998D, 251.88D, 251.83000000000001D, 349.42000000000002D, 84.659999999999997D, 141.74000000000001D, 207.13999999999999D, 154.84D, 34.520000000000003D, 207.19D,
+ 291.33999999999997D, 161.72D, 239.56D, 331.55000000000001D
+ };
+ private static final double addCoeff[] = {
+ 0.107408D, 0.016320999999999999D, 26.641886D, 36.412478D, 18.206239D, 53.303770999999998D, 2.453732D, 7.3068600000000004D, 27.261239D, 0.121824D,
+ 1.844379D, 24.198153999999999D, 25.513099D, 3.5925180000000001D
+ };
+ private static final double addExtra[] = {
+ -0.0091730000000000006D, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0
+ };
+ private static final double addFactor[] = {
+ 0.00032499999999999999D, 0.000165D, 0.000164D, 0.000126D, 0.00011D, 6.2000000000000003E-005D, 6.0000000000000002E-005D, 5.5999999999999999E-005D, 4.6999999999999997E-005D, 4.1999999999999998E-005D,
+ 4.0000000000000003E-005D, 3.6999999999999998E-005D, 3.4999999999999997E-005D, 2.3E-005D
+ };
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ nm()
+ {
+ }
+ }
+
+ private static class sfj
+ {
+
+ private static final double siderealCoeff[] = {
+ 280.46061837000002D, 13185000.770053742D, 0.00038793299999999997D, 2.5833118057349522E-008D
+ };
+
+
+
+ sfj()
+ {
+ }
+ }
+
+
+ public ProtoDate()
+ {
+ }
+
+ public ProtoDate(int date)
+ {
+ fromFixed(date);
+ }
+
+ public ProtoDate(Date date)
+ throws BogusDateException
+ {
+ fromDate(date);
+ }
+
+ public abstract void fromFixed(int i);
+
+ public void fromDate(Date fromDate)
+ throws BogusDateException
+ {
+ convert(fromDate, this);
+ }
+
+ public abstract void fromArray(int ai[]);
+
+ public static void convert(Date fromDate, ProtoDate toDate)
+ throws BogusDateException
+ {
+ toDate.fromFixed(fromDate.toFixed());
+ }
+
+ public static int difference(Date date1, Date date2)
+ throws BogusDateException
+ {
+ return date2.toFixed() - date1.toFixed();
+ }
+
+ public static int difference(int date1, Date date2)
+ throws BogusDateException
+ {
+ return date2.toFixed() - date1;
+ }
+
+ public static int difference(Date date1, int date2)
+ throws BogusDateException
+ {
+ return date2 - date1.toFixed();
+ }
+
+ public static int difference(int date1, int date2)
+ {
+ return date2 - date1;
+ }
+
+ public static double mod(double x, double y)
+ {
+ return x - y * Math.floor(x / y);
+ }
+
+ public static int mod(int x, int y)
+ {
+ return (int)((double)x - (double)y * Math.floor((double)x / (double)y));
+ }
+
+ public static int quotient(double x, double y)
+ {
+ return (int)Math.floor(x / y);
+ }
+
+ public static int adjustedMod(int m, int n)
+ {
+ return mod(m - 1, n) + 1;
+ }
+
+ public static int dayOfWeekFromFixed(int date)
+ {
+ return mod(date, 7);
+ }
+
+ public static int kDayOnOrBefore(int date, int k)
+ {
+ return date - dayOfWeekFromFixed(date - k);
+ }
+
+ public static int kDayOnOrAfter(int date, int k)
+ {
+ return kDayOnOrBefore(date + 6, k);
+ }
+
+ public static int kDayNearest(int date, int k)
+ {
+ return kDayOnOrBefore(date + 3, k);
+ }
+
+ public static int kDayAfter(int date, int k)
+ {
+ return kDayOnOrBefore(date + 7, k);
+ }
+
+ public static int kDayBefore(int date, int k)
+ {
+ return kDayOnOrBefore(date - 1, k);
+ }
+
+ public static int nthKDay(int n, int k, int date)
+ {
+ return n <= 0 ? kDayAfter(date, k) + 7 * n : kDayBefore(date, k) + 7 * n;
+ }
+
+ public static int signum(double x)
+ {
+ if(x < 0.0D)
+ return -1;
+ return x <= 0.0D ? 0 : 1;
+ }
+
+ public static double square(double x)
+ {
+ return x * x;
+ }
+
+ public static double poly(double x, double a[])
+ {
+ double result = a[0];
+ for(int i = 1; i < a.length; i++)
+ result += a[i] * Math.pow(x, i);
+
+ return result;
+ }
+
+ public static double localFromUniversal(double uTime, double zone)
+ {
+ return uTime + zone / 1440D;
+ }
+
+ public static double universalFromLocal(double lTime, double zone)
+ {
+ return lTime - zone / 1440D;
+ }
+
+ public static int locationOffset(double longitude, double zone)
+ {
+ return (int)(4D * longitude - zone);
+ }
+
+ public static double localFromStandard(double sTime, double offset)
+ {
+ return sTime + offset / 1440D;
+ }
+
+ public static double standardFromLocal(double lTime, double offset)
+ {
+ return lTime - offset / 1440D;
+ }
+
+ public static double momentFromJD(double jd)
+ {
+ return jd + -1721424.5D;
+ }
+
+ public static double jdFromMoment(double moment)
+ {
+ return moment - -1721424.5D;
+ }
+
+ public static int fixedFromJD(double jd)
+ {
+ return (int)Math.floor(momentFromJD(jd));
+ }
+
+ public static double jdFromFixed(int date)
+ {
+ return jdFromMoment(date);
+ }
+
+ public static double degrees(double theta)
+ {
+ return mod(theta, 360D);
+ }
+
+ public static double radiansToDegrees(double theta)
+ {
+ return degrees((theta / 3.1415926535897931D) * 180D);
+ }
+
+ public static double degreesToRadians(double theta)
+ {
+ return (degrees(theta) * 3.1415926535897931D) / 180D;
+ }
+
+ public static double sinDegrees(double theta)
+ {
+ return Math.sin(degreesToRadians(theta));
+ }
+
+ public static double cosDegrees(double theta)
+ {
+ return Math.cos(degreesToRadians(theta));
+ }
+
+ public static double tanDegrees(double theta)
+ {
+ return Math.tan(degreesToRadians(theta));
+ }
+
+ public static double arcTanDegrees(double x, int quad)
+ {
+ double deg = radiansToDegrees(Math.atan(x));
+ return quad != 1 && quad != 4 ? deg + 180D : deg;
+ }
+
+ public static double arcSinDegrees(double x)
+ {
+ return radiansToDegrees(Math.asin(x));
+ }
+
+ public static double arcCosDegrees(double x)
+ {
+ return radiansToDegrees(Math.acos(x));
+ }
+
+ public static double localFromApparent(double moment)
+ {
+ return moment - equationOfTime(moment);
+ }
+
+ public static double apparentFromLocal(double moment)
+ {
+ return moment + equationOfTime(moment);
+ }
+
+ public static double solarMoment(int date, double latitude, double longitude, double riseOrSet)
+ {
+ double approx = (double)(new Gregorian(date)).dayNumber() + 0.5D + riseOrSet + longitude / -360D;
+ double anomaly = 0.98560000000000003D * approx - 3.2890000000000001D;
+ double sun = degrees(anomaly + 1.9159999999999999D * sinDegrees(anomaly) + 282.63400000000001D + 0.02D * sinDegrees(2D * anomaly));
+ double rightAscension = arcTanDegrees(cosDegrees(23.441884000000002D) * tanDegrees(sun), 1 + quotient(sun, 90D));
+ double declination = arcSinDegrees(sinDegrees(23.441884000000002D) * sinDegrees(sun));
+ double local = (double)signum(riseOrSet) * arcCosDegrees((cosDegrees(90.833332999999996D) - sinDegrees(declination) * sinDegrees(latitude)) / cosDegrees(declination) / cosDegrees(latitude));
+ return mod((local + rightAscension) / 360D - 0.27592D - 0.00273792D * approx, 1.0D);
+ }
+
+ public static double sunrise(int date, double latitude, double longitude)
+ {
+ return solarMoment(date, latitude, longitude, -0.25D);
+ }
+
+ public static double sunset(int date, double latitude, double longitude)
+ {
+ return solarMoment(date, latitude, longitude, 0.25D);
+ }
+
+ public static double universalFromEphemeris(double jd)
+ {
+ return jd - ephemerisCorrection(momentFromJD(jd));
+ }
+
+ public static double ephemerisFromUniversal(double jd)
+ {
+ return jd + ephemerisCorrection(momentFromJD(jd));
+ }
+
+ public static double julianCenturies(double moment)
+ {
+ return (ephemerisFromUniversal(moment) - J2000) / 36525D;
+ }
+
+ public static double ephemerisCorrection(double moment)
+ {
+ int year = Gregorian.yearFromFixed((int)moment);
+ double theta = (double)difference(Gregorian.toFixed(1, 1, 1900), Gregorian.toFixed(7, 1, year)) / 36525D;
+ double result;
+ if(1988 <= year && year <= 2019)
+ result = (double)(year - 1933) / 86400D;
+ else
+ if(1900 <= year && year <= 1987)
+ result = poly(theta, ec.coeff19th);
+ else
+ if(1800 <= year && year <= 1899)
+ result = poly(theta, ec.coeff18th);
+ else
+ if(1620 <= year && year <= 1799)
+ {
+ result = poly(year - 1600, ec.coeff17th) / 86400D;
+ } else
+ {
+ double x = 0.5D + (double)difference(Gregorian.toFixed(1, 1, 1810), Gregorian.toFixed(1, 1, year));
+ return ((x * x) / 41048480D - 15D) / 86400D;
+ }
+ return result;
+ }
+
+ public static double equationOfTime(double jd)
+ {
+ double c = (jd - J2000) / 36525D;
+ double longitude = poly(c, et.coeffLongitude);
+ double anomaly = poly(c, et.coeffAnomaly);
+ double inclination = poly(c, et.coeffInclination);
+ double eccentricity = poly(c, et.coeffEccentricity);
+ double y = square(tanDegrees(inclination / 2D));
+ return (y * sinDegrees(2D * longitude) + -2D * eccentricity * sinDegrees(anomaly) + 4D * eccentricity * y * sinDegrees(anomaly) * cosDegrees(2D * longitude) + -0.5D * y * y * sinDegrees(4D * longitude) + -1.25D * eccentricity * eccentricity * sinDegrees(2D * anomaly)) / 6.2831853071795862D;
+ }
+
+ public static double solarLongitude(double jd)
+ {
+ double c = julianCenturies(jd);
+ double sigma = 0.0D;
+ for(int i = 0; i < sl.coefficients.length; i++)
+ sigma += (double)sl.coefficients[i] * Math.sin(sl.multipliers[i] * c + sl.addends[i]);
+
+ double longitude = 4.9353929000000001D + 628.33196167999995D * c + 9.9999999999999995E-008D * sigma;
+ return radiansToDegrees(longitude + aberration(c) + nutation(c));
+ }
+
+ public static double nutation(double c)
+ {
+ double a = poly(c, nu.coeffa);
+ double b = poly(c, nu.coeffb);
+ return -8.3399999999999994E-005D * sinDegrees(a) + -6.3999999999999997E-006D * sinDegrees(b);
+ }
+
+ public static double aberration(double c)
+ {
+ return 1.7E-006D * cosDegrees(177.63D + 35999.018479999999D * c) - 9.7299999999999993E-005D;
+ }
+
+ public static double dateNextSolarLongitude(double jd, double l)
+ {
+ double next = degrees(l * Math.ceil(solarLongitude(jd) / l));
+ double lo = jd;
+ double hi = jd + (l / 360D) * 400D;
+ double x;
+ for(x = (hi + lo) / 2D; hi - lo > 1.0000000000000001E-005D; x = (hi + lo) / 2D)
+ if(next != 0.0D ? solarLongitude(x) >= next : l >= solarLongitude(x))
+ hi = x;
+ else
+ lo = x;
+
+ return x;
+ }
+
+ public static double lunarLongitude(double uTime)
+ {
+ double c = julianCenturies(uTime);
+ double meanMoon = degrees(poly(c, ll.coeffMeanMoon));
+ double elongation = degrees(poly(c, ll.coeffElongation));
+ double solarAnomaly = degrees(poly(c, ll.coeffSolarAnomaly));
+ double lunarAnomaly = degrees(poly(c, ll.coeffLunarAnomaly));
+ double moonFromNode = degrees(poly(c, ll.coeffMoonFromNode));
+ double e = poly(c, ll.coeffE);
+ double sigma = 0.0D;
+ for(int i = 0; i < ll.argsLunarElongation.length; i++)
+ {
+ double x = ll.argsSolarAnomaly[i];
+ sigma += (double)ll.sineCoefficients[i] * Math.pow(e, Math.abs(x)) * sinDegrees((double)ll.argsLunarElongation[i] * elongation + x * solarAnomaly + (double)ll.argsLunarAnomaly[i] * lunarAnomaly + (double)ll.argsMoonFromNode[i] * moonFromNode);
+ }
+
+ double longitude = 9.9999999999999995E-007D * sigma;
+ double venus = 0.0039579999999999997D * sinDegrees(119.75D + c * 131.84899999999999D);
+ double jupiter = 0.00031799999999999998D * sinDegrees(53.090000000000003D + c * 479264.28999999998D);
+ double flatEarth = 0.0019620000000000002D * sinDegrees(meanMoon - moonFromNode);
+ return degrees(meanMoon + longitude + venus + jupiter + flatEarth + radiansToDegrees(nutation(c)));
+ }
+
+ public static double newMoonTime(int k)
+ {
+ double c = (double)k / 1236.8499999999999D;
+ double JDE = poly(c, nm.coeffJDE);
+ double e = poly(c, nm.coeffE);
+ double solarAnomaly = poly(c, nm.coeffSolarAnomaly);
+ double lunarAnomaly = poly(c, nm.coeffLunarAnomaly);
+ double moonArgument = poly(c, nm.coeffMoonArgument);
+ double omega = poly(c, nm.coeffOmega);
+ double correction = -0.00017000000000000001D * sinDegrees(omega);
+ for(int ix = 0; ix < nm.sineCoeff.length; ix++)
+ correction += nm.sineCoeff[ix] * Math.pow(e, nm.eFactor[ix]) * sinDegrees((double)nm.solarCoeff[ix] * solarAnomaly + (double)nm.lunarCoeff[ix] * lunarAnomaly + (double)nm.moonCoeff[ix] * moonArgument);
+
+ double additional = 0.0D;
+ for(int ix = 0; ix < nm.addConst.length; ix++)
+ additional += nm.addFactor[ix] * sinDegrees(nm.addConst[ix] + nm.addCoeff[ix] * (double)k + nm.addExtra[ix] * c * c);
+
+ return universalFromEphemeris(JDE + correction + additional);
+ }
+
+ public static double newMoonAtOrAfter(double jd)
+ {
+ Gregorian date = new Gregorian((int)Math.floor(momentFromJD(jd)));
+ int approx = (int)Math.floor((((double)((StandardDate) (date)).year + (double)date.dayNumber() / 365.25D) - 2000D) * 12.368499999999999D) - 1;
+ int error = 0;
+ for(int i = approx; newMoonTime(i) < jd; i++)
+ error++;
+
+ return newMoonTime(approx + error);
+ }
+
+ public static double newMoonBefore(double jd)
+ {
+ return newMoonAtOrAfter(newMoonAtOrAfter(jd) - 45D);
+ }
+
+ public static double lunarSolarAngle(double jd)
+ {
+ return degrees(lunarLongitude(jd) - solarLongitude(jd));
+ }
+
+ public static double lunarPhaseAtOrBefore(double phase, double jd)
+ {
+ boolean close = degrees(lunarSolarAngle(jd) - phase) < 40D;
+ double yesterday = jd - 1.0D;
+ double orig = 2451550.2599999998D + 29.530588853000001D * (phase / 360D);
+ double epsilon = 9.9999999999999995E-007D;
+ double tau = yesterday - mod(yesterday - orig, 29.530588853000001D);
+ double lo = close ? jd - 4D : tau - 2D;
+ double hi = close ? jd : tau + 2D;
+ double x;
+ for(x = (hi + lo) / 2D; hi - lo > epsilon; x = (hi + lo) / 2D)
+ {
+ double lunSolAngle = lunarSolarAngle(x);
+ if(phase <= lunSolAngle && lunSolAngle <= phase + 90D)
+ hi = x;
+ else
+ lo = x;
+ }
+
+ return x;
+ }
+
+ public static double newMoonAtOrBefore(double jd)
+ {
+ return lunarPhaseAtOrBefore(0.0D, jd);
+ }
+
+ public static double fullMoonAtOrBefore(double jd)
+ {
+ return lunarPhaseAtOrBefore(180D, jd);
+ }
+
+ public static double firstQuarterMoonAtOrBefore(double jd)
+ {
+ return lunarPhaseAtOrBefore(90D, jd);
+ }
+
+ public static double lastQuarterMoonAtOrBefore(double jd)
+ {
+ return lunarPhaseAtOrBefore(270D, jd);
+ }
+
+ public static double siderealFromJD(double jd)
+ {
+ double c = (jd - J2000) / 36525D;
+ return poly(c, sfj.siderealCoeff) / 360D;
+ }
+
+ public String toString()
+ {
+ return getClass().getName() + "[" + toStringFields() + "]";
+ }
+
+ protected abstract String toStringFields();
+
+ public abstract boolean equals(Object obj);
+
+ public static final int JANUARY = 1;
+ public static final int FEBRUARY = 2;
+ public static final int MARCH = 3;
+ public static final int APRIL = 4;
+ public static final int MAY = 5;
+ public static final int JUNE = 6;
+ public static final int JULY = 7;
+ public static final int AUGUST = 8;
+ public static final int SEPTEMBER = 9;
+ public static final int OCTOBER = 10;
+ public static final int NOVEMBER = 11;
+ public static final int DECEMBER = 12;
+ public static final int SUNDAY = 0;
+ public static final int MONDAY = 1;
+ public static final int TUESDAY = 2;
+ public static final int WEDNESDAY = 3;
+ public static final int THURSDAY = 4;
+ public static final int FRIDAY = 5;
+ public static final int SATURDAY = 6;
+ public static final int FIRST = 1;
+ public static final int LAST = -1;
+ public static final double JD_START = -1721424.5D;
+ public static final double J2000 = jdFromMoment(0.5D + (double)Gregorian.toFixed(1, 1, 2000));
+ public static final double MEAN_TROPICAL_YEAR = 365.24219900000003D;
+ public static final double MEAN_SYNODIC_MONTH = 29.530588853000001D;
+ public static final double NEW = 0D;
+ public static final double FIRST_QUARTER = 90D;
+ public static final double FULL = 180D;
+ public static final double LAST_QUARTER = 270D;
+
+}
+
+
+
\ No newline at end of file diff --git a/calendar/java/src/org/panchanga/common/StandardDate.java b/calendar/java/src/org/panchanga/common/StandardDate.java new file mode 100755 index 0000000..83c6f97 --- /dev/null +++ b/calendar/java/src/org/panchanga/common/StandardDate.java @@ -0,0 +1,67 @@ +
+
+package org.panchanga.common;
+
+import org.panchanga.common.exception.BogusDateException;
+
+
+// Referenced classes of package calendrica:
+// Date, BogusDateException
+
+public abstract class StandardDate extends Date
+{
+
+ public StandardDate()
+ {
+ }
+
+ public StandardDate(int date)
+ {
+ super(date);
+ }
+
+ public StandardDate(Date date)
+ throws BogusDateException
+ {
+ super(date);
+ }
+
+ public StandardDate(int month, int day, int year)
+ {
+ this.month = month;
+ this.day = day;
+ this.year = year;
+ }
+
+ public StandardDate(int a[])
+ {
+ fromArray(a);
+ }
+
+ public void fromArray(int a[])
+ {
+ month = a[0];
+ day = a[1];
+ year = a[2];
+ }
+
+ protected String toStringFields()
+ {
+ return "month=" + month + ",day=" + day + ",year=" + year;
+ }
+
+ protected boolean internalEquals(Object obj)
+ {
+ StandardDate o = (StandardDate)obj;
+ if(this == obj)
+ return true;
+ return o.month == month && o.day == day && o.year == year;
+ }
+
+ public int month;
+ public int day;
+ public int year;
+}
+
+
+
\ No newline at end of file diff --git a/calendar/java/src/org/panchanga/common/Time.java b/calendar/java/src/org/panchanga/common/Time.java new file mode 100755 index 0000000..78ba7e1 --- /dev/null +++ b/calendar/java/src/org/panchanga/common/Time.java @@ -0,0 +1,68 @@ +
+package org.panchanga.common;
+
+import java.io.Serializable;
+
+// Referenced classes of package calendrica:
+// ProtoDate
+
+public class Time
+ implements Cloneable, Serializable
+{
+
+ public Time()
+ {
+ }
+
+ public Time(double moment)
+ {
+ fromMoment(moment);
+ }
+
+ public Time(int hour, int minute, double second)
+ {
+ this.hour = hour;
+ this.minute = minute;
+ this.second = second;
+ }
+
+ public static double toMoment(int hour, int minute, double second)
+ {
+ return (double)hour / 24D + (double)minute / 1440D + second / 86400D;
+ }
+
+ public double toMoment()
+ {
+ return toMoment(hour, minute, second);
+ }
+
+ public void fromMoment(double moment)
+ {
+ hour = (int)Math.floor(ProtoDate.mod(moment * 24D, 24D));
+ minute = (int)Math.floor(ProtoDate.mod(moment * 24D * 60D, 60D));
+ second = ProtoDate.mod(moment * 24D * 60D * 60D, 60D);
+ }
+
+ public String toString()
+ {
+ return getClass().getName() + "[hour=" + hour + ",minute=" + minute + ",second=" + second + "]";
+ }
+
+ public boolean equals(Object obj)
+ {
+ if(this == obj)
+ return true;
+ if(!(obj instanceof Time))
+ return false;
+ Time o = (Time)obj;
+ return o.hour == hour && o.minute == minute && o.second == second;
+ }
+
+ public int hour;
+ public int minute;
+ public double second;
+}
+
+
+
+
\ No newline at end of file diff --git a/calendar/java/src/org/panchanga/common/exception/BogusDateException.java b/calendar/java/src/org/panchanga/common/exception/BogusDateException.java new file mode 100755 index 0000000..5ae901a --- /dev/null +++ b/calendar/java/src/org/panchanga/common/exception/BogusDateException.java @@ -0,0 +1,20 @@ +
+package org.panchanga.common.exception;
+
+
+public class BogusDateException extends Exception
+{
+
+ public BogusDateException()
+ {
+ }
+
+ public BogusDateException(String s)
+ {
+ super(s);
+ }
+}
+
+
+
+
\ No newline at end of file diff --git a/calendar/java/src/org/panchanga/gregorian/Gregorian.java b/calendar/java/src/org/panchanga/gregorian/Gregorian.java new file mode 100755 index 0000000..d5c6ee0 --- /dev/null +++ b/calendar/java/src/org/panchanga/gregorian/Gregorian.java @@ -0,0 +1,150 @@ +
+
+package org.panchanga.gregorian;
+
+import org.panchanga.common.Date;
+import org.panchanga.common.ProtoDate;
+import org.panchanga.common.StandardDate;
+import org.panchanga.common.exception.BogusDateException;
+
+
+// Referenced classes of package calendrica:
+// StandardDate, BogusDateException, ProtoDate, Date
+
+public class Gregorian extends StandardDate
+{
+
+ public Gregorian()
+ {
+ }
+
+ public Gregorian(int date)
+ {
+ super(date);
+ }
+
+ public Gregorian(Date date)
+ throws BogusDateException
+ {
+ super(date);
+ }
+
+ public Gregorian(int month, int day, int year)
+ {
+ super(month, day, year);
+ }
+
+ public static int toFixed(int month, int day, int year)
+ {
+ return ((0 + 365 * (year - 1) + ProtoDate.quotient(year - 1, 4D)) - ProtoDate.quotient(year - 1, 100D)) + ProtoDate.quotient(year - 1, 400D) + ProtoDate.quotient(367 * month - 362, 12D) + (month > 2 ? isLeapYear(year) ? -1 : -2 : 0) + day;
+ }
+
+ public int toFixed()
+ {
+ return toFixed(super.month, super.day, super.year);
+ }
+
+ public void fromFixed(int date)
+ {
+ super.year = yearFromFixed(date);
+ int priorDays = date - toFixed(1, 1, super.year);
+ int correction = date >= toFixed(3, 1, super.year) ? ((int) (isLeapYear(super.year) ? 1 : 2)) : 0;
+ super.month = ProtoDate.quotient(12 * (priorDays + correction) + 373, 367D);
+ super.day = (date - toFixed(super.month, 1, super.year)) + 1;
+ }
+
+ public static boolean isLeapYear(int year)
+ {
+ boolean result = false;
+ if(ProtoDate.mod(year, 4) == 0)
+ {
+ int n = ProtoDate.mod(year, 400);
+ if(n != 100 && n != 200 && n != 300)
+ result = true;
+ }
+ return result;
+ }
+
+ public static int yearFromFixed(int date)
+ {
+ int d0 = date - 1;
+ int n400 = ProtoDate.quotient(d0, 146097D);
+ int d1 = ProtoDate.mod(d0, 146097);
+ int n100 = ProtoDate.quotient(d1, 36524D);
+ int d2 = ProtoDate.mod(d1, 36524);
+ int n4 = ProtoDate.quotient(d2, 1461D);
+ int d3 = ProtoDate.mod(d2, 1461);
+ int n1 = ProtoDate.quotient(d3, 365D);
+ int _tmp = ProtoDate.mod(d3, 365) + 1;
+ int year = 400 * n400 + 100 * n100 + 4 * n4 + n1;
+ return n100 != 4 && n1 != 4 ? year + 1 : year;
+ }
+
+ public int dayNumber()
+ {
+ return ProtoDate.difference(toFixed(12, 31, super.year - 1), toFixed());
+ }
+
+ public int daysRemaining()
+ {
+ return ProtoDate.difference(toFixed(), toFixed(12, 31, super.year));
+ }
+
+ public static int independenceDay(int year)
+ {
+ return toFixed(7, 4, year);
+ }
+
+ public static int laborDay(int year)
+ {
+ return ProtoDate.nthKDay(1, 1, toFixed(9, 1, year));
+ }
+
+ public static int memorialDay(int year)
+ {
+ return ProtoDate.nthKDay(-1, 1, toFixed(5, 31, year));
+ }
+
+ public static int electionDay(int year)
+ {
+ return ProtoDate.nthKDay(1, 2, toFixed(11, 2, year));
+ }
+
+ public static int daylightSavingsStart(int year)
+ {
+ return ProtoDate.nthKDay(1, 0, toFixed(4, 1, year));
+ }
+
+ public static int daylightSavingsEnd(int year)
+ {
+ return ProtoDate.nthKDay(-1, 0, toFixed(10, 31, year));
+ }
+
+ public static int christmas(int year)
+ {
+ return toFixed(12, 25, year);
+ }
+
+ public static int advent(int year)
+ {
+ return ProtoDate.kDayNearest(toFixed(11, 30, year), 0);
+ }
+
+ public static int epiphany(int year)
+ {
+ return christmas(year - 1) + 12;
+ }
+
+ public boolean equals(Object obj)
+ {
+ if(!(obj instanceof Gregorian))
+ return false;
+ else
+ return internalEquals(obj);
+ }
+
+ public static final int EPOCH = 1;
+}
+
+
+
\ No newline at end of file diff --git a/calendar/java/src/org/panchanga/indic/BengaliCalendar.java b/calendar/java/src/org/panchanga/indic/BengaliCalendar.java new file mode 100755 index 0000000..b0b63b2 --- /dev/null +++ b/calendar/java/src/org/panchanga/indic/BengaliCalendar.java @@ -0,0 +1,125 @@ +package org.panchanga.indic;
+
+import java.util.Date;
+
+import org.panchanga.common.ProtoDate;
+import org.panchanga.common.exception.BogusDateException;
+import org.panchanga.gregorian.Gregorian;
+
+
+
+
+/**
+ * @author Santhosh.thottingal
+ */
+public class BengaliCalendar {
+
+ String bn_months[] = { "Boishakh", "Joishtho", "Asharh ", "Srabon ",
+ "Bhadro ", "Ashshin ", "Kartik ", "Ogrohaeon ", "Poush ", "Magh ",
+ "Falgun ", "Choitro", };
+
+ private int MSum(int start, int cond) {
+ int total = 0;
+ for (int i = start; HinduSolar.zodiac(HinduSolar.sunriseAtUjjain(i)) != cond; i++) {
+ total++;
+ }
+ return total;
+ }
+ private int bengaliYear(int month, int year) {
+
+ if (1 <= month && month <= 4)
+ return year - 593+78;
+ else
+ return year - 594+79;
+ }
+
+ /**
+ * oriyaHinduSolar[date_Integer] Input: Fixed number for RD date.
+ * Output: Bengali calendar date of day at sunrise on RD date.
+ *
+ * @throws BogusDateException
+ */
+
+ public void bengaliHinduSolar(Date date) throws BogusDateException {
+ int year1 = 0, year2 = 0;
+ double samk2 = 0;
+ double srise2 = 0;
+ double aparahna2 = 0;
+ int kyTime = OldHinduSolar.dayCount(Gregorian.toFixed(10, 29, 2008));
+
+ /* We find rise1, month1, year1, approx1, begin1 and day1 at kyTime - 1 because under certain criteria, the Bengal calendar date is behind the HinduSolar calendar date by a day. */
+
+ double rise1 = HinduSolar.sunriseAtUjjain(kyTime - 1);
+ double rise2 = HinduSolar.sunriseAtUjjain(kyTime);
+ int month1 = HinduSolar.zodiac(rise1);
+ int month2 = HinduSolar.zodiac(rise2);
+ year1 = HinduSolar.calendarYear(rise1) - HinduSolar.SOLAR_ERA;
+ // HinduSolar.SOLAR_ERA; = Years from Kali Yuga until Saka era. =
+ // (AD+3101)-(AD-78) =3179
+
+ int approx1 = kyTime - 4
+ - ProtoDate.quotient(HinduSolar.solarLongitude(rise1) % 1800, 60);
+ int begin1 = approx1 + MSum(approx1, month1);
+ int day1 = kyTime - begin1;
+ double samk1 = HinduSolar.samkranti(78 + year1, month1);
+ /* srise1 is the IST for sunrise for the day of samk1 if the IST for samk1 falls before midnight. Otherwise srise1 gives the IST for sunrise for the following day. If the latter is true, then samk1 < srise1. */
+ double srise1 = HinduSolar.sunriseAtUjjain((int)OldHinduSolar
+ .dayCount(Math.abs(samk1)))
+ + OldHinduSolar.EPOCH;
+
+ /* midnight1 is the midnight following samk1. */
+ double midnight1 = Math.floor(samk1) + 1;
+
+ /* The explanation for aparahna1 is similar to that for srise1. */
+ if (month1 != month2) {
+ /*
+ * If month1!= month2, then month2 is the new month. We need the
+ * IST for the samkranti, the sunrise and the aparahna for the day
+ * of the samkranti and the Saka year for month2.
+ */
+ year2 = HinduSolar.calendarYear(rise2) - HinduSolar.SOLAR_ERA;
+ ;
+ samk2 = HinduSolar.samkranti(78 + year2, month2);
+ srise2 = HinduSolar.sunriseAtUjjain((int)OldHinduSolar
+ .dayCount(Math.abs(samk2)))
+ + OldHinduSolar.EPOCH;
+ double midnight2 = Math.floor(samk1) + 1;
+ if ((srise2 <= samk2) && (samk2 < midnight2)) {
+
+ System.out.println(bn_months[(month2) - 1] + "-" + 1 + "-"
+ + bengaliYear(month2,year2));
+ }
+ if ((srise1 <= samk1) && (samk1 < midnight1)) {
+
+ System.out.println(bn_months[(month2) - 1] + "-" + (day1 + 1)
+ + "-" + bengaliYear(month2,year2));
+ }
+
+ }
+
+ if (month1 == month2) {
+ if ((srise1 <= samk1) && (samk1 < midnight1)) {
+
+ System.out.println(bn_months[month1 - 1] + "-" + (day1 + 1)
+ + "-" + bengaliYear(month1,year1));
+ }
+ else {
+ System.out.println(bn_months[(month1) - 1] + "-" + (day1)
+ + "-" + bengaliYear(month1,year1));
+ }
+
+ }
+
+ }
+
+ public static void main(String[] args) {
+ BengaliCalendar mlCalendar = new BengaliCalendar();
+ try {
+ mlCalendar.bengaliHinduSolar(new Date());
+ }
+ catch (BogusDateException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/calendar/java/src/org/panchanga/indic/HinduLunar.java b/calendar/java/src/org/panchanga/indic/HinduLunar.java new file mode 100755 index 0000000..c1e4ad5 --- /dev/null +++ b/calendar/java/src/org/panchanga/indic/HinduLunar.java @@ -0,0 +1,244 @@ +
+
+package org.panchanga.indic;
+
+import org.panchanga.common.Date;
+import org.panchanga.common.FixedVector;
+import org.panchanga.common.ProtoDate;
+import org.panchanga.common.exception.BogusDateException;
+import org.panchanga.gregorian.Gregorian;
+
+
+
+// Referenced classes of package calendrica:
+// Date, BogusDateException, OldHinduLunar, OldHinduSolar,
+// HinduSolar, ProtoDate, Gregorian, FixedVector
+
+public class HinduLunar extends Date
+{
+
+ public HinduLunar()
+ {
+ }
+
+ public HinduLunar(int date)
+ {
+ super(date);
+ }
+
+ public HinduLunar(Date date)
+ throws BogusDateException
+ {
+ super(date);
+ }
+
+ public HinduLunar(int month, boolean leapMonth, int day, boolean leapDay, int year)
+ {
+ this.month = month;
+ this.leapMonth = leapMonth;
+ this.day = day;
+ this.leapDay = leapDay;
+ this.year = year;
+ }
+
+ public static int toFixed(int month, boolean leapMonth, int day, boolean leapDay, int year)
+ throws BogusDateException
+ {
+ return (new HinduLunar(month, leapMonth, day, leapDay, year)).toFixed();
+ }
+
+ public int toFixed()
+ throws BogusDateException
+ {
+ int kyYear = year + 3044;
+ int mean = OldHinduLunar.toFixed(month, leapMonth, day, kyYear);
+ double approx;
+ if(precedes(new HinduLunar(mean + 15), this))
+ approx = (double)mean + 29.530587946071719D;
+ else
+ if(precedes(this, new HinduLunar(mean - 15)))
+ approx = (double)mean - 29.530587946071719D;
+ else
+ approx = mean;
+ double lo = approx - 4D;
+ double hi = approx + 4D;
+ double d;
+ for(d = (lo + hi) / 2D; hi - lo > 2D; d = (lo + hi) / 2D)
+ if(!precedes(new HinduLunar((int)Math.floor(d)), this))
+ hi = d;
+ else
+ lo = d;
+
+ int aTry = (int)Math.floor(d);
+ int result;
+ if((new HinduLunar(aTry)).equals(this))
+ result = aTry;
+ else
+ if((new HinduLunar(aTry + 1)).equals(this))
+ result = aTry + 1;
+ else
+ if((new HinduLunar(aTry - 1)).equals(this))
+ result = aTry - 1;
+ else
+ throw new BogusDateException();
+ return result;
+ }
+
+ public void fromFixed(int date)
+ {
+ int kyTime = OldHinduSolar.dayCount(date);
+ double rise = HinduSolar.sunrise(kyTime);
+ day = lunarDay(rise);
+ leapDay = day == lunarDay(HinduSolar.sunrise(kyTime - 1));
+ double lastNewMoon = newMoon(rise);
+ double nextNewMoon = newMoon(Math.floor(lastNewMoon) + 35D);
+ int solarMonth = HinduSolar.zodiac(lastNewMoon);
+ leapMonth = solarMonth == HinduSolar.zodiac(nextNewMoon);
+ month = ProtoDate.adjustedMod(solarMonth + 1, 12);
+ year = HinduSolar.calendarYear(nextNewMoon) - 3044 - (!leapMonth || month != 1 ? 0 : -1);
+ }
+
+ public void fromArray(int a[])
+ {
+ month = a[0];
+ leapMonth = a[1] != 0;
+ day = a[2];
+ leapDay = a[3] != 0;
+ year = a[4];
+ }
+
+ public static double newMoon(double kyTime)
+ {
+ double tomorrow = kyTime + 1.0D;
+ double estimate = tomorrow - ProtoDate.mod(tomorrow, 29.530587946071719D);
+ double lo = estimate - 0.66666666666666663D;
+ double hi = estimate + 0.66666666666666663D;
+ double aTry;
+ for(aTry = (hi + lo) / 2D; kyTime >= lo && (hi > kyTime || HinduSolar.zodiac(lo) != HinduSolar.zodiac(hi)); aTry = (hi + lo) / 2D)
+ if(lunarPhase(aTry) < 10800D)
+ hi = aTry;
+ else
+ lo = aTry;
+
+ return aTry <= kyTime ? aTry : newMoon(Math.floor(kyTime) - 20D);
+ }
+
+ public static boolean precedes(HinduLunar d1, HinduLunar d2)
+ {
+ return d1.year < d2.year || d1.year == d2.year && (d1.month < d2.month || d1.month == d2.month && (d1.leapMonth && !d2.leapMonth || d1.leapMonth == d2.leapMonth && (d1.day < d2.day || d1.day == d2.day && !d1.leapDay && d2.leapDay)));
+ }
+
+ public static double lunarDayStart(double kyTime, double k, double accuracy)
+ {
+ double tomorrow = kyTime + 1.0D;
+ double part = (((k - 1.0D) * 1.0D) / 30D) * 29.530587946071719D;
+ double estimate = tomorrow - ProtoDate.mod(tomorrow - part, 29.530587946071719D);
+ double lo = estimate - 0.66666666666666663D;
+ double hi = estimate + 0.66666666666666663D;
+ double aTry;
+ for(aTry = (hi + lo) / 2D; kyTime >= lo && hi - lo >= accuracy; aTry = (hi + lo) / 2D)
+ {
+ double diffX = lunarPhase(aTry) - (k - 1.0D) * 720D;
+ if(0.0D < diffX && diffX < 10800D || diffX < -10800D)
+ hi = aTry;
+ else
+ lo = aTry;
+ }
+
+ return aTry <= kyTime ? aTry : lunarDayStart(kyTime - 20D, k, accuracy);
+ }
+
+ public static double lunarLongitude(double kyTime)
+ {
+ return HinduSolar.truePosition(kyTime, 27.321674162683866D, 0.088888888888888892D, 27.554597974680476D, 0.023809523809523808D);
+ }
+
+ public static double lunarPhase(double kyTime)
+ {
+ return ProtoDate.mod(lunarLongitude(kyTime) - HinduSolar.solarLongitude(kyTime), 21600D);
+ }
+
+ public static int lunarDay(double kyTime)
+ {
+ return ProtoDate.quotient(lunarPhase(kyTime), 720D) + 1;
+ }
+
+ public static int lunarMansion(int date)
+ {
+ double rise = HinduSolar.sunrise(OldHinduSolar.dayCount(date));
+ return ProtoDate.quotient(lunarLongitude(rise), 800D) + 1;
+ }
+
+ public static int newYear(int gYear)
+ {
+ double mesha = HinduSolar.meshaSamkranti(gYear);
+ double m1 = lunarDayStart(OldHinduSolar.dayCount(mesha), 1.0D, 1.0000000000000001E-005D);
+ double m0 = lunarDayStart(m1 - 27D, 1.0D, 1.0000000000000001E-005D);
+ double aNewMoon = HinduSolar.zodiac(m0) != HinduSolar.zodiac(m1) ? m1 : m0;
+ int hDay = (int)Math.floor(aNewMoon);
+ double rise = HinduSolar.sunrise(hDay);
+ return OldHinduSolar.EPOCH + hDay + (aNewMoon >= rise && lunarDay(HinduSolar.sunrise(hDay + 1)) != 2 ? 1 : 0);
+ }
+
+ public static int karana(int n)
+ {
+ if(n == 1)
+ return 0;
+ if(n > 57)
+ return n - 50;
+ else
+ return ProtoDate.adjustedMod(n - 1, 7);
+ }
+
+ public static int yoga(double kyTime)
+ {
+ return (int)Math.floor(ProtoDate.mod((HinduSolar.solarLongitude(kyTime) + lunarLongitude(kyTime)) / 800D, 27D)) + 1;
+ }
+
+ public static FixedVector sacredWednesdaysInGregorian(int gYear)
+ {
+ return sacredWednesdays(Gregorian.toFixed(1, 1, gYear), Gregorian.toFixed(12, 31, gYear));
+ }
+
+ public static FixedVector sacredWednesdays(int start, int end)
+ {
+ int wed = ProtoDate.kDayOnOrAfter(start, 3);
+ FixedVector result = new FixedVector();
+ for(; wed <= end; wed += 7)
+ {
+ HinduLunar hDate = new HinduLunar(wed);
+ if(hDate.day == 8)
+ result.addFixed(wed);
+ }
+
+ return result;
+ }
+
+ protected String toStringFields()
+ {
+ return "month=" + month + ",leapMonth=" + leapMonth + ",day=" + day + ",leapDay=" + leapDay + ",year=" + year;
+ }
+
+ public boolean equals(Object obj)
+ {
+ if(this == obj)
+ return true;
+ if(!(obj instanceof HinduLunar))
+ return false;
+ HinduLunar o = (HinduLunar)obj;
+ return o.month == month && o.leapMonth == leapMonth && o.day == day && o.leapDay == leapDay && o.year == year;
+ }
+
+ public int month;
+ public boolean leapMonth;
+ public int day;
+ public boolean leapDay;
+ public int year;
+ public static final int LUNAR_ERA = 3044;
+ public static final double SYNODIC_MONTH = 29.530587946071719D;
+ public static final double SIDEREAL_MONTH = 27.321674162683866D;
+ public static final double ANOMALISTIC_MONTH = 27.554597974680476D;
+}
+
+
+
\ No newline at end of file diff --git a/calendar/java/src/org/panchanga/indic/HinduSolar.java b/calendar/java/src/org/panchanga/indic/HinduSolar.java new file mode 100755 index 0000000..6449c7e --- /dev/null +++ b/calendar/java/src/org/panchanga/indic/HinduSolar.java @@ -0,0 +1,257 @@ +
+package org.panchanga.indic;
+
+import org.panchanga.common.Date;
+import org.panchanga.common.ProtoDate;
+import org.panchanga.common.StandardDate;
+import org.panchanga.common.exception.BogusDateException;
+import org.panchanga.gregorian.Gregorian;
+
+
+// Referenced classes of package calendrica:
+// StandardDate, BogusDateException, OldHinduSolar, ProtoDate,
+// Gregorian, Date
+
+public class HinduSolar extends StandardDate
+{
+
+ public HinduSolar()
+ {
+ }
+
+ public HinduSolar(int date)
+ {
+ super(date);
+ }
+
+ public HinduSolar(Date date)
+ throws BogusDateException
+ {
+ super(date);
+ }
+
+ public HinduSolar(int month, int day, int year)
+ {
+ super(month, day, year);
+ }
+
+ public static int toFixed(int month, int day, int year)
+ throws BogusDateException
+ {
+ return (new HinduSolar(month, day, year)).toFixed();
+ }
+
+ public int toFixed()
+ throws BogusDateException
+ {
+ int approx = (int)Math.floor(((double)(super.year + 3179 + (super.month - 1) / 12) * 365.2587564814815D + (double)OldHinduSolar.EPOCH + (double)super.day) - 9D);
+ int aTry;
+ HinduSolar tryDate;
+ for(aTry = approx; precedes(tryDate = new HinduSolar(aTry), this); aTry++);
+ int result;
+ if(tryDate.equals(this))
+ result = aTry;
+ else
+ throw new BogusDateException();
+ return result;
+ }
+
+ public void fromFixed(int date)
+ {
+ int kyTime = OldHinduSolar.dayCount(date);
+ double rise = sunrise(kyTime);
+ super.month = zodiac(rise);
+ super.year = calendarYear(rise) - 3179;
+ int approx = kyTime - 3 - ProtoDate.quotient(ProtoDate.mod(solarLongitude(rise), 1800D), 60D);
+ int begin;
+ for(begin = approx; zodiac(sunrise(begin)) != super.month; begin++);
+ super.day = (kyTime - begin) + 1;
+ }
+
+ public static double hinduSineTable(int entry)
+ {
+ double exact = 3438D * ProtoDate.sinDegrees(((double)entry * 225D) / 60D);
+ double error = 0.215D * (double)ProtoDate.signum(exact) * (double)ProtoDate.signum(Math.abs(exact) - 1716D);
+ return (double)Math.round(exact + error);
+ }
+
+ public static double hinduSine(double theta)
+ {
+ double entry = theta / 225D;
+ double fraction = ProtoDate.mod(entry, 1.0D);
+ return fraction * hinduSineTable((int)Math.ceil(entry)) + (1.0D - fraction) * hinduSineTable((int)Math.floor(entry));
+ }
+
+ public static double hinduArcsin(double units)
+ {
+ boolean neg = units < 0.0D;
+ if(neg)
+ units = -units;
+ int pos;
+ for(pos = 0; units > hinduSineTable(pos); pos++);
+ double val = hinduSineTable(pos - 1);
+ double result = 225D * ((double)(pos - 1) + (units - val) / (hinduSineTable(pos) - val));
+ if(neg)
+ result = -result;
+ return result;
+ }
+
+ public static double meanPosition(double kyTime, double period)
+ {
+ return 21600D * ProtoDate.mod(kyTime / period, 1.0D);
+ }
+
+ public static double truePosition(double kyTime, double period, double size, double anomalistic,
+ double change)
+ {
+ double aLong = meanPosition(kyTime, period);
+ double days = kyTime + 714402296627D;
+ double offset = hinduSine(meanPosition(days, anomalistic));
+ double contraction = (Math.abs(offset) * change * size * 1.0D) / 3438D;
+ double equation = hinduArcsin(offset * (size - contraction));
+ return ProtoDate.mod(aLong - equation, 21600D);
+ }
+
+ public static double solarLongitude(double kyTime)
+ {
+ return truePosition(kyTime, 365.2587564814815D, 0.03888888888888889D, 365.25878920258134D, 0.023809523809523808D);
+ }
+
+ public static int zodiac(double kyTime)
+ {
+ return ProtoDate.quotient(solarLongitude(kyTime), 1800D) + 1;
+ }
+
+ public static boolean precedes(HinduSolar d1, HinduSolar d2)
+ {
+ return ((StandardDate) (d1)).year < ((StandardDate) (d2)).year || ((StandardDate) (d1)).year == ((StandardDate) (d2)).year && (((StandardDate) (d1)).month < ((StandardDate) (d2)).month || ((StandardDate) (d1)).month == ((StandardDate) (d2)).month && ((StandardDate) (d1)).day < ((StandardDate) (d2)).day);
+ }
+
+ public static int calendarYear(double kyTime)
+ {
+ double mean = 21600D * ProtoDate.mod(kyTime / 365.2587564814815D, 1.0D);
+ double real = solarLongitude(kyTime);
+ int year = ProtoDate.quotient(kyTime, 365.2587564814815D);
+ if(real > 20000D && 1000D > mean)
+ return year - 1;
+ if(mean > 20000D && 1000D > real)
+ return year + 1;
+ else
+ return year;
+ }
+
+ public static double equationOfTime(double kyTime)
+ {
+ double offset = hinduSine(meanPosition(714402296627D + kyTime, 365.25878920258134D));
+ double equationSun = offset * (Math.abs(offset) / 3713040D - 0.03888888888888889D);
+ return (((dailyMotion(kyTime) * equationSun * 365.2587564814815D * 1.0D) / 21600D) * 1.0D) / 21600D;
+ }
+
+ public static double ascensionalDifference(double kyTime, double latitude)
+ {
+ double sinDecl = 0.40634089586969169D * hinduSine(tropicalLongitude(kyTime));
+ double diurnalRadius = hinduSine(5400D - hinduArcsin(sinDecl));
+ double tan = hinduSine(latitude) / hinduSine(5400D + latitude);
+ double earthSine = sinDecl * tan;
+ return hinduArcsin((-3438D * earthSine) / diurnalRadius);
+ }
+
+ public static double tropicalLongitude(double kyTime)
+ {
+ double midnight = Math.floor(kyTime);
+ double precession = 1620D - Math.abs(1620D - ProtoDate.mod(0.002464006636472327D * midnight, 6480D));
+ return ProtoDate.mod(solarLongitude(kyTime) - precession, 21600D);
+ }
+
+ public static int risingSign(double kyTime)
+ {
+ int index = ProtoDate.mod(ProtoDate.quotient(tropicalLongitude(kyTime), 1800D), 6);
+ return rs[index];
+ }
+
+ public static double dailyMotion(double kyTime)
+ {
+ double meanMotion = 59.136159275335849D;
+ double anomaly = meanPosition(714402296627D + kyTime, 365.25878920258134D);
+ double epicycle = 0.03888888888888889D - Math.abs(hinduSine(anomaly)) / 3713040D;
+ int entry = ProtoDate.quotient(anomaly, 225D);
+ double sineTableStep = hinduSineTable(entry + 1) - hinduSineTable(entry);
+ double equationOfMotionFactor = sineTableStep * -0.0044444444444444444D * epicycle;
+ return meanMotion * (equationOfMotionFactor + 1.0D);
+ }
+
+ public static double solarSiderealDifference(double kyTime)
+ {
+ return (dailyMotion(kyTime) * (double)risingSign(kyTime) * 1.0D) / 1800D;
+ }
+
+ public static double sunrise(double kyTime)
+ {
+ return kyTime + 0.25D + equationOfTime(kyTime) + 4.6169893048655071E-005D * (ascensionalDifference(kyTime, 1389D) + solarSiderealDifference(kyTime) / 4D);
+ }
+
+ public static double sunriseAtUjjain(int kyTime)
+ {
+ int d = kyTime + OldHinduSolar.EPOCH;
+ double latitude = 23.149999999999999D;
+ double longitude = 75.766666666666666D;
+ return (double)kyTime + ProtoDate.sunrise(d, latitude, longitude);
+ }
+
+
+ public static double sunsetAtUjjain(int kyTime) {
+ int d = kyTime + OldHinduSolar.EPOCH;
+ double latitude = 23.149999999999999D;
+ double longitude = 75.766666666666666D;
+ return (double)kyTime + ProtoDate.sunset(d, latitude, longitude);
+ }
+ public static double samkranti(int gYear, int m)
+ throws BogusDateException
+ {
+ int diff = 3179 + ((StandardDate) (new Gregorian(OldHinduSolar.EPOCH))).year;
+ int hYear = gYear - diff;
+ int ny = toFixed(m, 1, hYear) - OldHinduSolar.EPOCH;
+ double lo = (double)ny - 0.875D;
+ double hi = (double)ny + 0.375D;
+ double begin;
+ for(begin = (hi + lo) / 2D; hi - lo >= 9.9999999999999995E-008D; begin = (hi + lo) / 2D)
+ if(m != 1 ? solarLongitude(begin) >= (double)((m - 1) * 1800) : solarLongitude(begin) < 1800D)
+ hi = begin;
+ else
+ lo = begin;
+
+ return begin + (double)OldHinduSolar.EPOCH;
+ }
+
+ public static double meshaSamkranti(int gYear)
+ {
+ double result = 0.0D;
+ try
+ {
+ result = samkranti(gYear, 1);
+ }
+ catch(BogusDateException _ex) { }
+ return result;
+ }
+
+ public boolean equals(Object obj)
+ {
+ if(!(obj instanceof HinduSolar))
+ return false;
+ else
+ return internalEquals(obj);
+ }
+
+ public static final double SIDEREAL_YEAR = 365.2587564814815D;
+ public static final double CREATION = 714402296627D;
+ public static final double ANOMALISTIC_YEAR = 365.25878920258134D;
+ public static final int SOLAR_ERA = 3179;
+ private static final short rs[] = {
+ 1670, 1795, 1935, 1935, 1795, 1670
+ };
+
+}
+
+
+
+
\ No newline at end of file diff --git a/calendar/java/src/org/panchanga/indic/MalayalamCalendar.java b/calendar/java/src/org/panchanga/indic/MalayalamCalendar.java new file mode 100755 index 0000000..62a812d --- /dev/null +++ b/calendar/java/src/org/panchanga/indic/MalayalamCalendar.java @@ -0,0 +1,172 @@ +package org.panchanga.indic;
+
+import java.util.Date;
+
+import org.panchanga.common.ProtoDate;
+import org.panchanga.common.exception.BogusDateException;
+import org.panchanga.gregorian.Gregorian;
+
+
+
+
+/**
+ * @author Santhosh.thottingal
+ */
+public class MalayalamCalendar {
+ String ml_months[] = { "chingam", "kanni", "thulam", "vrishchikam",
+ "dhanu", "makaram", "kumbham", "meenam", "medam", "edavam",
+ "midhunam", "karkkidakam", };
+
+ private int MSum(int start, int cond) {
+ int total = 0;
+ for (int i = start; HinduSolar.zodiac(HinduSolar.sunriseAtUjjain(i)) != cond; i++) {
+ total++;
+ }
+ return total;
+ }
+
+
+
+ /*
+ * ujjainAparahna[kyTime_] Input : Hindu moment. Output : Hindu moment.
+ * We're computing the IST for aparahna at Ujjain. Accuracy tested within
+ * about 5 minutes.
+ */
+ private double ujjainAparahna(int kyTime) {
+ return HinduSolar.sunriseAtUjjain(kyTime) + 0.6
+ * (HinduSolar.sunriseAtUjjain(kyTime) - HinduSolar.sunriseAtUjjain(kyTime));
+ }
+
+ /*
+ * Input: (solar)month number. Output: malayali month number. The Malayali
+ * calendar uses the Kollem era, not the Saka traditional era. Starting
+ * month of the nirayana year is month 5, the solar month that links with
+ * rasi 5. For example, if month = 5, then malayaliMonth = 1.
+ */
+ private int malayaliMonth(int month) {
+
+ return HinduSolar.adjustedMod(month - 4, 12);
+ }
+
+ /*
+ * malayaliYear[m_, n_] Input : (solar) month and Saka year. Output :
+ * Kollem year. The Malayali calendar uses the Kollem era, not the Saka
+ * traditional era. Starting month of the nirayana year is month 5, the
+ * solar month that links with rasi 5. Hence malayaliYear number changes
+ * to a new year at month 5 and not month 1. =AD-824 or AD-825. Saka=
+ * AD-78
+ */
+ private int malayaliYear(int month, int year) {
+
+ if (1 <= month && month <= 4)
+ return year - 747;
+ else
+ return year - 746;
+ }
+
+ /**
+ * malayaliHinduSolar[date_Integer] Input: Fixed number for RD date.
+ * Output: Malayali calendar date of day at sunrise on RD date. Output may
+ * differ from the actual Malayali calendar date by a day.
+ *
+ * @throws BogusDateException
+ */
+
+ public void malayaliHinduSolar(Date date) throws BogusDateException {
+ int year1 = 0, year2 = 0;
+ double samk2 = 0;
+ double srise2 = 0;
+ double aparahna2 = 0;
+ int kyTime = OldHinduSolar.dayCount(Gregorian.toFixed(4, 14, 1993));
+
+ /*
+ * We find rise2 and month2 at kyTime + 1 because under certain
+ * criteria, the Malayali calendar date is ahead of the HinduSolar
+ * calendar date by a day. Then we make necessary changes to obtain
+ * the malayaliMonth and malayaliYear.
+ */
+ double rise1 = HinduSolar.sunriseAtUjjain(kyTime);
+ double rise2 = HinduSolar.sunriseAtUjjain(kyTime + 1);
+ int month1 = HinduSolar.zodiac(rise1);
+ int month2 = HinduSolar.zodiac(rise2);
+ year1 = HinduSolar.calendarYear(rise1) - HinduSolar.SOLAR_ERA;
+ // HinduSolar.SOLAR_ERA; = Years from Kali Yuga until Saka era. =
+ // (AD+3101)-(AD-78) =3179
+
+ int approx1 = kyTime - 3
+ - ProtoDate.quotient(HinduSolar.solarLongitude(rise1) % 1800, 60);
+ int begin1 = approx1 + MSum(approx1, month1);
+ int day1 = kyTime - begin1 + 1;
+ double samk1 = HinduSolar.samkranti(78 + year1, month1);
+ double srise1 = HinduSolar.sunriseAtUjjain((int)OldHinduSolar
+ .dayCount(Math.abs(samk1)))
+ + OldHinduSolar.EPOCH;
+
+ /*
+ * srise1 is the IST for sunrise for the day of samk1 if the IST for
+ * samk1 falls before midnight. Otherwise srise1 gives the IST for
+ * sunrise for the following day. If the latter is true, then samk1
+ * falls after sunset for the same day.
+ */
+ double aparahna1 = ujjainAparahna((int)OldHinduSolar.dayCount(Math
+ .abs(samk1)))
+ + OldHinduSolar.EPOCH;
+ /* The explanation for aparahna1 is similar to that for srise1. */
+ if (month1 != month2) {
+ /*
+ * If month1!= month2, then month2 is the new month. We need the
+ * IST for the samkranti, the sunrise and the aparahna for the day
+ * of the samkranti and the Saka year for month2.
+ */
+ year2 = HinduSolar.calendarYear(rise2) - HinduSolar.SOLAR_ERA;
+ ;
+ samk2 = HinduSolar.samkranti(78 + year2, month2);
+ srise2 = HinduSolar.sunriseAtUjjain((int)OldHinduSolar
+ .dayCount(Math.abs(samk2)))
+ + OldHinduSolar.EPOCH;
+ aparahna2 = ujjainAparahna((int)OldHinduSolar.dayCount(Math
+ .abs(samk2)))
+ + OldHinduSolar.EPOCH;
+ if ((srise2 <= samk2) && (samk2 < aparahna2)) {
+ /*
+ * If samk1 falls between srise1 and aparahna1 on the same
+ * day, the Malayali rule and the Orissa rule will both agree.
+ */
+ System.out.println(ml_months[malayaliMonth(month2) - 1] + "-"
+ + 1 + "-" + malayaliYear(month2, year2));
+ }
+ else {
+ System.out.println(ml_months[malayaliMonth(month2) - 1] + "-"
+ + (day1 + 1) + "-" + malayaliYear(month2, year2));
+ }
+ }
+ System.out.println(month1);
+ if (month1 == month2) {
+ if ((srise1 <= samk1) && (samk1 < aparahna1)) {
+ /*
+ * If samk1 falls between srise1 and aparahna1 on the same
+ * day, the Malayali rule and the Orissa rule will both agree.
+ */
+ System.out.println(ml_months[malayaliMonth(month1) - 1] + "-"
+ + (day1 + 1) + "-" + malayaliYear(month1, year1));
+ }
+ else {
+ System.out.println(ml_months[malayaliMonth(month1) - 1] + "-"
+ + (day1) + "-" + malayaliYear(month1, year1));
+ }
+
+ }
+
+ }
+
+ public static void main(String[] args) {
+ MalayalamCalendar mlCalendar = new MalayalamCalendar();
+ try {
+ mlCalendar.malayaliHinduSolar(new Date());
+ }
+ catch (BogusDateException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/calendar/java/src/org/panchanga/indic/OldHinduLunar.java b/calendar/java/src/org/panchanga/indic/OldHinduLunar.java new file mode 100755 index 0000000..cca534c --- /dev/null +++ b/calendar/java/src/org/panchanga/indic/OldHinduLunar.java @@ -0,0 +1,99 @@ +
+
+package org.panchanga.indic;
+
+import org.panchanga.common.Date;
+import org.panchanga.common.ProtoDate;
+import org.panchanga.common.exception.BogusDateException;
+
+
+// Referenced classes of package calendrica:
+// Date, BogusDateException, ProtoDate, OldHinduSolar
+
+public class OldHinduLunar extends Date
+{
+
+ public OldHinduLunar()
+ {
+ }
+
+ public OldHinduLunar(int date)
+ {
+ super(date);
+ }
+
+ public OldHinduLunar(Date date)
+ throws BogusDateException
+ {
+ super(date);
+ }
+
+ public OldHinduLunar(int month, boolean leap, int day, int year)
+ {
+ this.month = month;
+ this.leap = leap;
+ this.day = day;
+ this.year = year;
+ }
+
+ public static int toFixed(int month, boolean leap, int day, int year)
+ {
+ double mina = (double)(12 * year - 1) * 30.43822337962963D;
+ double lunarNewYear = 29.530581807581694D * (double)(ProtoDate.quotient(mina, 29.530581807581694D) + 1);
+ return (int)Math.floor((double)OldHinduSolar.EPOCH + lunarNewYear + 29.530581807581694D * (double)(leap || Math.ceil((lunarNewYear - mina) / 0.90764157204793605D) > (double)month ? month - 1 : month) + (double)(day - 1) * 0.9843527269193898D + 0.75D);
+ }
+
+ public int toFixed()
+ {
+ return toFixed(month, leap, day, year);
+ }
+
+ public void fromFixed(int date)
+ {
+ double rise = (double)OldHinduSolar.dayCount(date) + 0.25D;
+ double newMoon = rise - ProtoDate.mod(rise, 29.530581807581694D);
+ leap = 0.90764157204793605D >= ProtoDate.mod(newMoon, 30.43822337962963D) && ProtoDate.mod(newMoon, 30.43822337962963D) > 0.0D;
+ month = 1 + (int)ProtoDate.mod(Math.ceil(newMoon / 30.43822337962963D), 12D);
+ day = 1 + ProtoDate.mod(ProtoDate.quotient(rise, 0.9843527269193898D), 30);
+ year = (int)Math.ceil((newMoon + 30.43822337962963D) / 365.25868055555554D) - 1;
+ }
+
+ public void fromArray(int a[])
+ {
+ month = a[0];
+ leap = a[1] != 0;
+ day = a[2];
+ year = a[3];
+ }
+
+ public static boolean isLeapYear(int lYear)
+ {
+ return ProtoDate.mod((double)lYear * 365.25868055555554D - 30.43822337962963D, 29.530581807581694D) >= 29.530581807581694D - ProtoDate.mod(365.25868055555554D, 29.530581807581694D);
+ }
+
+ protected String toStringFields()
+ {
+ return "month=" + month + ",leap=" + leap + ",day=" + day + ",year=" + year;
+ }
+
+ public boolean equals(Object obj)
+ {
+ if(this == obj)
+ return true;
+ if(!(obj instanceof OldHinduLunar))
+ return false;
+ OldHinduLunar o = (OldHinduLunar)obj;
+ return o.month == month && o.leap == leap && o.day == day && o.year == year;
+ }
+
+ public int month;
+ public boolean leap;
+ public int day;
+ public int year;
+ public static final double ARYA_LUNAR_MONTH = 29.530581807581694D;
+ public static final double ARYA_LUNAR_DAY = 0.9843527269193898D;
+}
+
+
+
+
\ No newline at end of file diff --git a/calendar/java/src/org/panchanga/indic/OldHinduSolar.java b/calendar/java/src/org/panchanga/indic/OldHinduSolar.java new file mode 100755 index 0000000..d7eff3e --- /dev/null +++ b/calendar/java/src/org/panchanga/indic/OldHinduSolar.java @@ -0,0 +1,84 @@ +
+package org.panchanga.indic;
+
+import org.panchanga.common.Date;
+import org.panchanga.common.Julian;
+import org.panchanga.common.ProtoDate;
+import org.panchanga.common.StandardDate;
+import org.panchanga.common.exception.BogusDateException;
+
+
+// Referenced classes of package calendrica:
+// StandardDate, Julian, BogusDateException, ProtoDate,
+// Date
+
+public class OldHinduSolar extends StandardDate
+{
+
+ public OldHinduSolar()
+ {
+ }
+
+ public OldHinduSolar(int date)
+ {
+ super(date);
+ }
+
+ public OldHinduSolar(Date date)
+ throws BogusDateException
+ {
+ super(date);
+ }
+
+ public OldHinduSolar(int month, int day, int year)
+ {
+ super(month, day, year);
+ }
+
+ public static int toFixed(int month, int day, int year)
+ {
+ return (int)Math.floor(((double)EPOCH + (double)year * 365.25868055555554D + (double)(month - 1) * 30.43822337962963D + (double)day) - 0.25D);
+ }
+
+ public int toFixed()
+ {
+ return toFixed(super.month, super.day, super.year);
+ }
+
+ public void fromFixed(int date)
+ {
+ double rise = (double)dayCount(date) + 0.25D;
+ super.year = ProtoDate.quotient(rise, 365.25868055555554D);
+ super.month = 1 + ProtoDate.mod(ProtoDate.quotient(rise, 30.43822337962963D), 12);
+ super.day = 1 + (int)Math.floor(ProtoDate.mod(rise, 30.43822337962963D));
+ }
+
+ public static int dayCount(int date)
+ {
+ return date - EPOCH;
+ }
+
+ public static double dayCount(double date)
+ {
+ return date - (double)EPOCH;
+ }
+
+ public static int jovianYear(int date)
+ {
+ return ProtoDate.mod(ProtoDate.quotient(dayCount(date), 361.02268109734672D), 60) + 1;
+ }
+
+ public boolean equals(Object obj)
+ {
+ if(!(obj instanceof OldHinduSolar))
+ return false;
+ else
+ return internalEquals(obj);
+ }
+
+ public static final int EPOCH = Julian.toFixed(2, 18, Julian.BCE(3102));
+ public static final double ARYA_SIDEREAL_YEAR = 365.25868055555554D;
+ public static final double ARYA_SOLAR_MONTH = 30.43822337962963D;
+ public static final double ARYA_JOVIAN_PERIOD = 4332.2721731681604D;
+
+}
\ No newline at end of file diff --git a/calendar/java/src/org/panchanga/indic/OriyaCalendar.java b/calendar/java/src/org/panchanga/indic/OriyaCalendar.java new file mode 100755 index 0000000..a9cf606 --- /dev/null +++ b/calendar/java/src/org/panchanga/indic/OriyaCalendar.java @@ -0,0 +1,82 @@ +package org.panchanga.indic;
+
+import java.util.Date;
+
+import org.panchanga.common.ProtoDate;
+import org.panchanga.common.exception.BogusDateException;
+import org.panchanga.gregorian.Gregorian;
+
+
+
+
+/**
+ * @author Santhosh.thottingal
+ */
+public class OriyaCalendar {
+ String or_months[] = { "Chaitra", "Baisakhi", "Jyaistha", "Ashadha", "Srabana", "Bhadrapada", "Asvina", "Karthika", "Margashira", "Pausa", "Magha", "Phalguna"};
+
+ private int MSum(int start, int cond) {
+ int total = 0;
+ for (int i = start; HinduSolar.zodiac(HinduSolar.sunriseAtUjjain(i)) != cond; i++) {
+ total++;
+ }
+ return total;
+ }
+
+ /**
+ * oriyaHinduSolar[date_Integer] Input: Fixed number for RD date.
+ * Output: Oriya calendar date of day at sunrise on RD date.
+ *
+ * @throws BogusDateException
+ */
+
+ public void oriyaHinduSolar(Date date) throws BogusDateException {
+ int year = 0;
+ int kyTime = OldHinduSolar.dayCount(Gregorian.toFixed(10, 28, 2008));
+ /*
+ * kyTime gives the number of days of RD date since the start of Kali
+ * Yuga or we can say in Hindu moment.
+ */
+ /*
+ * We find the rise, month, year, approx, begin and day at kyTime + 1
+ * because the Orissa calendar date is ahead of the HinduSolar
+ * calendar date by a day.
+ */
+
+ double rise = HinduSolar.sunriseAtUjjain(kyTime + 1);
+ int month = HinduSolar.zodiac(rise);
+ year = HinduSolar.calendarYear(rise) - HinduSolar.SOLAR_ERA;
+ // HinduSolar.SOLAR_ERA; = Years from Kali Yuga until Saka era. =
+ // (AD+3101)-(AD-78) =3179
+ /* year determines the Saka year in which kyTime + 1 falls. */
+
+ int approx = kyTime - 2
+ - ProtoDate.quotient(HinduSolar.solarLongitude(rise) % 1800, 60);
+ /*
+ * approx is a day in Hindu moment that falls in the previous solar
+ * month.
+ */
+
+ int begin = approx + MSum(approx, month);
+ int day = kyTime - begin + 1;
+ /*
+ * day gives the day count from the starting day of month to kyTime +
+ * 1.
+ */
+ day = day + 1;
+ System.out.println("Year:" + year);
+ System.out.println("Month:" +or_months[month-1]);
+ System.out.println("Day:" + day);
+ }
+
+ public static void main(String[] args) {
+ OriyaCalendar mlCalendar = new OriyaCalendar();
+ try {
+ mlCalendar.oriyaHinduSolar(new Date());
+ }
+ catch (BogusDateException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/calendar/java/src/org/panchanga/indic/SakaCalendar.java b/calendar/java/src/org/panchanga/indic/SakaCalendar.java new file mode 100755 index 0000000..35f5423 --- /dev/null +++ b/calendar/java/src/org/panchanga/indic/SakaCalendar.java @@ -0,0 +1,409 @@ +package org.panchanga.indic;
+/*
+ *******************************************************************************
+ * Copyright (C) 1996-2008, International Business Machines Corporation and *
+ * others. All Rights Reserved. *
+ *******************************************************************************
+ */
+
+
+
+
+/**
+ * <code>IndianCalendar</code> is a subclass of <code>GregorianCalendar</code>
+ * that numbers years since the birth of the Buddha. 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>
+ * This class should not be subclassed.</p>
+ * <p>
+ * IndianCalendar usually should be instantiated using
+ * {@link com.ibm.icu.util.Calendar#getInstance(ULocale)} passing in a <code>ULocale</code>
+ * with the tag <code>"@calendar=Indian"</code>.</p>
+ *
+ * @see com.ibm.icu.util.Calendar
+ * @see com.ibm.icu.util.GregorianCalendar
+ *
+ * @stable ICU 3.8
+ */
+public class SakaCalendar {
+ // jdk1.4.2 serialver
+ private static final long serialVersionUID = 3617859668165014834L;
+
+ /**
+ * Constant for Chaitra, the 1st month of the Indian year.
+ * @stable ICU 3.8
+ */
+ public static final int CHAITRA = 0;
+
+ /**
+ * Constant for Vaisakha, the 2nd month of the Indian year.
+ * @stable ICU 3.8
+ */
+ public static final int VAISAKHA = 1;
+
+ /**
+ * Constant for Jyaistha, the 3rd month of the Indian year.
+ * @stable ICU 3.8
+ */
+ public static final int JYAISTHA = 2;
+
+ /**
+ * Constant for Asadha, the 4th month of the Indian year.
+ * @stable ICU 3.8
+ */
+ public static final int ASADHA = 3;
+
+ /**
+ * Constant for Sravana, the 5th month of the Indian year.
+ * @stable ICU 3.8
+ */
+ public static final int SRAVANA = 4 ;
+
+ /**
+ * Constant for Bhadra, the 6th month of the Indian year.
+ * @stable ICU 3.8
+ */
+ public static final int BHADRA = 5 ;
+
+ /**
+ * Constant for Asvina, the 7th month of the Indian year.
+ * @stable ICU 3.8
+ */
+ public static final int ASVINA = 6 ;
+
+ /**
+ * Constant for Kartika, the 8th month of the Indian year.
+ * @stable ICU 3.8
+ */
+ public static final int KARTIKA = 7 ;
+
+ /**
+ * Constant for Agrahayana, the 9th month of the Indian year.
+ * @stable ICU 3.8
+ */
+ public static final int AGRAHAYANA = 8 ;
+
+ /**
+ * Constant for Pausa, the 10th month of the Indian year.
+ * @stable ICU 3.8
+ */
+ public static final int PAUSA = 9 ;
+
+ /**
+ * Constant for Magha, the 11th month of the Indian year.
+ * @stable ICU 3.8
+ */
+ public static final int MAGHA = 10;
+
+ /**
+ * Constant for Phalguna, the 12th month of the Indian year.
+ * @stable ICU 3.8
+ */
+ public static final int PHALGUNA = 11;
+
+ //-------------------------------------------------------------------------
+ // Constructors...
+ //-------------------------------------------------------------------------
+
+ /**
+ * Constant for the Indian Era. This is the only allowable <code>ERA</code>
+ * value for the Indian calendar.
+ *
+ * @see com.ibm.icu.util.Calendar#ERA
+ * @stable ICU 3.8
+ */
+ public static final int IE = 0;
+
+
+
+
+
+ //-------------------------------------------------------------------------
+ // The only practical difference from a Gregorian calendar is that years
+ // are numbered since the Saka Era. A couple of overrides will
+ // take care of that....
+ //-------------------------------------------------------------------------
+
+ // Starts in 78 AD,
+ private static final int INDIAN_ERA_START = 78;
+
+ // The Indian year starts 80 days later than the Gregorian year.
+ private static final int INDIAN_YEAR_START = 80;
+
+
+
+ /**
+ * {@inheritDoc}
+ * @stable ICU 3.8
+ */
+ protected int handleGetMonthLength(int extendedYear, int month) {
+ if (month < 0 || month > 11) {
+
+ extendedYear += month/12;// floorDivide(month, 12, remainder);
+
+ month = month%12;
+ }
+
+ if(isGregorianLeap(extendedYear + INDIAN_ERA_START) && month == 0) {
+ return 31;
+ }
+
+ if(month >= 1 && month <=5) {
+ return 31;
+ }
+
+ return 30;
+ }
+
+
+ private static final int LIMITS[][] = {
+ // Minimum Greatest Least Maximum
+ // Minimum Maximum
+ { 0, 0, 0, 0}, // ERA
+ { -5000000, -5000000, 5000000, 5000000}, // YEAR
+ { 0, 0, 11, 11}, // MONTH
+ { 1, 1, 52, 53}, // WEEK_OF_YEAR
+ {/* */}, // WEEK_OF_MONTH
+ { 1, 1, 30, 31}, // DAY_OF_MONTH
+ { 1, 1, 365, 366}, // DAY_OF_YEAR
+ {/* */}, // DAY_OF_WEEK
+ { -1, -1, 5, 5}, // DAY_OF_WEEK_IN_MONTH
+ {/* */}, // AM_PM
+ {/* */}, // HOUR
+ {/* */}, // HOUR_OF_DAY
+ {/* */}, // MINUTE
+ {/* */}, // SECOND
+ {/* */}, // MILLISECOND
+ {/* */}, // ZONE_OFFSET
+ {/* */}, // DST_OFFSET
+ { -5000000, -5000000, 5000000, 5000000}, // YEAR_WOY
+ {/* */}, // DOW_LOCAL
+ { -5000000, -5000000, 5000000, 5000000}, // EXTENDED_YEAR
+ {/* */}, // JULIAN_DAY
+ {/* */}, // MILLISECONDS_IN_DAY
+ };
+
+
+ /**
+ * {@inheritDoc}
+ * @stable ICU 3.8
+ */
+ protected int handleGetLimit(int field, int limitType) {
+ return LIMITS[field][limitType];
+ }
+
+
+
+
+ /*
+ * This routine converts an Indian date to the corresponding Julian date"
+ * @param year The year in Saka Era according to Indian calendar.
+ * @param month The month according to Indian calendar (between 1 to 12)
+ * @param date The date in month
+ */
+ private static double IndianToJD(int year, int month, int date) {
+ int 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);
+ jd += m * 31;
+ if (month >= 8) {
+ m = month - 7;
+ jd += m * 30;
+ }
+ jd += date - 1;
+ }
+
+ return jd;
+ }
+
+ /*
+ * The following function is not needed for basic calendar functioning.
+ * This routine converts a gregorian date to the corresponding Julian date"
+ * @param year The year in standard Gregorian calendar (AD/BC) .
+ * @param month The month according to Gregorian calendar (between 0 to 11)
+ * @param date The date in month
+ */
+ private static double gregorianToJD(int year, int month, int date) {
+ double JULIAN_EPOCH = 1721425.5;
+ double jd = (JULIAN_EPOCH - 1) +
+ (365 * (year - 1)) +
+ Math.floor((year - 1) / 4) +
+ (-Math.floor((year - 1) / 100)) +
+ Math.floor((year - 1) / 400) +
+ Math.floor((((367 * month) - 362) / 12) +
+ ((month <= 2) ? 0 :
+ (isGregorianLeap(year) ? -1 : -2)
+ ) +
+ date);
+
+ return jd;
+ }
+
+ /*
+ * The following function is not needed for basic calendar functioning.
+ * This routine converts a julian day (jd) to the corresponding date in Gregorian calendar"
+ * @param jd The Julian date in Julian Calendar which is to be converted to Indian date"
+ */
+ private static int[] jdToGregorian(double jd) {
+ double JULIAN_EPOCH = 1721425.5;
+ double wjd, depoch, quadricent, dqc, cent, dcent, quad, dquad, yindex, yearday, leapadj;
+ int year, month, day;
+
+ wjd = Math.floor(jd - 0.5) + 0.5;
+ depoch = wjd - JULIAN_EPOCH;
+ quadricent = Math.floor(depoch / 146097);
+ dqc = depoch % 146097;
+ cent = Math.floor(dqc / 36524);
+ dcent = dqc % 36524;
+ quad = Math.floor(dcent / 1461);
+ dquad = dcent % 1461;
+ yindex = Math.floor(dquad / 365);
+ year = (int)((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 = (int)Math.floor((((yearday + leapadj) * 12) + 373) / 367);
+ day = (int)(wjd - gregorianToJD(year, month, 1)) + 1;
+
+ int[] julianDate = new int[3];
+
+ julianDate[0] = year;
+ julianDate[1] = month;
+ julianDate[2] = day;
+
+ return julianDate;
+ }
+
+ /*
+ * The following function is not needed for basic calendar functioning.
+ * This routine checks if the Gregorian year is a leap year"
+ * @param year The year in Gregorian Calendar
+ */
+ private static boolean isGregorianLeap(int year)
+ {
+ return ((year % 4) == 0) &&
+ (!(((year % 100) == 0) && ((year % 400) != 0)));
+ }
+
+ public static int[] GregorianToIndian( int[] gregorianDay){
+ int[] indDate=new int[3];;
+ double jdAtStartOfGregYear;
+ int leapMonth, IndianYear, yday, IndianMonth, IndianDayOfMonth, mday;
+ // gregorianDay Stores gregorian date
+
+ // gregorianDay = jdToGregorian(julianDay); // Gregorian date for Julian day
+ IndianYear = gregorianDay[0] - INDIAN_ERA_START; // Year in Saka era
+ jdAtStartOfGregYear = gregorianToJD(gregorianDay[0], 1, 1); // JD at start of Gregorian year
+ double julianDay=gregorianToJD( gregorianDay[0], gregorianDay[1], gregorianDay[2]);
+ yday = (int)(julianDay - jdAtStartOfGregYear); // Day number in Gregorian year (starting from 0)
+
+ if (yday < INDIAN_YEAR_START) {
+ // Day is at the end of the preceding Saka year
+ IndianYear -= 1;
+ leapMonth = isGregorianLeap(gregorianDay[0] - 1) ? 31 : 30; // Days in leapMonth this year, previous Gregorian year
+ yday += leapMonth + (31 * 5) + (30 * 3) + 10;
+ } else {
+ leapMonth = isGregorianLeap(gregorianDay[0]) ? 31 : 30; // Days in leapMonth this year
+ yday -= INDIAN_YEAR_START;
+ }
+
+ if (yday < leapMonth) {
+ IndianMonth = 0;
+ IndianDayOfMonth = yday + 1;
+ } else {
+ mday = yday - leapMonth;
+ if (mday < (31 * 5)) {
+ IndianMonth = (int)Math.floor(mday / 31) + 1;
+ IndianDayOfMonth = (mday % 31) + 1;
+ } else {
+ mday -= 31 * 5;
+ IndianMonth = (int)Math.floor(mday / 30) + 6;
+ IndianDayOfMonth = (mday % 30) + 1;
+ }
+ }
+ /*Month is 0 based.converting it to 1 based*/
+ if(IndianMonth == 12) {
+ IndianMonth = 1;
+ } else {
+ IndianMonth = IndianMonth +1;
+ }
+ indDate[0]=IndianYear;
+ indDate[1]=IndianMonth;
+ indDate[2]=IndianDayOfMonth;
+ System.out.println(IndianDayOfMonth);
+ System.out.println(IndianMonth);
+ System.out.println(IndianYear);
+ return indDate;
+
+ }
+
+ public static void main(String args[]){
+ // System.out.println(jdToGregorian(IndianToJD(1123, 4, 5)));
+ int[] greg={2008,12,31};
+ int[] indDate=new int[3];
+ indDate=GregorianToIndian(greg);
+ greg= jdToGregorian(IndianToJD(indDate[0],indDate[1],indDate[2]));
+ System.out.println(greg[0]+"/"+greg[1]+"/"+greg[2]);
+ }
+}
diff --git a/calendar/java/src/org/panchanga/indic/TamilCalendar.java b/calendar/java/src/org/panchanga/indic/TamilCalendar.java new file mode 100755 index 0000000..baffdac --- /dev/null +++ b/calendar/java/src/org/panchanga/indic/TamilCalendar.java @@ -0,0 +1,132 @@ +package org.panchanga.indic;
+
+import java.util.Date;
+
+import org.panchanga.common.ProtoDate;
+import org.panchanga.common.exception.BogusDateException;
+import org.panchanga.gregorian.Gregorian;
+
+/**
+ * @author Santhosh.thottingal
+ */
+public class TamilCalendar {
+ String ta_months[] = { "Cittirai","Vaikasi", "Ani", "Adi", "Avadi",
+ "Purattasi", "Aippasi", "Karthikai", "Markazhi", "Tai", "Masi",
+ "Paikuni", };
+
+ private int MSum(int start, int cond) {
+ int total = 0;
+ for (int i = start; HinduSolar.zodiac(HinduSolar.sunriseAtUjjain(i)) != cond; i++) {
+ total++;
+ }
+ return total;
+ }
+
+
+
+ /**
+ * malayaliHinduSolar[date_Integer] Input: Fixed number for RD date.
+ * Output: Malayali calendar date of day at sunrise on RD date. Output may
+ * differ from the actual Malayali calendar date by a day.
+ *
+ * @throws BogusDateException
+ */
+
+ public void malayaliHinduSolar(Date date) throws BogusDateException {
+ int year1 = 0, year2 = 0;
+ double samk2 = 0;
+ double srise2 = 0;
+ int kyTime = OldHinduSolar.dayCount(Gregorian.toFixed(11, 4, 2008));
+
+ /*
+ * We find rise2 and month2 at kyTime + 1 because under certain
+ * criteria, the Tamil calendar date is ahead of the HinduSolar
+ * calendar date by a day.
+ */
+
+ double rise1 = HinduSolar.sunriseAtUjjain(kyTime);
+ double rise2 = HinduSolar.sunriseAtUjjain(kyTime + 1);
+ int month1 = HinduSolar.zodiac(rise1);
+ int month2 = HinduSolar.zodiac(rise2);
+ year1 = HinduSolar.calendarYear(rise1) - HinduSolar.SOLAR_ERA;
+ // HinduSolar.SOLAR_ERA; = Years from Kali Yuga until Saka era. =
+ // (AD+3101)-(AD-78) =3179
+
+ int approx1 = kyTime - 3
+ - ProtoDate.quotient(HinduSolar.solarLongitude(rise1) % 1800, 60);
+ int begin1 = approx1 + MSum(approx1, month1);
+ int day1 = kyTime - begin1 + 1;
+ double samk1 = HinduSolar.samkranti(78 + year1, month1);
+ double srise1 = HinduSolar.sunriseAtUjjain((int)OldHinduSolar
+ .dayCount(Math.abs(samk1)))
+ + OldHinduSolar.EPOCH;
+ /*
+ * srise1 is the IST for sunrise for the day of samk1 if the IST for
+ * samk1 falls before midnight. Otherwise srise1 gives the IST for
+ * sunrise for the following day. If the latter is true, then samk1
+ * falls after sunset for the same day.
+ */
+
+ double sset1 = HinduSolar.sunsetAtUjjain((int)OldHinduSolar
+ .dayCount(Math.abs(samk1)))
+ + OldHinduSolar.EPOCH;
+
+ /* The explanation for aparahna1 is similar to that for srise1. */
+ if (month1 != month2) {
+ /*
+ * If month1!= month2, then month2 is the new month. We need the
+ * IST for the samkranti, the sunrise and the aparahna for the day
+ * of the samkranti and the Saka year for month2.
+ */
+ year2 = HinduSolar.calendarYear(rise2) - HinduSolar.SOLAR_ERA;
+ ;
+ samk2 = HinduSolar.samkranti(78 + year2, month2);
+ srise2 = HinduSolar.sunriseAtUjjain((int)OldHinduSolar
+ .dayCount(Math.abs(samk2)))
+ + OldHinduSolar.EPOCH;
+ double sset2 = HinduSolar.sunsetAtUjjain((int)OldHinduSolar
+ .dayCount(Math.abs(samk1)))
+ + OldHinduSolar.EPOCH;
+ if ((srise2 <= samk2) && (samk2 < sset2)) {
+ /*
+ * If samk1 falls between srise2 and sset2 on the same
+ * day, the Tamil rule and the Orissa rule will both agree.
+ */
+ System.out.println(ta_months[month2 - 1] + "-"
+ + 1 + "-" + year2);
+ }
+ else {
+ System.out.println(ta_months[(month2) - 1] + "-"
+ + (day1 + 1) + "-" +year2);
+ }
+ }
+
+ if (month1 == month2) {
+ if ((srise1 <= samk1) && (samk1 < sset1)) {
+ /*
+ * If samk1 falls between srise1 and aparahna1 on the same
+ * day, the Tamil rule and the Orissa rule will both agree.
+ */
+ System.out.println(ta_months[(month1) - 1] + "-"
+ + (day1 + 1) + "-" + year1);
+ }
+ else {
+ System.out.println(ta_months[(month1) - 1] + "-"
+ + (day1) + "-" + year1);
+ }
+
+ }
+
+ }
+
+ public static void main(String[] args) {
+ TamilCalendar mlCalendar = new TamilCalendar();
+ try {
+ mlCalendar.malayaliHinduSolar(new Date());
+ }
+ catch (BogusDateException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
|