Welcome to the Cumulus Support forum.

Latest Cumulus MX V4 release 4.4.2 (build 4085) - 12 March 2025

Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024

Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)

Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki

If you are posting a new Topic about an error or if you need help PLEASE read this first viewtopic.php?p=164080#p164080

Moon Phase Date webtags

Please DO NOT use this to publish your entire wish. This Forum is for specific suggestions to enhance the usability of Cumulus MX for all users, NOT your personal requirements. Please check this forum and the rejected forum to make sure you are NOT posting a DUPLICATE suggestion. It will be heavily monitored by Admin and Mark Crossley to determine the feasibility and the difficulty of the suggestion. Those Topics that are deemed inadmissible will moved to the rejected Forum. The remaining Topics will be the Accepted list of future developments, and when our voluntary development group adds it to a build, the build number will be added to the Topic title.
WERPNST8
Posts: 10
Joined: Sat 10 Aug 2024 12:37 pm
Weather Station: Davis Vantage Pro2 Wireless
Operating System: Windows 11

Moon Phase Date webtags

Post by WERPNST8 »

Would it be possible to create webtags for the date of each moon phase? I have been changing the moon phase dates on my website manually each month for years.
User avatar
De Hout
Posts: 92
Joined: Thu 09 Oct 2014 5:40 pm
Weather Station: Davis Vantage Pro2+ FARS
Operating System: Windows 11 | CU v1.9.4 (10992)
Location: Alkmaar, The Netherlands
Contact:

Re: Moon Phase Date webtags

Post by De Hout »

I don’t know if it is possible for Mark to program that feature, so let’s wait for his answer.

But if it can’t be done, and your web server has PHP enabled, I can create a PHP code for you that calculates the dates for the next 4 moon phases. This code can be implemented on your website. (You’ve given me an excellent idea for my own website, so I’m going to implement it right away. :D )

Can you post your website URL, so I can already check what the output of your edited moon phases looks like?
Derk

Image
User avatar
Dador
Posts: 352
Joined: Thu 24 Nov 2011 2:22 pm
Weather Station: Davis VP2 Plus & Ecowitt
Operating System: Windows 10
Location: Rybnik, Poland
Contact:

Re: Moon Phase Date webtags

Post by Dador »

There is already a <#moonphase> webtag that displays the phases of the moon.
Unless you have something else in mind.
User avatar
De Hout
Posts: 92
Joined: Thu 09 Oct 2014 5:40 pm
Weather Station: Davis Vantage Pro2+ FARS
Operating System: Windows 11 | CU v1.9.4 (10992)
Location: Alkmaar, The Netherlands
Contact:

Re: Moon Phase Date webtags

Post by De Hout »

Dador wrote: Sat 17 Aug 2024 5:57 pm There is already a <#moonphase> webtag that displays the phases of the moon.
Unless you have something else in mind.
True for the actual phase. But I assume (I might be wrong) he's asking for the dates of the 4 next moonphases (new moon, first quarter, full moon, last quarter).
Derk

Image
WERPNST8
Posts: 10
Joined: Sat 10 Aug 2024 12:37 pm
Weather Station: Davis Vantage Pro2 Wireless
Operating System: Windows 11

Re: Moon Phase Date webtags

Post by WERPNST8 »

I would use the .php script if you develop it. That would be great. Here is the link to my astronomy page of the site.
https://www.nittanylaneweather.info/wx7.html
WERPNST8
Posts: 10
Joined: Sat 10 Aug 2024 12:37 pm
Weather Station: Davis Vantage Pro2 Wireless
Operating System: Windows 11

Re: Moon Phase Date webtags

Post by WERPNST8 »

Dador wrote: Sat 17 Aug 2024 5:57 pm There is already a <#moonphase> webtag that displays the phases of the moon.
Unless you have something else in mind.
I am looking for the date for each of the next 4 phases, not just the phase.
griffo42
Posts: 247
Joined: Thu 10 Dec 2015 6:41 am
Weather Station: Davis Vantage Pro2
Operating System: Win 11 Home
Location: Brisbane, Queensland, Australia
Contact:

Re: Moon Phase Date webtags

Post by griffo42 »

This has already been programmed by Ken True and shown on his website Saratoga-weather.org/almanac/sun/moon/sky/almanac and is part of his templates which are available for download from there.
Keith
Davis Vantage Pro2 Model #6152AU - CumulusMX - Win11 - Saratoga/CUMX Default Scripts
https://www.kstwx.net/index.php
https://www.kstwx.net/cumx/index.html
Image
Weerhaas
Posts: 25
Joined: Mon 31 Aug 2015 6:31 am
Weather Station: Vantage Pro 2 Plus
Operating System: Windows Pro 10 64b
Location: Zaandam, Nederland
Contact:

Re: Moon Phase Date webtags

Post by Weerhaas »

Weerhaas
Posts: 25
Joined: Mon 31 Aug 2015 6:31 am
Weather Station: Vantage Pro 2 Plus
Operating System: Windows Pro 10 64b
Location: Zaandam, Nederland
Contact:

