Swiftpack.co - Sunlitt/MoonKit as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Sunlitt.
Sunlitt/MoonKit 2.1.1
MoonKit is a Swift library which uses math and trigonometry to compute several information about the Moon.
⭐️ 55
🕓 1 year ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/Sunlitt/MoonKit.git", from: "2.1.1")

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.

GitHub

link
Stars: 55
Last commit: 14 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Related Packages

Release Notes

MoonKit 2.1.1
1 year ago

bug fix of 'The package does not work well with daylight saving time'

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics