Skip to content

Commit 52897b9

Browse files
Use less memory.
1 parent 5d1a772 commit 52897b9

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

moonPhase.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,29 +81,22 @@ static moonData_t _getPhase( const int32_t &year, const int32_t &month, const in
8181
Calculates the phase of the moon at the given epoch.
8282
returns the moon percentage that is lit as a real number (0-1)
8383
*/
84-
moonData_t returnValue;
8584
double j = _Julian(year, month, (double)day + hour / 24.0) - 2444238.5;
8685
double ls = _sun_position(j);
8786
double lm = _moon_position(j, ls);
8887
double t = lm - ls;
8988
if (t < 0) t += 360;
89+
moonData_t returnValue;
9090
returnValue.angle = t;
9191
returnValue.percentLit = (1.0 - cos((lm - ls) * DEG_TO_RAD)) / 2;
9292
return returnValue;
9393
}
9494

95-
moonData_t moonPhase::getPhase()
96-
{
97-
time_t now = time(NULL);
98-
return getPhase( now );
99-
}
100-
10195
moonData_t moonPhase::getPhase( const time_t t )
10296
{
10397
struct tm timeinfo;
10498
gmtime_r( &t, &timeinfo );
105-
double hour = _fhour( timeinfo );
106-
return _getPhase( 1900 + timeinfo.tm_year, 1 + timeinfo.tm_mon, timeinfo.tm_mday, hour );
99+
return _getPhase( 1900 + timeinfo.tm_year, 1 + timeinfo.tm_mon, timeinfo.tm_mday, _fhour( timeinfo ) );
107100
}
108101

109102

moonPhase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct moonData_t
2020
class moonPhase
2121
{
2222
public:
23-
moonData_t getPhase();
23+
moonData_t getPhase(){ return getPhase( time(NULL) ); };
2424
moonData_t getPhase( const time_t t );
2525
};
2626
#endif

0 commit comments

Comments
 (0)