Please enable JavaScript to view this site.

 

int = MoonPhaseAndTimeOf(nDate,nMoonSourceIndex,bUseEighths)

 

This macro function returns the index and time of the Moon phase that occurs on nDate.

 

➢The result combines the Moon phase index and its time: phase index × 1000000 + time in millionths of a day. A result of 0 means that no phase of the requested type occurs on nDate. Use div 1000000 to extract the phase index and mod 1000000 to extract the time, as shown in the source code example below.

 

The index extracted from the result corresponds to the following table. A complete result of 0 indicates that no event of the requested type occurs on nDate.

 

0

No moon phase of the type specified on nDate.

1

New Moon

2

Waxing Crescent

3

First Quarter

4

Waxing Gibbous

5

Full Moon

6

Waning Gibbous

7

Last quarter

8

Waning Crescent

 

The bUseEighths parameter is used as follows:

 

•If bUseEighths is false, then only the four main phases are considered: New Moon (1), First Quarter (3), Full Moon (5), and Last Quarter (7).

•If bUseEighths is true, the intermediate phases (2, 4, 6, and 8) are also considered. This is an extremely rarely used setting.

 

The indices are not renumbered when bUseEighths is false. A result of 0 means that none of the selected phases occurs on nDate.

 

Extracting Phase and Time

 

To extract the index and time from the result of this function, use the div and mod functions on the returned result, as shown in the code below.

nMoonIndex = 0
nPhaseAndTime = MoonPhaseAndTimeOf(nRunDate,1,false)
// do we have a phase ?
if (nPhaseAndTime > 0)
   nMoonIndex = nPhaseAndTime div 1000000
   nMoonTime = nPhaseAndTime mod 1000000
endif

The macro code below uses HeliacalEventOnDate with MoonPhaseAndTimeOf in a historical Matariki example: it searches for the new Moon following the heliacal rise of the Pleiades star cluster. This example does not calculate the statutory Matariki public holiday dates introduced in New Zealand in 2022 (see Historical Follow-Up below).

For this example, Sun data source 1 and Moon data source 1 must refer to the intended New Zealand location and use consistent local-time settings.

nEventType = 1 // heliacal rise
nAstroBody = 29 // Alcyone, the brightest star in the Pleiades
// look from mid-May to the end of June
nHeliacalDate = 0
for nRunDate = EncodeDate(nYear,5,15) to EncodeDate(nYear,6,30)
   nHeliacalTime = HeliacalEventOnDate(nRunDate,1,nAstroBody,nEventType)
   if nHeliacalTime >= 0
      nHeliacalDate = nRunDate
      break // found it
   endif
endfor
Assert(nHeliacalDate > 0, 'heliacal event not found', true)
// now look for the new Moon that follows
nMatarikiDate = 0
for nRunDate = nHeliacalDate to nHeliacalDate + 35
   nNewMoonTime = MoonPhaseAndTimeOf(nRunDate,1,false)
   // do we have a phase and if so a new Moon ?
   if (nNewMoonTime > 0) and (nNewMoonTime div 1000000 == 1)
      // if the new Moon is on the exact date of the heliacal rise
      // make sure that the time of the new Moon is after it
      if nRunDate == nHeliacalDate
         // New Moon must be after heliacal rise
         if (nNewMoonTime mod 1000000) > nHeliacalTime
            nMatarikiDate = nRunDate
            break // found it
         else
            // too early keep looking for the next new Moon
         endif
      else
         nMatarikiDate = nRunDate
         break // found it
      endif
   endif
endfor
Assert(nMatarikiDate > 0, 'Matariki not found', true)
// at the end
sResult = 'Maori New Year on ' + FormatDate('Dddd, Mmmmm d, yyyy', nMatarikiDate)

Historical Follow-Up

 

The above code is based on the way Matariki was calculated up to, and including, 2021. But, when Matariki was added as an official non-working public holiday in New Zealand, beginning in 2022, a Matariki Advisory Group was created, comprising experts in Mātauranga Māori (Māori knowledge), tasked with the determination of the dates of the Matariki public holiday for the period 2022–2052. The result was a list of hard-coded dates for the occurrence of Matariki in the period 2022–2052.

 

See also: MoonPhaseName and MoonPhaseSymbol.

 


Topic 177660, last updated on 14-Oct-2026