Re: Moon Phase Date webtags

Post by Weerhaas »

<?php
// UTC date and time
date_default_timezone_set('UTC');

$numberYear = date("Y")-2023;
$numberMonth = date("n");

// The average duration in days of a lunar cycle
$lunardays = 29.53058770576;
// Seconds in lunar cycle
$lunarsecs = $lunardays * (24 * 60 *60);

// Last quarter 4 Jan 2024 03:30
$lastQuarter2024 = strtotime("2024-01-04 03:30");
$lQ = ($lastQuarter2024) + ($numberYear*$numberMonth*$lunarsecs);
$dateLastQuarter2024 = date('d-m-Y', $lQ);
echo "Last quarter : ".$dateLastQuarter2024;echo "<br>";

// New moon 11 Jan 2024 11:57
$newMoon2024 = strtotime("2024-01-11 11:57");
$nM = ($newMoon2024) + ($numberYear*$numberMonth*$lunarsecs);
$dateNewMoon = date('d-m-Y', $nM);
echo "New moon : ".$dateNewMoon;echo "<br>";

// First quarter 18 Jan 2024 03:52
$firstQuarter2024 = strtotime("2024-01-18 03:52");
$fQ = ($firstQuarter2024) + ($numberYear*$numberMonth*$lunarsecs);
$dateFirstQuarter = date('d-m-Y', $fQ);
echo "First quarter : ".$dateFirstQuarter;echo "<br>";

// Full moon 25 Jan 2024 17:54
$fullMoon2024 = strtotime("2024-01-25 17:54");
$fM = ($fullMoon2024) + ($numberYear*$numberMonth*$lunarsecs);
$dateFullMoon = date('d-m-Y', $fM);
echo "Full moon : ".$dateFullMoon;echo "<br>";
?>
AndyKF650
Posts: 818
Joined: Thu 20 Aug 2020 8:35 am
Weather Station: Davis VP2 Plus
Operating System: RPiv5B 64bit Linux 12 Bookworm
Location: Jersey Channel Islands
Contact:

Re: Moon Phase Date webtags

Post by AndyKF650 »

Hi there

Thanks for the inspiration and code for the moon phase calculators. I have combined the two pieces of code and added them to my website. A real thought provoker to get me thinking in .php code again.

Code: Select all

// Moon phase calculator 18 August 2024

<?php
// UTC date and time
date_default_timezone_set('Europe/Jersey');

$numberYear = date("Y")-2023;
$numberMonth = date("n");

// The average duration in days of a lunar cycle
$lunardays = 29.53058770576;
// Seconds in lunar cycle
$lunarsecs = $lunardays * (24 * 60 *60);
echo "<h2>Current Moon Phases</h2>"; echo "<br>";

// Last quarter 4 Jan 2024 03:30
$lastQuarter2024 = strtotime("2024-01-04 03:30");
$lQ = ($lastQuarter2024) + ($numberYear*$numberMonth*$lunarsecs);
$dateLastQuarter2024 = date('d-m-Y', $lQ);
echo "<p> Last quarter : $dateLastQuarter2024</p>";echo "<br>";

// New moon 11 Jan 2024 11:57
$newMoon2024 = strtotime("2024-01-11 11:57");
$nM = ($newMoon2024) + ($numberYear*$numberMonth*$lunarsecs);
$dateNewMoon = date('d-m-Y', $nM);
echo "<p>New moon : $dateNewMoon </p>";echo "<br>";

// First quarter 18 Jan 2024 03:52
$firstQuarter2024 = strtotime("2024-01-18 03:52");
$fQ = ($firstQuarter2024) + ($numberYear*$numberMonth*$lunarsecs);
$dateFirstQuarter = date('d-m-Y', $fQ);
echo "<p>First quarter : $dateFirstQuarter </p>";echo "<br>";

// Full moon 25 Jan 2024 17:54
$fullMoon2024 = strtotime("2024-01-25 17:54");
$fM = ($fullMoon2024) + ($numberYear*$numberMonth*$lunarsecs);
$dateFullMoon = date('d-m-Y', $fM);
echo "<p>Full moon : $dateFullMoon</p>";echo "<br>";
?>

<?php
    /* 
    Moon Phaser Demo
    By: Minkukel
    Date: 18-04-2020
    */

// Use current UTC date and time for this demo
date_default_timezone_set('Europe/Jersey');
$thedate = date('Y-m-d H:i:s');
$unixdate = strtotime($thedate);

// The duration in days of a lunar cycle
$lunardays = 29.53058770576;
// Seconds in lunar cycle
$lunarsecs = $lunardays * (24 * 60 *60);
// Date time of first new moon in year 2000
$new2000 = strtotime("2000-01-06 18:14");

// Calculate seconds between date and new moon 2000
$totalsecs = $unixdate - $new2000;

// Calculate modulus to drop completed cycles
// Note: for real numbers use fmod() instead of % operator
$currentsecs = fmod($totalsecs, $lunarsecs);

