From c31df927f64b74f83a9b37fe18d8ec02a351d03c Mon Sep 17 00:00:00 2001
From: samuel <53528911+samuel-jimenez@users.noreply.github.com>
Date: Thu, 5 Dec 2024 09:13:38 -0600
Subject: [PATCH] Cleanup Javascript, Update license to GPL3

---
 package/LICENSE.GPL2                 | 341 -------------------
 package/contents/ui/LunaIcon.qml     |  11 -
 package/contents/ui/code/lunacalc.js | 235 ++++++-------
 package/contents/ui/code/phases.js   | 483 ++++++++++-----------------
 package/contents/ui/main.qml         |  16 +-
 5 files changed, 285 insertions(+), 801 deletions(-)
 delete mode 100644 package/LICENSE.GPL2

diff --git a/package/LICENSE.GPL2 b/package/LICENSE.GPL2
deleted file mode 100644
index 667d40e..0000000
--- a/package/LICENSE.GPL2
+++ /dev/null
@@ -1,341 +0,0 @@
-
-		    GNU GENERAL PUBLIC LICENSE
-		       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
- 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-			    Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-		    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term "modification".)  Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-			    NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-		     END OF TERMS AND CONDITIONS
-
-	    How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) year name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  <signature of Ty Coon>, 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/package/contents/ui/LunaIcon.qml b/package/contents/ui/LunaIcon.qml
index 3332d07..84bf4d9 100644
--- a/package/contents/ui/LunaIcon.qml
+++ b/package/contents/ui/LunaIcon.qml
@@ -30,7 +30,6 @@ import org.kde.plasma.plasmoid
 Item {
     id: lunaIcon
 
-    property int phaseNumber: 0
     property int latitude: 90 //Degrees: 0=Equator, 90=North Pole, -90=South Pole
     property bool showShadow: true
     property bool transparentShadow: true
@@ -101,9 +100,7 @@ Item {
                     startAngle: 0
                     sweepAngle: 360
                 }
-
             }
-
         }
 
         Canvas {
@@ -180,11 +177,9 @@ Item {
                     // Copernicus
                     if (showCopernicus)
                         marker(radius, 9.6, -20);
-
                 }
             }
         }
-
     }
 
     ShaderEffectSource {
@@ -234,11 +229,9 @@ Item {
                 }
             }
         }
-
     }
 
     ShaderEffectSource {
-
         id: lunaMask
 
         anchors.centerIn: parent
@@ -268,11 +261,8 @@ Item {
                     startAngle: 0
                     sweepAngle: 360
                 }
-
             }
-
         }
-
     }
 
     ShaderEffect {
@@ -289,5 +279,4 @@ Item {
         anchors.fill: lunaBackground
         fragmentShader: "shadow.qsb"
     }
-
 }
diff --git a/package/contents/ui/code/lunacalc.js b/package/contents/ui/code/lunacalc.js
index 6172cc4..3baf500 100644
--- a/package/contents/ui/code/lunacalc.js
+++ b/package/contents/ui/code/lunacalc.js
@@ -1,170 +1,151 @@
 /**
 
-    Copyright 1998, 2000  Stephan Kulow <coolo@kde.org>
-    Copyright 2008 by Davide Bettio <davide.bettio@kdemail.net>
-    Copyright (C) 2009, 2011, 2012, 2013 Glad Deschrijver <glad.deschrijver@gmail.com>
-		Copyright 2017 Bill Binder <dxtwjb@gmail.com>
+	Copyright 1998, 2000  Stephan Kulow <coolo@kde.org>
+	Copyright 2008 by Davide Bettio <davide.bettio@kdemail.net>
+	Copyright (C) 2009, 2011, 2012, 2013 Glad Deschrijver <glad.deschrijver@gmail.com>
+	Copyright 2017 Bill Binder <dxtwjb@gmail.com>
+	Copyright (C) 2024 Samuel Jimenez <therealsamueljimenez@gmail.com>
 
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
+	This program is free software; you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation; either version 3 of the License, or
+	(at your option) any later version.
 
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
+	This program is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
 
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, see <http://www.gnu.org/licenses/>.
+	You should have received a copy of the GNU General Public License
+	along with this program; if not, see <http://www.gnu.org/licenses/>.
 
 */
 
 var lunation = 0;
 
-function getLunation(time)
-{
-	//var lunation = 0;
-	var nextNew = new Date(0);
-
-	// obtain reasonable start value for lunation so that the while loop below has a minimal amount of iterations (for faster startup of the plasmoid)
-	var reference = 947178885000; // number of milliseconds between 1970-01-01 00:00:00 and 2000-01-06 18:14:45 (first new moon of 2000, see lunation in phases.js)
-	var lunationDuration = 2551442877; // number of milliseconds in 29.530588853 days (average lunation duration, same number as in (47.1) in phases.js)
-//	var lunationDuration = 2583360000; // number of milliseconds in 29.9 days (maximum lunation duration, see wikipedia on synodic month); use this if the bug ever appears that the lunar phases displayed at startup are too much in the future
-	var lunation = Math.floor((time.getTime() - reference) / lunationDuration);
-
-	do {
-		var JDE = Phases.moonphasebylunation(lunation, 0);
-		nextNew = Phases.JDtoDate(JDE);
-		lunation++;
-	} while (nextNew < time);
-
-	lunation -= 2;
-	return lunation;
-}
 
 function getPhasesByLunation(lunation)
 {
 	var phases = new Array();
-	phases[0] = Phases.JDtoDate(Phases.moonphasebylunation(lunation, 0)); // new moon
-	phases[1] = Phases.JDtoDate(Phases.moonphasebylunation(lunation, 1)); // first quarter
-	phases[2] = Phases.JDtoDate(Phases.moonphasebylunation(lunation, 2)); // full moon
-	phases[3] = Phases.JDtoDate(Phases.moonphasebylunation(lunation, 3)); // last quarter
-	phases[4] = Phases.JDtoDate(Phases.moonphasebylunation(lunation+1, 0)); // next new moon
+	phases[0] = Phases.DatefromJD(Phases.moonphasebylunation(lunation, 0)) // new moon
+	phases[1] = Phases.DatefromJD(Phases.moonphasebylunation(lunation, 1)) // first quarter
+	phases[2] = Phases.DatefromJD(Phases.moonphasebylunation(lunation, 2)) // full moon
+	phases[3] = Phases.DatefromJD(Phases.moonphasebylunation(lunation, 3)) // last quarter
+	phases[4] = Phases.DatefromJD(Phases.moonphasebylunation(lunation + 1, 0)) // next new moon
 	return phases;
 }
 
 function getTodayPhases()
 {
-	var today = new Date();
-	lunation = getLunation(today);
-	return getPhasesByLunation(lunation);
+	var today = new Date()
+	lunation = Phases.getLunation(today)
+	return getPhasesByLunation(lunation)
 }
 
 function getPreviousPhases()
 {
-	lunation--;
-	return getPhasesByLunation(lunation);
+	lunation--
+	return getPhasesByLunation(lunation)
 }
 
 function getNextPhases()
 {
-	lunation++;
-	return getPhasesByLunation(lunation);
+	lunation++
+	return getPhasesByLunation(lunation)
 }
 
 function reloadPhases()
 {
-	return getPhasesByLunation(lunation);
+	return getPhasesByLunation(lunation)
 }
 
