44#include  < sstream> 
55#include  < iomanip> 
66
7+ const  char * tithi[] = { " प्रतिपदा" " द्वितीया" " तृतीया" " चतुर्थी" " पञ्चमी" " षष्ठी" " सप्तमी" " अष्टमी" " नवमी" " दशमी" " एकादशी" " द्वादशी" " त्रयोदशी" " चतुर्दशी" " पूर्णिमा" " प्रतिपदा" " द्वितीया" " तृतीया" " चतुर्थी" " पञ्चमी" " षष्ठी" " सप्तमी" " अष्टमी" " नवमी" " दशमी" " एकादशी" " द्वादशी" " त्रयोदशी" " चतुर्दशी" " औंसी" 
8+ const  char * paksha[] = { " शुक्ल पक्ष" " कृष्ण पक्ष" 
9+ const  char * nakshatra[] = { " अश्विनी" " भरणी" " कृत्तिका" " रोहिणी" " मृगशिरा" " आर्द्रा" " पुनर्वसु" " पुष्य" " आश्रेषा" " मघा" " पूर्वा फाल्गुनी" " उत्तर फाल्गुनी" " हस्त" " चित्रा" " स्वाति" " विशाखा" " अनुराधा" " ज्येष्ठा" " मूला" " पूर्वाषाढा" " उत्तराषाढा" " श्रवण" " श्रविष्ठा" " शतभिषा" " पूर्वा भाद्रपदा" " उत्तर भाद्रपदा" " रेवती" 
10+ const  char * rashi[] = { " मेष" " वृष" " मिथुन" " कर्कट" " सिंह" " कन्या" " तुला" " वृश्चिक" " धनु" " मकर" " कुम्भ" " मीन" 
11+ const  char * karan[] = { " बव" " बालव" " कौलव" " तैतिल" " गर" " वणिज" " विष्टि" " शकुनि" " चतुष्पद" " नाग" " किंस्तुघ्न" 
12+ const  char * yoga[] = { " विष्कुम्भ" " प्रीति" " आयुष्मान्" " सौभाग्य" " शोभन" " अतिगण्ड" " सुकर्मा" " धृति" " शूल" " गण्ड" " वृद्धि" " ध्रुव" " व्याघात" " हर्षण" " वज्र" " सिद्धि" " व्यतीपात" " वरीयान्" " परिघ" " शिव" " सिद्ध" " साध्य" " शुभ" " शुक्ल" " ब्रह्म" " इन्द्र" " वैधृति" 
13+ 
14+ 
15+ 
16+ //  --- Utility functions (defined outside the Panchang class) ---
17+ 
718std::string formatAMPM (int  hours, int  minutes) {
819    int  h_12 = hours % 12 ;
920    if  (h_12 == 0 ) h_12 = 12 ;
@@ -86,9 +97,11 @@ TithiResult calculateTithi(const std::tm& date) {
8697    int  sunriseHour = std::stoi (sunriseStr.substr (0 , 2 ));
8798    int  sunriseMin = std::stoi (sunriseStr.substr (3 , 2 ));
8899    double  jdAtSunrise = julianDay (year, month, day, sunriseHour + sunriseMin / 60.0 , NEPAL_OFFSET);
89-      //  double d_days_since_j2000 = jdAtSunrise - 2451543.5; 
90-     //  For simplicity, use the Panchang class for tithi index 
100+ 
101+     //  Create a Panchang object and let its constructor and methods do the calculation 
91102    Panchang p (jdAtSunrise);
103+ 
104+     //  Now you can safely access the calculated members of the Panchang object
92105    int  tithiIndex = static_cast <int >(p.tithi_index );
93106    int  pakshaIndex = tithiIndex < 15  ? 0  : 1 ;
94107    return  {tithiIndex, tithi[tithiIndex], paksha[pakshaIndex], pakshaIndex};
@@ -158,8 +171,13 @@ RashiResult calculateRashi(const std::tm& date) {
158171    return  {rashiIndex, rashi[rashiIndex]};
159172}
160173
161- double  getSunLongitude (double  d) {
162-     //  Based on the TypeScript logic
174+ //  --- Member functions for the Panchang class ---
175+ 
176+ //  Correctly define this as a member function of Panchang
177+ //  It uses the 'Panchang::' scope resolution operator.
178+ double  Panchang::getSunLongitude () {
179+     //  Use the class's member variable 'tdays' directly
180+     double  d = tdays;
163181    double  w = 282.9404  + 4.70935e-5  * d;
164182    double  e = 0.016709  - 1.151e-9  * d;
165183    double  M = REV (356.0470  + 0.9856002585  * d);
@@ -170,7 +188,11 @@ double getSunLongitude(double d) {
170188    return  REV (v + w);
171189}
172190
173- double  getMoonLongitude (double  d) {
191+ //  Correctly define this as a member function of Panchang
192+ //  It uses the 'Panchang::' scope resolution operator.
193+ double  Panchang::getMoonLongitude () {
194+     //  Use the class's member variable 'tdays' directly
195+     double  d = tdays;
174196    double  N = REV (125.1228  - 0.0529538083  * d);
175197    double  i = 5.1454 ;
176198    double  w = REV (318.0634  + 0.1643573223  * d);
@@ -187,7 +209,8 @@ double getMoonLongitude(double d) {
187209    double  yh = r_dist * (sin (N * D2R) * cos ((v_true_anomaly + w) * D2R) + cos (N * D2R) * sin ((v_true_anomaly + w) * D2R) * cos (i * D2R));
188210    double  moonLon = REV (R2D * atan2 (yh, xh));
189211    //  Periodic corrections (simplified, as in TS)
190-     double  D_elong = REV (L0 - getSunLongitude (d));
212+     //  NOTE: This correctly calls the member function getSunLongitude()
213+     double  D_elong = REV (L0 - getSunLongitude ());
191214    double  Ms_global = REV (356.0470  + 0.9856002585  * d);
192215    moonLon += -1.274  * sin ((M - 2  * D_elong) * D2R);
193216    moonLon += +0.658  * sin ((2  * D_elong) * D2R);
@@ -204,6 +227,22 @@ double getMoonLongitude(double d) {
204227    return  REV (moonLon);
205228}
206229
230+ //  Correct implementation of the Panchang class method
207231void  Panchang::calculateTithi () {
208-     TithiResult calculateTithi (const  std::tm& date);
232+     double  sunLongitude = getSunLongitude ();
233+     double  moonLongitude = getMoonLongitude ();
234+ 
235+     //  Calculate the difference in longitude and normalize it
236+     double  tithiElongation = REV (moonLongitude - sunLongitude);
237+ 
238+     //  Calculate the tithi index (360 degrees / 12 degrees per tithi = 30 tithis)
239+     tithi_index = std::floor (tithiElongation / 12.0 );
240+ 
241+     //  Determine the Paksha (bright or dark half of the lunar month)
242+     //  The first 15 tithis are Shukla Paksha (bright), the next 15 are Krishna Paksha (dark)
243+     if  (tithi_index < 15 ) {
244+         paksha = " शुक्ल पक्ष" //  Shukla Paksha
245+     } else  {
246+         paksha = " कृष्ण पक्ष" //  Krishna Paksha
247+     }
209248}
0 commit comments