// If negative number (date before new moon 2000) add $lunarsecs
if ( $currentsecs < 0 ) {
    $currentsecs += $lunarsecs;
}

// Calculate the fraction of the moon cycle
$currentfrac = $currentsecs / $lunarsecs;

// Calculate days in current cycle (moon age)
$currentdays = $currentfrac * $lunardays;

// Array with start and end of each phase
// In this array 'new', 'first quarter', 'full' and
// 'last quarter' each get a duration of 2 days.
$phases = array
    (
    array("new", 0, 1),
    array("waxing crescent", 1, 6.38264692644),
    array("first quarter", 6.38264692644, 8.38264692644),
    array("waxing gibbous", 8.38264692644, 13.76529385288),
    array("full", 13.76529385288, 15.76529385288),
    array("waning gibbous", 15.76529385288, 21.14794077932),
    array("last quarter", 21.14794077932, 23.14794077932),
    array("waning crescent", 23.14794077932, 28.53058770576),
    array("new", 28.53058770576, 29.53058770576),
    );

// Find current phase in the array
for ( $i=0; $i<9; $i++ ){
    if ( ($currentdays >= $phases[$i][1]) && ($currentdays <= $phases[$i][2]) ) {
        $thephase = $phases[$i][0];
        break;
    }
}

// Spit it out
echo "<h2>Moon Phase Calculator</h2>";
echo "<p>Date and time: ".date("l, j F Y H:i:s", $unixdate)." In Gorey Jersey</p>";

echo "<h2>Constants used</h2>";
echo "<p>Duration of Lunar Cycle is: $lunardays days</p>";
//echo "<p>Date time of first new moon in 2000 is: 2000-01-06 18:14 UTC</p>";

echo "<h2>Calculated moon phase</h2>";
echo "<p>Percentage of lunation: ".round((100*$currentfrac),2)."%</p>";
echo "<p>The moon age is: ".round($currentdays,2)." days</p>";
echo "<p>The moon phase is: $thephase</p>";

?>

Mapantz
Posts: 1992
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 11 x64
Location: Dorset - UK
Contact:

Re: Moon Phase Date webtags

Post by Mapantz »

I thought I'd put that script in a file to see what the output was like.

Moon age is wrong
The illumination percentage is completely wrong
First and last quarter dates are wrong

It says it is a full moon, but technically its waxing gibbous
Image
AndyKF650
Posts: 818
Joined: Thu 20 Aug 2020 8:35 am
Weather Station: Davis VP2 Plus
Operating System: RPiv5B 64bit Linux 12 Bookworm
Location: Jersey Channel Islands
Contact:

Re: Moon Phase Date webtags

Post by AndyKF650 »

Hi there

I would suggest that you look up the word lunation, which is the period between successive new moons and has nothing to do with illumination levels.

Going back to the original script the author said that there was a 2 day variance for the actual description of the moon quarters. Today my site shows that the moon is full since it is 14.23 days out of a lunar cycle of 29.531 days between new moons.
Mapantz
Posts: 1992
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 11 x64
Location: Dorset - UK
Contact:

Re: Moon Phase Date webtags

Post by Mapantz »

AndyKF650 wrote: Mon 19 Aug 2024 7:08 am Hi there

I would suggest that you look up the word lunation, which is the period between successive new moons and has nothing to do with illumination levels.
Ah OK.

But why is it expressed as a percentage?

Re 2 day variance for the quarters; that's pointless then. It's either right or wrong.

There's no point in showing wrong phase dates.
Image
Mapantz
Posts: 1992
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 11 x64
Location: Dorset - UK
Contact:

Re: Moon Phase Date webtags

Post by Mapantz »

I did some searching and I found a PHP script called Solaris: https://github.com/BitAndBlack/php-moon-phase

It seems to provide accurate dates for the phases for me, compared to those above.

You can call the dates for the current lunar cycle or the next lunar cycle.

I added the 4 phase dates to my site, but I made a little extra PHP stuff so that it checks the date of each phase against the current date.
If any of the current 4 phase dates have passed, it'll show the phase date of the next lunar cycle.
Image
User avatar
mcrossley
Posts: 14382
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Moon Phase Date webtags

Post by mcrossley »

Any calculation that uses the mean lunation period to calculate the lunation age from some full moon date/time in the past is going to give a value +/- 2 days or so. The lunation period varies with each cycle though the long-term mean is stable.

To determine the "age" in days of the current cycle MX uses a precalculated list of new moon dates (it is expensive in compute terms to calculate the new moon date accurately every time the web tag is called - it is an iterative process to narrow down on the required phase angle). To get the age, MX simply interpolates between the last and the next new moons. This is accurate to less than hour- enough for our purposes.

The phase angle is determined using astronomical calculations laid down by Jean Meeus which I have used before in other programs, they are accurate to about one minute. The moon descriptive phase (full, new etc) and percentage illumination are determined from the phase angle.

I'm unlikely to add the dates for next phases to MX, there are plenty of libraries out there in every language that already do this.
Post Reply