25 #include "lunarphase.h"
26 #include <config-kholidays.h>
30 #include <KLocalizedString>
32 #include <QtCore/QDateTime>
34 using namespace KHolidays;
36 static double percentFull( uint tmpt );
37 static double degreesToRadians(
double degree );
38 static void adj360(
double *degree );
49 return( i18n(
"New Moon" ) );
51 return( i18n(
"Full Moon" ) );
53 return( i18n(
"First Quarter Moon" ) );
55 return( i18n(
"Last Quarter Moon" ) );
67 const QTime anytime( 12, 0, 0 );
68 const QDateTime today( date, anytime, Qt::UTC );
69 const double todayPer = percentFull( today.
toTime_t() ) + 0.5;
72 const double tomorrowPer = percentFull( tomorrow.toTime_t() ) + 0.5;
74 if ( static_cast<int>( todayPer ) == 100 &&
75 static_cast<int>( tomorrowPer ) != 100 ) {
77 }
else if ( static_cast<int>( todayPer ) == 0 &&
78 static_cast<int>( tomorrowPer ) != 0 ) {
81 if ( todayPer > 50 && tomorrowPer < 50 ) {
84 if ( todayPer < 50 && tomorrowPer > 50 ) {
130 #ifdef HAVE_SYS_CDEFS_H
131 #include <sys/cdefs.h>
156 static double PI = 3.14159265358979323846;
164 static int EPOCH_MINUS_1970 = ( 20 * 365 + 5 - 1 );
165 static double EPSILONg = 279.403303;
166 static double RHOg = 282.768422;
167 static double ECCEN = 0.016713;
168 static double lzero = 318.351648;
169 static double Pzero = 36.340410;
170 static double Nzero = 318.510107;
176 static double percentFull( uint tmpt )
178 double N, Msol, Ec, LambdaSol, l, Mm, Ev, Ac, A3, Mmprime;
179 double A4, lprime, V, ldprime, D, Nm;
182 days = ( tmpt - EPOCH_MINUS_1970 * 86400 ) / 86400.0;
184 N = 360 * days / 365.242191;
186 Msol = N + EPSILONg - RHOg;
188 Ec = 360 / PI * ECCEN * sin( degreesToRadians( Msol ) );
189 LambdaSol = N + Ec + EPSILONg;
190 adj360( &LambdaSol );
191 l = 13.1763966 * days + lzero;
193 Mm = l - ( 0.1114041 * days ) - Pzero;
195 Nm = Nzero - ( 0.0529539 * days );
197 Ev = 1.2739 * sin( degreesToRadians( 2 * ( l - LambdaSol ) - Mm ) );
198 Ac = 0.1858 * sin( degreesToRadians( Msol ) );
199 A3 = 0.37 * sin( degreesToRadians( Msol ) );
200 Mmprime = Mm + Ev - Ac - A3;
201 Ec = 6.2886 * sin( degreesToRadians( Mmprime ) );
202 A4 = 0.214 * sin( degreesToRadians( 2 * Mmprime ) );
203 lprime = l + Ev + Ec - Ac + A4;
204 V = 0.6583 * sin( degreesToRadians( 2 * ( lprime - LambdaSol ) ) );
205 ldprime = lprime + V;
206 D = ldprime - LambdaSol;
207 D = 50.0 * ( 1 - cos( degreesToRadians( D ) ) );
215 static double degreesToRadians(
double degree )
217 return ( degree * PI ) / 180.00;
224 static void adj360(
double *degree )
229 }
else if ( *degree > 360 ) {
Last quarter of moon phase.
First quarter of moon phase.
static QString phaseName(Phase phase)
Return the string representation of phase.
static QString phaseNameAtDate(const QDate &date)
Return the lunar phase as a text string for the specified date.
Phase
Phases of the moon, in traditional English notation.
static Phase phaseAtDate(const QDate &date)
Return the lunar phase for the specified Gregorian date.
QDate addDays(int ndays) const