{"id":32151043,"url":"https://github.com/mannylopez/tinymoon","last_synced_at":"2026-02-19T02:02:19.246Z","repository":{"id":236834211,"uuid":"793244377","full_name":"mannylopez/TinyMoon","owner":"mannylopez","description":"A tiny Swift library to calculate the moon phase for any given date, works super fast, and works completely offline.","archived":false,"fork":false,"pushed_at":"2024-09-07T23:54:32.000Z","size":5331,"stargazers_count":120,"open_issues_count":1,"forks_count":6,"subscribers_count":3,"default_branch":"main","last_synced_at":"2026-01-18T20:59:26.982Z","etag":null,"topics":["library","moon","moon-phase","offline","swift","swiftui"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mannylopez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-28T20:14:15.000Z","updated_at":"2025-12-10T13:25:58.000Z","dependencies_parsed_at":"2024-05-30T02:11:06.446Z","dependency_job_id":"c5d351d4-9180-4ef4-a383-3d2e5a9eb822","html_url":"https://github.com/mannylopez/TinyMoon","commit_stats":null,"previous_names":["mannylopez/tinymoon"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/mannylopez/TinyMoon","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mannylopez%2FTinyMoon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mannylopez%2FTinyMoon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mannylopez%2FTinyMoon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mannylopez%2FTinyMoon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mannylopez","download_url":"https://codeload.github.com/mannylopez/TinyMoon/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mannylopez%2FTinyMoon/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29600847,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-19T00:59:38.239Z","status":"online","status_checked_at":"2026-02-19T02:00:07.702Z","response_time":117,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["library","moon","moon-phase","offline","swift","swiftui"],"created_at":"2025-10-21T10:33:26.780Z","updated_at":"2026-02-19T02:02:19.240Z","avatar_url":"https://github.com/mannylopez.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fmannylopez%2FTinyMoon%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/mannylopez/TinyMoon)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fmannylopez%2FTinyMoon%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/mannylopez/TinyMoon)\n[![Swift Package Manager](https://img.shields.io/badge/SPM-compatible-brightgreen.svg)](https://swift.org/package-manager)\n\n![Tiny Moon icon](images/TinyMoonTransparent_256x256.png)\n# Tiny Moon Swift Package\n\nA tiny Swift library to calculate the moon phase for any given date, works super fast, and works completely offline.\n\nCompatible with iOS and MacOS.\n\n## Quick start\n\n```swift\n// Get the moon phase for right now\nlet moon = TinyMoon.calculateMoonPhase()\n```\n\n## Installation\n1. Open your existing Xcode project or create a new one\n2. Open the Swift Packages Manager\n\t- In the project navigator, select your project file to open the project settings.\n\t- Navigate to the the **Package Dependencies** tab\n3. Add the Tiny Moon Package\n\t- Click the **+** button at the bottom of the tab\n\t- In the dialog box that appears, enter the URL for Tiny Moon: `https://github.com/mannylopez/TinyMoon.git`\n4. Specify version rules\n\t- Xcode will prompt you to specify version rules for the package. \"Up to Next Major Version\" ensures compatibility with future updates that don't introduce breaking changes.\n\t- Click **Add Package**\n\n![Xcode package dialog box](images/XcodePackageDialogBox.png)\n\n## Usage\nNow that Tiny Moon is added to your project, import it and simply pass in the the `Date` and `TimeZone` for which you'd like to know the Moon phase for. If no date is passed in, then your system's current `Date` will be used.\n\n*An example app using Tiny Moon*\n\n```swift\nimport SwiftUI\nimport TinyMoon\n\nstruct SimpleMoonView: View {\n\n  private let moon = TinyMoon.calculateMoonPhase()\n\n  var body: some View {\n    VStack(spacing: 16) {\n      Text(moon.date.toString())\n      Text(moon.emoji)\n      Text(moon.name)\n      Text(\"Illumination: \\(moon.illuminatedFraction)\")\n      Text(\"\\(moon.ageOfMoon.days) days, \\(moon.ageOfMoon.hours) hours, \\(moon.ageOfMoon.minutes) minutes\")\n      Text(\"Full Moon in \\(moon.daysTillFullMoon) days\")\n      Text(\"New Moon in \\(moon.daysTillNewMoon) days\")\n    }\n  }\n}\n\n#Preview {\n  SimpleMoonView()\n}\n```\n\n![Simple Moon View](images/SimpleMoon.png)\n\n## API\n\n#### Entry point\nThe main entry point into the library is the [`TinyMoon`](https://github.com/mannylopez/TinyMoon/blob/main/Sources/TinyMoon/TinyMoon.swift) name space.\n\nFrom there, you can access func's `calculateMoonPhase` and `calculateExactMoonPhase`\n\n```swift\npublic enum TinyMoon {\n  public static func calculateMoonPhase(\n    _ date: Date = Date(),\n    timeZone: TimeZone = TimeZone.current)\n    -\u003e Moon\n  {\n    Moon(date: date, timeZone: timeZone)\n  }\n\n  public static func calculateExactMoonPhase(_ date: Date = Date()) -\u003e ExactMoon {\n    ExactMoon(date: date)\n  }\n}\n\n```\n\n#### `Moon` vs `ExactMoon`\n\nThe `Moon` object prioritizes the major phases (new moon, first quarter, full moon, last quarter) if it happens to land within a specific day.\n\nThe `ExactMoon` object always returns the exact values for the specific date and time passed in.\n\nFor example, given that the full moon occurs on `August 19, 2024 at 13:25 UTC` \n\n```swift\nimport Foundation\n\n// The Date we will query for is August 19, 2024 at 02:00 UTC\nlet isoFormatter = ISO8601DateFormatter()\nisoFormatter.timeZone = TimeZone(secondsFromGMT: 0)\nlet date = isoFormatter.date(from: \"2024-08-19T02:00:00Z\")!\n\nlet moon = TinyMoon.calculateMoonPhase(date, timeZone: isoFormatter.timeZone) // If you don't specify a TimeZone, it will default to the system's TimeZone\nprint(moon.name)\t// Full Moon\nprint(moon.emoji)\t// 🌕\n\nlet exactMoon = TinyMoon.calculateExactMoonPhase(date)\nprint(exactMoon.name)\t// Waxing Gibbous\nprint(exactMoon.emoji)\t// 🌔\n```\n\n`ExactMoon` will return `.waxingGibbous` because that is a more accurate representation of the moon phase at `02:00 UTC` time. `Moon` will return `.fullMoon` since a Full Moon happens during that day.\n\n#### Moon properties\n\n| Property | Type | Description |\n| -- | -- | -- |\n| moonPhase | MoonPhase | Enum with all 8 moon phases |\n| name | String | String representation of MoonPhase case |\n| emoji | String | Emoji for moon phase |\n| date | Date | Date passed in for the Moon object |\n| julianDay | Double | Continuous count of day since the beginning of Julian period. Used in astronomical calculations ([wikipedia](https://en.wikipedia.org/wiki/Julian_day)) |\n| daysTillFullMoon | Int | Returns `0` if the current `date` is a full moon |\n| daysTillNewMoon | Int | Returns `0` if the current `date` is a new moon |\n| daysElapsedInCycle | Double | Number of days elapsed into the synodic cycle, represented as a fraction |\n| ageOfMoon | (days: Int, hours: Int, minutes: Int) | Age of the moon in days, minutes, hours |\n| illuminatedFraction | Double | Illuminated portion of the Moon, where 0.0 = new and 1.00 = full |\n| phaseFraction | Double | Phase of the Moon, represented as a fraction. See table below. |\n| distanceFromCenterOfEarth | Double | Distance of moon from the center of the Earth, in kilometers |\n| fullMoonName | String? | Returns the coloquial full moon name |\n\nValues for `phaseFraction` and corresponding emoji\n\n| phaseFraction | Name | Emoji |\n| -- | -- | -- |\n| 0.0 | New Moon | 🌑 |\n|| Waxing Crescent | 🌒 |\n| 0.25 | First Quarter | 🌓 |\n|| Waxing Gibbous | 🌔 |\n| 0.5 | Full Moon | 🌕 |\n|| Waning Gibbous | 🌖 |\n| 0.75 | Last Quarter | 🌗 |\n|| Waning Crescent | 🌘 |\n\n## Demos\nThe following are built with this Tiny Moon Swift Package\n\n#### MacOS\n\nA MacOS app (available in the [App Store](https://apps.apple.com/us/app/tiny-moon/id6502374344)) that displays the current moon phase as an emoji in your toolbar.\n\nSource code: https://github.com/mannylopez/TinyMoonApp\n\n![Toolbar](images/AppScreenshot_1280x800_toolbar.png)\n![Detail view](images/AppScreenshot_1280x800_DarkMode.png)\n\n\n#### iOS\n\nA simple iOS app to showcase how to use Tiny Moon Swift Package\n\nSource code: https://github.com/mannylopez/TinyMoonMobile\n\n![Mobile app](images/MobileApp.png)\n\n## Appreciation\n\nBig thank you to [suncalc](https://github.com/mourner/suncalc), a tiny JavaScript for calculating the moon position and lunar phase for the given time (sun position and sunlight phases as well). It helped me understand the underlying formulas needed for calculating the moon phase.\n\nGreat resources I found via suncalc include, but are not limited to:\n\n- [Astronomy Answers Positions in the Sky](https://aa.quae.nl/en/reken/hemelpositie.html)\n- NASA's [IDL Astronomy User's Library](https://github.com/wlandsman/IDLAstro/blob/master/pro/mphase.pro)\n\nA big big thank you to John Walker who wrote [Moontool for Windows](https://www.fourmilab.ch/moontoolw/) and released the C source code into the public domain. This is where the main formula for calculating the moon phase comes from, and I've found it to be extremely accurate.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmannylopez%2Ftinymoon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmannylopez%2Ftinymoon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmannylopez%2Ftinymoon/lists"}