-function getCurrentPhase(interpolate) // this function assumes that today is between phases[0] (last new moon) and phases[4] (next new moon)
+
+
+function getCurrentPhase()
 {
 
-	var oneDay = 1000 * 60 * 60 * 24;
-	var today = new Date().getTime();
-	var phases = getTodayPhases();
-
-  var terminator;
-  if (interpolate) {
-		  // Estimate where the terminator is - base this on knowing where it
-		  // is at each quarter, and interpolating. Cowboy maths.
-		  // Determines how far into the current quarter we are, and uses
-		  // the result to work out where the terminator is. This allows for
-		  // the quarters being different sizes, rather than assuming they are
-		  // each one quarter of the cycle time.
-
-		  var qnum = 0;
-		  while (today > phases[qnum+1] && qnum < 3) {
-		     qnum++;
-		  }
-		  var quarterTime = phases[qnum+1].getTime() - phases[qnum].getTime();
-		  var sinceQuarter = today - phases[qnum].getTime();
-		  terminator = Math.floor(((sinceQuarter / quarterTime) + qnum) * 90);
-  }
-	else {
-		  // Work out where the terminator is, 0..359 degrees.
-			// This assumes a constant rate for the month, which is unlikely
-		  var cycleTime = phases[4].getTime() - phases[0].getTime();
-		  var sinceNew = today - phases[0].getTime();
-		  terminator = Math.floor((sinceNew / cycleTime) * 360);
-  }
-
-  // Keep this in the range [0,360):
-	if (terminator >= 360) {
-		terminator -= 360;
+	var today = new Date().getTime() // this function assumes that today is between phases[0] (last new moon) and phases[4] (next new moon)
+	var phases = getTodayPhases()
+	var terminator
+	var lunaCalc={
+		terminator:terminator,
+		text: "",
+		subText: ""}
+
+	// Estimate where the terminator is - base this on knowing where it
+	// is at each quarter, and interpolating. Cowboy maths.
+	// Determines how far into the current quarter we are, and uses
+	// the result to work out where the terminator is. This allows for
+	// the quarters being different sizes, rather than assuming they are
+	// each one quarter of the cycle time.
+
+	var qnum = 0
+	while (today > phases[qnum+1] && qnum < 3) {
+		qnum++
 	}
-	//console.log("Terminator: " + terminator.toString());
+	var quarterTime = phases[qnum+1].getTime() - phases[qnum].getTime()
+	var sinceQuarter = today - phases[qnum].getTime()
+	terminator = Math.floor(((sinceQuarter / quarterTime) + qnum) * 90)
 
-	// set time for all phases to 00:00:00 in order to obtain the correct phase for today (these changes should be local)
+	// Keep this in the range [0,360):
+	lunaCalc.terminator = terminator % 360
+
+	// set time for all phases to 00:00:00 (midnight local time) in order to obtain the correct phase for today
 	for (var i = 0; i < 5; i++) {
-		phases[i].setHours(0);
-		phases[i].setMinutes(0);
-		phases[i].setSeconds(0);
+		phases[i].setHours(0)
+		phases[i].setMinutes(0)
+		phases[i].setSeconds(0)
 	}
 
-	// if today <= first quarter, calculate day since last new moon
-	var daysFromFirstQuarter = Math.floor((today - phases[1].getTime()) / oneDay);
-	if (daysFromFirstQuarter == 0)
-		return {number: 7, terminator:terminator, text: i18n("First Quarter"), subText: ""};
-	else if (daysFromFirstQuarter < 0) {
-		var daysFromLastNew = Math.floor((today - phases[0].getTime()) / oneDay);
-		if (daysFromLastNew == 0)
-			return {number: 0, terminator:terminator, text: i18n("New Moon"), subText: ""};
-		else if (daysFromLastNew == 1)
-			return {number: 1, terminator:terminator, text: i18n("Waxing Crescent"), subText: i18n("Yesterday was New Moon")};
-		else // assume that today >= last new moon
-			return {number: daysFromLastNew, terminator:terminator, text: i18n("Waxing Crescent"), subText: i18n("%1 days since New Moon", daysFromLastNew)};
-	}
 
-	// if today >= third quarter, calculate day until next new moon
-	var daysFromThirdQuarter = Math.floor((today - phases[3].getTime()) / oneDay);
-	if (daysFromThirdQuarter == 0)
-		return {number: 21, terminator:terminator, text: i18n("Last Quarter"), subText: ""};
-	else if (daysFromThirdQuarter > 0) {
-		var daysToNextNew = -Math.floor((today - phases[4].getTime()) / oneDay);
-		if (daysToNextNew == 0)
-			return {number: 0, terminator:terminator, text: i18n("New Moon"), subText: ""};
-		else if (daysToNextNew == 1)
-			return {number: 27, terminator:terminator, text: i18n("Waning Crescent"), subText: i18n("Tomorrow is New Moon")};
-		else // assume that today <= next new moon
-			return {number: 28 - daysToNextNew, terminator:terminator, text: i18n("Waning Crescent"), subText: i18n("%1 days to New Moon", daysToNextNew)};
-	}
 
-	// in all other cases, calculate day from or until full moon
-	var daysFromFullMoon = Math.floor((today - phases[2].getTime()) / oneDay);
-	if (daysFromFullMoon == 0)
-		return {number: 14, terminator:terminator, text: i18n("Full Moon"), subText: ""};
-	else if (daysFromFullMoon == -1)
-		return {number: 13, terminator:terminator, text: i18n("Waxing Gibbous"), subText: i18n("Tomorrow is Full Moon")};
-	else if (daysFromFullMoon < -1)
-		return {number: 14 + daysFromFullMoon, terminator:terminator, text: i18n("Waxing Gibbous"), subText: i18n("%1 days to Full Moon", -daysFromFullMoon)};
-	else if (daysFromFullMoon == 1)
-		return {number: 15, terminator:terminator, text: i18n("Waning Gibbous"), subText: i18n("Yesterday was Full Moon")};
-	else if (daysFromFullMoon > 1)
-		return {number: 14 + daysFromFullMoon, terminator:terminator, text: i18n("Waning Gibbous"), subText: i18n("%1 days since Full Moon", daysFromFullMoon)};
-
-	// this should never happen:
-	console.log("We cannot count :-(");
-	return {number: -1, text: ""};
+	var daysFromLastNew = Math.floor((today - phases[0].getTime()) / Phases.MS_PER_DAY)
+	var daysFromFirstQuarter = Math.floor((today - phases[1].getTime()) / Phases.MS_PER_DAY)
+	var daysFromFullMoon = Math.floor((today - phases[2].getTime()) / Phases.MS_PER_DAY)
+	var daysFromThirdQuarter = Math.floor((today - phases[3].getTime()) / Phases.MS_PER_DAY)
+	var daysToNextNew = -Math.floor((today - phases[4].getTime()) / Phases.MS_PER_DAY)
+	if (daysFromLastNew == 0 || daysToNextNew == 0){
+		lunaCalc.text=i18n("New Moon")
+	} else if (daysFromFirstQuarter == 0){
+		lunaCalc.text=i18n("First Quarter")
+	} else if (daysFromFullMoon == 0){
+		lunaCalc.text=i18n("Full Moon")
+	} else if (daysFromThirdQuarter == 0){
+		lunaCalc.text=i18n("Last Quarter")
+	} else if (daysFromFirstQuarter < 0) {
+		// if today <= first quarter, calculate day since last new moon
+		lunaCalc.text=i18n("Waxing Crescent")
+		if (daysFromLastNew == 1){
+			lunaCalc.subText=i18n("Yesterday was New Moon")
+		} else{// assume that today >= last new moon
+			lunaCalc.subText=i18n("%1 days since New Moon", daysFromLastNew)
+		}
+	} else if (daysFromThirdQuarter > 0) {
+		// if today >= third quarter, calculate day until next new moon
+		lunaCalc.text=i18n("Waning Crescent")
+		if (daysToNextNew == 1){
+			lunaCalc.subText=i18n("Tomorrow is New Moon")}
+		else {// assume that today <= next new moon
+			lunaCalc.subText=i18n("%1 days to New Moon", daysToNextNew)}
+	} else if (daysFromFullMoon < 0) {
+		// if today >= full moon, calculate day until full moon
+		lunaCalc.text=i18n("Waxing Gibbous")
+		if (daysFromFullMoon == -1){
+			lunaCalc.subText=i18n("Tomorrow is Full Moon")
+		} else {
+			lunaCalc.subText=i18n("%1 days to Full Moon", -daysFromFullMoon)
+		}
+	} else if (daysFromFullMoon > 0){
+		// in all other cases, calculate day since full moon
+		lunaCalc.text=i18n("Waning Gibbous")
+		if (daysFromFullMoon == 1){
+			lunaCalc.subText=i18n("Yesterday was Full Moon")
+		} else{
+			lunaCalc.subText=i18n("%1 days since Full Moon", daysFromFullMoon)
+		}
+	} else {
+		// this should never happen:
+		console.log("We cannot count :-(", today)
+	}
+	return lunaCalc
 }
diff --git a/package/contents/ui/code/phases.js b/package/contents/ui/code/phases.js
index 45d3656..8a13aa6 100644
--- a/package/contents/ui/code/phases.js
+++ b/package/contents/ui/code/phases.js
@@ -1,4 +1,7 @@
 /*
+
+	Copyright (C) 2024 Samuel Jimenez <therealsamueljimenez@gmail.com>
+
 	JavaScript version
 	Copyright 2011 Glad Deschrijver <glad.deschrijver@gmail.com>
 	with the same license as below.
@@ -10,7 +13,7 @@
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Library General Public
     License as published by the Free Software Foundation; either
-    version 2 of the License, or (at your option) any later version.
+    version 3 of the License, or (at your option) any later version.
 
     This library is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -21,130 +24,73 @@
     along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
 
-.pragma library
 
-/*
-** jd.c:
-** 1996/02/11
-**
-** Copyright 1996, Christopher Osburn, Lunar Outreach Services, <chris@speakeasy.org>
-** Non-commercial usage license granted to all.
-**
-** convert a Julian Day number to a struct tm
-**
-** Parameter:
-**   double jd:  Julian day number with fraction of day
-**
-** Returns:
-**   struct tm *event_date:  Date-time group holding year, month, day, hour,
-**                and minute of the event
-*/
-
-function JDtoDate(jd) // convert a Julian Date to a date-time group
-{
-	var a, a1, z, b, c, d, e;
-	var f, day;
-	var event_date = new Date();
 
-	jd += 0.5;
-	z = Math.floor(jd);
-	f = jd - z;
-
-	if (z < 2299161)
-	{
-		a = z;
-	}
-	else
-	{
-		a1 = Math.floor((z - 1867216.25) / 36524.25);
-		a = z + 1 + a1 - Math.floor(a1 / 4);
-	}
-
-	b = a + 1524;
-	c = Math.floor((b - 122.1) / 365.25);
-	d = Math.floor(365.25 * c);
-	e = Math.floor((b - d)/30.6001);
-
-	day = b - d - Math.floor(30.6001 * e) + f;
-
-	event_date.setDate(1); // dirty hack, otherwise if today is the 31st of a month and the month below is set to a month with < 31 days, then the month is shifted to the next month, e.g. Feb 31 becomes Mar 2; the correct day is set further below
-	if (e < 14)
-		event_date.setMonth((e - 1) - 1);
-	else
-		event_date.setMonth((e - 13) - 1);
-
-	if (event_date.getMonth() > (2 - 1))
-		event_date.setFullYear(c - 4716);
-	else
-		event_date.setFullYear(c - 4715);
-
-	event_date.setDate(Math.floor(day));
-	day -= event_date.getDate();
-	day *= 24;
-	event_date.setHours(Math.floor(day));
-	day -= event_date.getHours();
-	day *= 60;
-	event_date.setMinutes(Math.floor(day));
-	day -= event_date.getMinutes();
-	day *= 60;
-	event_date.setSeconds(Math.floor(day));
-
-	return event_date;
-}
+.pragma library
 
-function DatetoJD(event_date) // convert a date-time group to a JD with fraction
+// var LUNATION_OFFSET = 953//lunation of LUNATION_EPOCH in Brown Lunation Number
+const LUNATION_OFFSET = 0//lunation of LUNATION_EPOCH using Meeus's Lunation Number
+// LUNATION_EPOCH
+//date of first new moon of 2000 (2000-01-06 18:14:00)
+const LUNATION_EPOCH_MS = 947182440000// number of milliseconds between 1970-01-01 00:00:00 and epoch
+const LUNATION_EPOCH_JD = 2451550.259722222//epoch in JD
+
+// milliseconds in one day
+const MS_PER_DAY = 86400000
+
+// average lunation duration
+const LUNATION_CYCLE_DURATION = 29.530588853
+const LUNATION_CYCLE_DURATION_MS = 2551442877
+
+/* DatefromJD(int) => Date
+ *
+ * convert a Julian Date to a JavaScript Date object
+ */
+function DatefromJD(jd)
 {
-	var y, m;
-	var d;
-	var a, b;
-	var jd;
-
-	y = event_date.getFullYear();
-	m = event_date.getMonth() + 1;
-	d = event_date.getDate() + (event_date.getHours() / 24.0)
-	  + (event_date.getMinutes() / 1440.0)
-	  + (event_date.getSeconds() / 86400.0);
-
-	if (m == 1 || m == 2)
-	{
-		y--;
-		m += 12;
-	}
-
-	a = Math.floor(y / 100);
-	b = 2 - a + Math.floor(a / 4);
-
-	if (y < 1583)
-		if ((y < 1582) || (m < 10) || ((m == 10) && (d <= 15)))
-			b = 0;
-
-	jd = Math.floor(365.25 * (y + 4716)) + Math.floor(30.6001 * (m+1))
-	   + d + b - 1524.5;
-
-	return jd;
+	// convert to epoch time, then instantiate Date
+	return new Date((jd - 2440587.5) * MS_PER_DAY)
 }
 
-/*
-** misc.h
-** 1996/02/11
-**
-** Copyright 1996, Christopher Osburn, Lunar Outreach Services,
-** Non-commercial usage license granted to all.
-**
-** Miscellaneous routines for moon phase programs
-**
-*/
+/* radian(x) : x in Reals -> [-2 PI, 2 PI]
+ *
+ * convert x to radians from degrees
+ */
 
-function fmod(x, y)
+function radian(x)
 {
-	var n = ((x > 0 && y > 0) || (x < 0 && y < 0)) ? Math.floor(x / y) : Math.ceil(x / y);
-	return x - n * y;
+	return ((x % 360.0) * Math.PI/180)
 }
 
-function torad(x) // convert x to radians
+/* getLunation(Date time) => int lunation
+ *
+ * Given time, returns number of lunation time falls in
+ *
+ */
+function getLunation(time)
 {
-	x = fmod(x, 360.0); // normalize the angle
-	return ((x) * 0.01745329251994329576); // and return the result
+
+	// find lunation
+	var lunation = Math.floor((time.getTime() - LUNATION_EPOCH_MS) / LUNATION_CYCLE_DURATION_MS) + LUNATION_OFFSET
+
+	//verify result
+	var currNew = DatefromJD(moonphasebylunation(lunation, 0))
+	var nextNew
+	while (currNew > time) {
+		// math is off: log result
+		console.log("Lunation number", lunation, "too high for", time.toISOString())
+		lunation--
+		currNew = DatefromJD(moonphasebylunation(lunation, 0))
+	}
+	nextNew = DatefromJD(moonphasebylunation(lunation + 1, 0))
+	while (nextNew < time) {
+		// math is off: log result
+		console.log("Lunation number", lunation, "too low for", time.toISOString())
+		lunation++
+		nextNew = DatefromJD(moonphasebylunation(lunation + 1, 0))
+	}
+
+	return lunation;
 }
 
 /*
@@ -154,7 +100,7 @@ function torad(x) // convert x to radians
 ** Copyright 1996, Christopher Osburn, Lunar Outreach Services,
 ** Non-commercial usage license granted to all.
 **
-** calculate phase of the moon per Meeus Ch. 47
+** calculate phase of the moon per Meeus Ch. 47 (ISBN:9780943396613)
 **
 ** Parameters:
 **    int lun:  phase parameter.  This is the number of lunations
@@ -165,206 +111,123 @@ function torad(x) // convert x to radians
 **
 ** Return:  Apparent JD of the needed phase
 */
-
-function moonphase(k, phi)
+function moonphasebylunation(lun, phi)
 {
-	var i;                    // iterator to be named later.  Every program needs an i
-	var T;                    // time parameter, Julian Centuries since J2000
-	var JDE;                  // Julian Ephemeris Day of phase event
-	var E;                    // Eccentricity anomaly
-	var M;                    // Sun's mean anomaly
-	var M1;                   // Moon's mean anomaly
-	var F;                    // Moon's argument of latitude
-	var O;                    // Moon's longitude of ascending node
-	var A = new Array();      // planetary arguments
-	var W;                    // added correction for quarter phases
-
-	T = k / 1236.85;                          // (47.3)
-
-	// this is the first approximation.  all else is for style points!
-	JDE = 2451550.09765 + (29.530588853 * k)  // (47.1)
-	    + T * T * (0.0001337 + T * (-0.000000150 + 0.00000000073 * T));
-
-	// these are correction parameters used below
-	E = 1.0                                   // (45.6)
-	  + T * (-0.002516 + -0.0000074 * T);
-	M = 2.5534 + 29.10535669 * k              // (47.4)
-	  + T * T * (-0.0000218 + -0.00000011 * T);
-	M1 = 201.5643 + 385.81693528 * k          // (47.5)
-	   + T * T * (0.0107438 + T * (0.00001239 + -0.000000058 * T));
-	F = 160.7108 + 390.67050274 * k           // (47.6)
-	  + T * T * (-0.0016341 * T * (-0.00000227 + 0.000000011 * T));
-	O = 124.7746 - 1.56375580 * k             // (47.7)
-	  + T * T * (0.0020691 + 0.00000215 * T);
+	var k = lun - LUNATION_OFFSET + phi / 4.0
+
+	// Julian Ephemeris Day of phase event
+	var JDE
+
+	// time parameter, Julian Centuries since LUNATION_EPOCH (47.3)
+	var T = k / 1236.85
+
+	// Eccentricity anomaly (45.6)
+	var E = 1.0 + T * (-0.002516 + -0.0000074 * T)
+
+	// Sun's mean anomaly (47.4)
+	var M = radian(2.5534 + 29.10535669 * k
+		+ T * T * (-0.0000218 + -0.00000011 * T))
+	// Moon's mean anomaly (47.5)
+	var M1 = radian(201.5643 + 385.81693528 * k
+		+ T * T * (0.0107438 + T * (0.00001239 + -0.000000058 * T)))
+	// Moon's argument of latitude (47.6)
+	var F = radian(160.7108 + 390.67050274 * k
+		+ T * T * (-0.0016341 * T * (-0.00000227 + 0.000000011 * T)))
+	// Moon's longitude of ascending node (47.7)
+	var O = radian(124.7746 - 1.56375580 * k
+		+ T * T * (0.0020691 + 0.00000215 * T))
 
 	// planetary arguments
-	A[0]  = 0; // unused!
-	A[1]  = 299.77 +  0.107408 * k - 0.009173 * T * T;
-	A[2]  = 251.88 +  0.016321 * k;
-	A[3]  = 251.83 + 26.651886 * k;
-	A[4]  = 349.42 + 36.412478 * k;
-	A[5]  =  84.66 + 18.206239 * k;
-	A[6]  = 141.74 + 53.303771 * k;
-	A[7]  = 207.14 +  2.453732 * k;
-	A[8]  = 154.84 +  7.306860 * k;
-	A[9]  =  34.52 + 27.261239 * k;
-	A[10] = 207.19 +  0.121824 * k;
-	A[11] = 291.34 +  1.844379 * k;
-	A[12] = 161.72 + 24.198154 * k;
-	A[13] = 239.56 + 25.513099 * k;
-	A[14] = 331.55 +  3.592518 * k;
-
-	// all of the above crap must be made into radians!!!
-	// except for E...
-
-	M = torad(M);
-	M1 = torad(M1);
-	F = torad(F);
-	O = torad(O);
-
-	// all those planetary arguments, too!
-	for (i = 1; i <= 14; ++i)
-		A[i] = torad(A[i]);
-
-	// ok, we have all the parameters, let's apply them to the JDE.
-	// (remember the JDE?  this is a program about the JDE...)
-
-	switch(phi)
-	{
-		// a special case for each different phase.  NOTE!,
-		// I'm not treating these in a 0123 order!!!  Pay
-		// attention, there, you!
-
-		case 0: // New Moon
-			JDE = JDE
-			    - 0.40720         * Math.sin(M1)
-			    + 0.17241 * E     * Math.sin(M)
-			    + 0.01608         * Math.sin(2.0 * M1)
-			    + 0.01039         * Math.sin(2.0 * F)
-			    + 0.00739 * E     * Math.sin(M1 - M)
-			    - 0.00514 * E     * Math.sin(M1 + M)
-			    + 0.00208 * E * E * Math.sin(2.0 * M)
-			    - 0.00111         * Math.sin(M1 - 2.0 * F)
-			    - 0.00057         * Math.sin(M1 + 2.0 * F)
-			    + 0.00056 * E     * Math.sin(2.0 * M1 + M)
-			    - 0.00042         * Math.sin(3.0 * M1)
-			    + 0.00042 * E     * Math.sin(M + 2.0 * F)
-			    + 0.00038 * E     * Math.sin(M - 2.0 * F)
-			    - 0.00024 * E     * Math.sin(2.0 * M1 - M)
-			    - 0.00017         * Math.sin(O)
-			    - 0.00007         * Math.sin(M1 + 2.0 * M)
-			    + 0.00004         * Math.sin(2.0 * M1 - 2.0 * F)
-			    + 0.00004         * Math.sin(3.0 * M)
-			    + 0.00003         * Math.sin(M1 + M - 2.0 * F)
-			    + 0.00003         * Math.sin(2.0 * M1 + 2.0 * F)
-			    - 0.00003         * Math.sin(M1 + M + 2.0 * F)
-			    + 0.00003         * Math.sin(M1 - M + 2.0 * F)
-			    - 0.00002         * Math.sin(M1 - M - 2.0 * F)
-			    - 0.00002         * Math.sin(3.0 * M1 + M)
-			    + 0.00002         * Math.sin(4.0 * M1);
-			break;
-
-		case 2: // Full Moon
-			JDE = JDE
-			    - 0.40614         * Math.sin(M1)
-			    + 0.17302 * E     * Math.sin(M)
-			    + 0.01614         * Math.sin(2.0 * M1)
-			    + 0.01043         * Math.sin(2.0 * F)
-			    + 0.00734 * E     * Math.sin(M1 - M)
-			    - 0.00515 * E     * Math.sin(M1 + M)
-			    + 0.00209 * E * E * Math.sin(2.0 * M)
-			    - 0.00111         * Math.sin(M1 - 2.0 * F)
-			    - 0.00057         * Math.sin(M1 + 2.0 * F)
-			    + 0.00056 * E     * Math.sin(2.0 * M1 + M)
-			    - 0.00042         * Math.sin(3.0 * M1)
-			    + 0.00042 * E     * Math.sin(M + 2.0 * F)
-			    + 0.00038 * E     * Math.sin(M - 2.0 * F)
-			    - 0.00024 * E     * Math.sin(2.0 * M1 - M)
-			    - 0.00017         * Math.sin(O)
-			    - 0.00007         * Math.sin(M1 + 2.0 * M)
-			    + 0.00004         * Math.sin(2.0 * M1 - 2.0 * F)
-			    + 0.00004         * Math.sin(3.0 * M)
-			    + 0.00003         * Math.sin(M1 + M - 2.0 * F)
-			    + 0.00003         * Math.sin(2.0 * M1 + 2.0 * F)
-			    - 0.00003         * Math.sin(M1 + M + 2.0 * F)
-			    + 0.00003         * Math.sin(M1 - M + 2.0 * F)
-			    - 0.00002         * Math.sin(M1 - M - 2.0 * F)
-			    - 0.00002         * Math.sin(3.0 * M1 + M)
-			    + 0.00002         * Math.sin(4.0 * M1);
-			break;
-
-		case 1: // First Quarter
-		case 3: // Last Quarter
-			JDE = JDE
-			    - 0.62801         * Math.sin(M1)
-			    + 0.17172 * E     * Math.sin(M)
-			    - 0.01183 * E     * Math.sin(M1 + M)
-			    + 0.00862         * Math.sin(2.0 * M1)
-			    + 0.00804         * Math.sin(2.0 * F)
-			    + 0.00454 * E     * Math.sin(M1 - M)
-			    + 0.00204 * E * E * Math.sin(2.0 * M)
-			    - 0.00180         * Math.sin(M1 - 2.0 * F)
-			    - 0.00070         * Math.sin(M1 + 2.0 * F)
-			    - 0.00040         * Math.sin(3.0 * M1)
-			    - 0.00034 * E     * Math.sin(2.0 * M1 - M)
-			    + 0.00032 * E     * Math.sin(M + 2.0 * F)
-			    + 0.00032 * E     * Math.sin(M - 2.0 * F)
-			    - 0.00028 * E * E * Math.sin(M1 + 2.0 * M)
-			    + 0.00027 * E     * Math.sin(2.0 * M1 + M)
-			    - 0.00017         * Math.sin(O)
-			    - 0.00005         * Math.sin(M1 - M - 2.0 * F)
-			    + 0.00004         * Math.sin(2.0 * M1 + 2.0 * F)
-			    - 0.00004         * Math.sin(M1 + M + 2.0 * F)
-			    + 0.00004         * Math.sin(M1 - 2.0 * M)
-			    + 0.00003         * Math.sin(M1 + M - 2.0 * F)
-			    + 0.00003         * Math.sin(3.0 * M)
-			    + 0.00002         * Math.sin(2.0 * M1 - 2.0 * F)
-			    + 0.00002         * Math.sin(M1 - M + 2.0 * F)
-			    - 0.00002         * Math.sin(3.0 * M1 + M);
-
-			W = 0.00306
-			  - 0.00038 * E * Math.cos(M)
-			  + 0.00026 * Math.cos(M1)
-			  - 0.00002 * Math.cos(M1 - M)
-			  + 0.00002 * Math.cos(M1 + M)
-			  + 0.00002 * Math.cos(2.0 * F);
-			if (phi == 3)
-				W = -W;
-			JDE += W;
-			break;
-
-		default: // oops!
-			console.log("The Moon has exploded!");
-			exit(1);
-			break; // unexecuted code
-	}
+	var planetaryArguments =
+		0.000325 * Math.sin(radian(299.77 +  0.107408 * k - 0.009173 * T * T))
+		+ 0.000165 * Math.sin(radian(251.88 +  0.016321 * k))
+		+ 0.000164 * Math.sin(radian(251.83 + 26.651886 * k))
+		+ 0.000126 * Math.sin(radian(349.42 + 36.412478 * k))
+		+ 0.000110 * Math.sin(radian(84.66  + 18.206239 * k))
+		+ 0.000062 * Math.sin(radian(141.74 + 53.303771 * k))
+		+ 0.000060 * Math.sin(radian(207.14 +  2.453732 * k))
+		+ 0.000056 * Math.sin(radian(154.84 +  7.306860 * k))
+		+ 0.000047 * Math.sin(radian(34.52  + 27.261239 * k))
+		+ 0.000042 * Math.sin(radian(207.19 +  0.121824 * k))
+		+ 0.000040 * Math.sin(radian(291.34 +  1.844379 * k))
+		+ 0.000037 * Math.sin(radian(161.72 + 24.198154 * k))
+		+ 0.000035 * Math.sin(radian(239.56 + 25.513099 * k))
+		+ 0.000023 * Math.sin(radian(331.55 +  3.592518 * k))
+
+	// added correction for quarter phases
+	var W
+
+	//group First, Last Quarter
+	var orbitalCorrectionIndex = 2-Math.abs(2-phi)
+
+	var orbitalCorrectionCoeffArray = [
+		// New Moon
+		[+0.17241, +0.00208, +0.00004, -0.40720, +0.00739, -0.00514, +0.00000, -0.00007, -0.00111, -0.00057, +0.01608, +0.01039, -0.00024, +0.00056, -0.00042, -0.00002, +0.00002, +0.00038, +0.00042, -0.00017, +0.00004, +0.00003, -0.00002, +0.00003, +0.00003, -0.00003,],
+		// First Quarter, Last Quarter,
+		[+0.17172, +0.00204, +0.00003, -0.62801, +0.00454, -0.01183, +0.00004, -0.00028* E * E, -0.00180, -0.00070, +0.00862, +0.00804, -0.00034, +0.00027, -0.00040, -0.00002, +0.00000, +0.00032, +0.00032, -0.00017, +0.00002, +0.00004, -0.00005, +0.00002, +0.00003, -0.00004,],
+		// New Moon
+		[+0.17302, +0.00209, +0.00004, -0.40614, +0.00734, -0.00515, +0.00000, -0.00007, -0.00111, -0.00057, +0.01614, +0.01043, -0.00024, +0.00056, -0.00042, -0.00002, +0.00002, +0.00038, +0.00042, -0.00017, +0.00004, +0.00003, -0.00002, +0.00003, +0.00003, -0.00003,]]
+
+	var orbitalCorrectionCoeffs =
+		orbitalCorrectionCoeffArray[orbitalCorrectionIndex]
+
+	var orbitalApproximation =
+		  orbitalCorrectionCoeffs[0] * E     * Math.sin(M)
+		+ orbitalCorrectionCoeffs[1] * E * E * Math.sin(2.0 * M)
+		+ orbitalCorrectionCoeffs[2]         * Math.sin(3.0 * M)
+		+ orbitalCorrectionCoeffs[3]         * Math.sin(M1)
+		+ orbitalCorrectionCoeffs[4] * E     * Math.sin(M1 - M)
+		+ orbitalCorrectionCoeffs[5] * E     * Math.sin(M1 + M)
+		+ orbitalCorrectionCoeffs[6]         * Math.sin(M1 - 2.0 * M)
+		+ orbitalCorrectionCoeffs[7]         * Math.sin(M1 + 2.0 * M)
+		+ orbitalCorrectionCoeffs[8]         * Math.sin(M1 - 2.0 * F)
+		+ orbitalCorrectionCoeffs[9]         * Math.sin(M1 + 2.0 * F)
+		+ orbitalCorrectionCoeffs[10]        * Math.sin(2.0 * M1)
+		+ orbitalCorrectionCoeffs[11]        * Math.sin(2.0 * F)
+		+ orbitalCorrectionCoeffs[12] * E    * Math.sin(2.0 * M1 - M)
+		+ orbitalCorrectionCoeffs[13] * E    * Math.sin(2.0 * M1 + M)
+		+ orbitalCorrectionCoeffs[14]        * Math.sin(3.0 * M1)
+		+ orbitalCorrectionCoeffs[15]        * Math.sin(3.0 * M1 + M)
+		+ orbitalCorrectionCoeffs[16]        * Math.sin(4.0 * M1)
+		+ orbitalCorrectionCoeffs[17] * E    * Math.sin(M - 2.0 * F)
+		+ orbitalCorrectionCoeffs[18] * E    * Math.sin(M + 2.0 * F)
+		+ orbitalCorrectionCoeffs[19]        * Math.sin(O)
+		+ orbitalCorrectionCoeffs[20]        * Math.sin(2.0 * M1 - 2.0 * F)
+		+ orbitalCorrectionCoeffs[21]        * Math.sin(2.0 * M1 + 2.0 * F)
+		+ orbitalCorrectionCoeffs[22]        * Math.sin(M1 - M - 2.0 * F)
+		+ orbitalCorrectionCoeffs[23]        * Math.sin(M1 - M + 2.0 * F)
+		+ orbitalCorrectionCoeffs[24]        * Math.sin(M1 + M - 2.0 * F)
+		+ orbitalCorrectionCoeffs[25]        * Math.sin(M1 + M + 2.0 * F)
+
+
+	// this is the first approximation.  all else is for style points! (47.1)
+	JDE = LUNATION_EPOCH_JD + (LUNATION_CYCLE_DURATION * k)
+	    + T * T * (0.0001337 + T * (-0.000000150 + 0.00000000073 * T))
+
 
-	// now there are some final correction to everything
 	JDE = JDE
-	    + 0.000325 * Math.sin(A[1])
-	    + 0.000165 * Math.sin(A[2])
-	    + 0.000164 * Math.sin(A[3])
-	    + 0.000126 * Math.sin(A[4])
-	    + 0.000110 * Math.sin(A[5])
-	    + 0.000062 * Math.sin(A[6])
-	    + 0.000060 * Math.sin(A[7])
-	    + 0.000056 * Math.sin(A[8])
-	    + 0.000047 * Math.sin(A[9])
-	    + 0.000042 * Math.sin(A[10])
-	    + 0.000040 * Math.sin(A[11])
-	    + 0.000037 * Math.sin(A[12])
-	    + 0.000035 * Math.sin(A[13])
-	    + 0.000023 * Math.sin(A[14]);
-
-	return JDE;
+		+ orbitalApproximation
+		+ planetaryArguments
+
+	// extra correction for quarter phases
+	if (orbitalCorrectionIndex == 1) {
+		W = 0.00306
+		- 0.00038 * E * Math.cos(M)
+		+ 0.00026 * Math.cos(M1)
+		- 0.00002 * Math.cos(M1 - M)
+		+ 0.00002 * Math.cos(M1 + M)
+		+ 0.00002 * Math.cos(2.0 * F)
+		if (phi == 3){
+			W = -W
+		}
+		JDE += W
+	}
+
+	return JDE
 }
 
-//var LUNATION_OFFSET = 953; // original value, I (Glad) don't know why it was chosen as it slows down the startup of the plasmoid
-//var LUNATION_OFFSET = -124; // set lunation start in 2010 (faster startup than with the above)
-var LUNATION_OFFSET = 0; // a reasonable start lunation is calculated in lunacalc.js
 
-function moonphasebylunation(lun, phi)
-{
-	var k = lun - LUNATION_OFFSET + phi / 4.0;
-	return moonphase(k, phi);
-}
+
+
+
+
diff --git a/package/contents/ui/main.qml b/package/contents/ui/main.qml
index 060d744..02cdf19 100644
--- a/package/contents/ui/main.qml
+++ b/package/contents/ui/main.qml
@@ -41,12 +41,9 @@ PlasmoidItem {
     property int preferredWidth
     property int preferredHeight
     property var currentPhase: {
-        terminator:
-        plasmoid.configuration.currentPhase;
-        text:
-        plasmoid.configuration.currentPhaseText;
-        subText:
-        plasmoid.configuration.currentPhaseSubText;
+        terminator: plasmoid.configuration.currentPhase;
+        text: plasmoid.configuration.currentPhaseText;
+        subText: plasmoid.configuration.currentPhaseSubText;
     }
     property bool showBackground: plasmoid.configuration.showBackground
     property bool transparentShadow: plasmoid.configuration.transparentShadow
@@ -74,9 +71,8 @@ PlasmoidItem {
 
         function updateDetails() {
             // set the correct image for the moon
-            currentPhase = LunaCalc.getCurrentPhase(true);
+            currentPhase = LunaCalc.getCurrentPhase();
             plasmoid.configuration.currentPhase = currentPhase.terminator;
-            lunaIcon.phaseNumber = 13; //currentPhase.number;
             lunaIcon.theta = currentPhase.terminator;
             lunaIcon.latitude = latitude;
             main.lunarImage = imageChoices.get(main.lunarIndex).filename;
@@ -115,9 +111,7 @@ PlasmoidItem {
                 anchors.fill: parent
                 onClicked: expanded = !expanded
             }
-
         }
-
     }
 
     fullRepresentation: Item {
@@ -141,7 +135,5 @@ PlasmoidItem {
             dateFormat: dateFormat
             dateFormatString: dateFormatString
         }
-
     }
-
 }
-- 
GitLab