Skip to content

Sunlitt/MoonKit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MoonKit

moonkit

GitHub GitHub stars GitHub issues Requires Core Location

MoonKit is a Swift package which uses math and trigonometry to compute several information about the Moon.

Usage

MoonKit only needs a location and the relative time zone to compute every Moon information.
Everything is computed locally, no internet connection is needed.

Creating a Moon

// Creating a CLLocation object with the coordinates you are interested in
let naplesLocation: CLLocation = .init(latitude: 40.84014, longitude: 14.25226)

// Timezone for the location of interest. It's highly recommended to initialize it via identifier
let timeZoneNaples: Timezone = .init(identifier: "Europe/Rome") ?? .current

// Creating the Moon instance which will store all the information you need about Moon events and her position
var myMoon: Moon = .init(location: naplesLocation, timeZone: timeZoneNaples)

Retrieve information

// Creating a Date instance
let myDate: Date = Date() // Your current date

// Setting inside myMoon object the date of interest
myMoon.setDate(myDate)

      // All the following informations are related to the given location for the date that has just been set

// Azimuth of the Moon 
myMoon.azimuth  

// Altitude of the Moon
myMoon.altitude

// Moonrise Date
myMoon.moonRise

// Moonset Date
myMoon.moonSet

// Current Moon Phase
myMoon.currentMoonPhase

// Moon Astrological sign
myMoon.moonSign

// To know all the information you can retrieve go to the **Features** section.

Working with Timezones and Dates

To properly show the Moon Date Events use the following DateFormatter.

 //Creting a DateFormatter
 let dateFormatter =  DateFormatter()
 
 //Properly setting his attributes
 dateFormatter.locale    =  .current
 dateFormatter.timeZone  =  timeZoneNaples  // It shall be the same as the one used to initilize myMoon
 dateFormatter.timeStyle = .full
 dateFormatter.dateStyle = .full
  
 //Printing Moon Date Events with the correct Timezone
  
 print("Moonrise: \(dateFormatter.string(from: myMoon.moonRise))")
    

Features

  • Moon Azimuth
  • Moon Altitude
  • MoonRise Time
  • MoonSet Time
  • Moon Percentage
  • Moon Phase
  • Moon Astrological Sign
  • MoonRise Azimuth
  • MoonSet Azimuth
  • Next Full Moon
  • Next New Moon

References

  • Celestial Calculations: A Gentle Introduction to Computational Astronomy: Link.

SunKit ☀️

Take a look to the other Package, this time about the Sun: SunKit.