Skip to content

BenMakesGames/MoonMath

Repository files navigation

What Is It?

BenMakesGames.MoonMath is a small library that adds extensions to DateTime and DateTimeOffset to calculate the phase of the Moon.

Buy Me a Coffee at ko-fi.com

How to Use

Install

dotnet add package BenMakesGames.MoonMath 

Add using

using BenMakesGames.MoonMath;

Reference

double DateTimeOffset.GetMoonAge()

Computes The Moon's "age" - the number of Earth days since the last new moon. Ranges from 0 to ~29.53.

Example Use

var now = DateTimeOffset.Now;

Console.WriteLine($"It has been {now.GetMoonAge()} days since the last new moon.");

MoonPhase DateTimeOffset.GetMoonPhase()

Returns a MoonPhase indicating the current phase of the Moon. MoonPhase has the following values:

  • NewMoon
  • WaxingCrescent
  • FirstQuarter
  • WaxingGibbous
  • FullMoon
  • WaningGibbous
  • ThirdQuarter
  • WaningCrescent

Example Use

var now = DateTimeOffset.Now;

var moonPhase = now.GetMoonPhase();

double DateTime.GetMoonAge()

Same as DateTimeOffset.GetMoonAge, but for DateTimes.

MoonPhase DateTime.GetMoonPhase()

Same as DateTimeOffset.GetMoonPhase, but for DateTimes.

string MoonPhase.ToEmoji()

Returns the emoji for the given MoonPhase:

  • 🌑 NewMoon
  • 🌒 WaxingCrescent
  • 🌓 FirstQuarter
  • 🌔 WaxingGibbous
  • 🌕 FullMoon
  • 🌖 WaningGibbous
  • 🌗 ThirdQuarter
  • 🌘 WaningCrescent

Example use:

var now = DateTimeOffset.Now;

Console.WriteLine(now.GetMoonPhase().ToEmoji());

About

Extension methods for DateTimeOffset and DateTime to compute the moon's "age" and phase.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages