{"id":20624688,"url":"https://github.com/timac/suncalc","last_synced_at":"2025-04-15T14:59:42.120Z","repository":{"id":163263162,"uuid":"638628409","full_name":"Timac/SunCalc","owner":"Timac","description":"Swift package to calculate the Sun and Moon positions","archived":false,"fork":false,"pushed_at":"2023-05-31T13:46:05.000Z","size":26,"stargazers_count":14,"open_issues_count":1,"forks_count":6,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T14:59:32.668Z","etag":null,"topics":[],"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/Timac.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2023-05-09T18:55:54.000Z","updated_at":"2025-03-27T10:55:47.000Z","dependencies_parsed_at":"2023-07-06T14:16:28.714Z","dependency_job_id":null,"html_url":"https://github.com/Timac/SunCalc","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Timac%2FSunCalc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Timac%2FSunCalc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Timac%2FSunCalc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Timac%2FSunCalc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Timac","download_url":"https://codeload.github.com/Timac/SunCalc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249094940,"owners_count":21211837,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-11-16T13:04:29.223Z","updated_at":"2025-04-15T14:59:42.113Z","avatar_url":"https://github.com/Timac.png","language":"Swift","readme":"# SunCalc\n\nSwift package to calculate the Sun and Moon positions\n\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FTimac%2FSunCalc%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/Timac/SunCalc)\n\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FTimac%2FSunCalc%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/Timac/SunCalc)\n\n# Description\n\nSunCalc is a Swift package to calculate the sun position, sunlight phases (times for sunrise, sunset, dusk, etc.), moon position and lunar phase for the given location and time.\n\nMost calculations are based on the formulas given in the excellent Astronomy Answers articles\nabout [position of the sun](http://aa.quae.nl/en/reken/zonpositie.html)\nand [the planets](http://aa.quae.nl/en/reken/hemelpositie.html).\nYou can read about different twilight phases calculated by SunCalc\nin the [Twilight article on Wikipedia](http://en.wikipedia.org/wiki/Twilight).\n\n\n# Usage\n\n\n```swift\n// get today's sunlight times for London\n\nlet date = Date()\n\nlet sunCalc = SunCalc.getTimes(date: date, latitude: 51.5, longitude: -0.1)\nif let sunrise = sunCalc.sunrise {\n\tdebugPrint(\"sunrise: \\(sunrise.formatted())\")\n}\n\nif let sunset = sunCalc.sunset {\n\tdebugPrint(\"sunset: \\(sunset.formatted())\")\n}\n\nlet sunPos = SunCalc.getSunPosition(timeAndDate: date, latitude: 51.5, longitude: -0.1)\nlet sunriseAzimuth = sunPos.azimuth * 180 / Constants.PI()\ndebugPrint(\"sunriseAzimuth: \\(sunriseAzimuth)\")\n```\n\n# Reference\n\n## Sunlight times\n\n```javascript\nSunCalc.getTimes(/*Date*/ date, /*Number*/ latitude, /*Number*/ longitude, /*Number (default=0)*/ height)\n```\n\nReturns an object with the following properties (each is a `Date` object):\n\n| Property        | Description                                                              |\n| --------------- | ------------------------------------------------------------------------ |\n| `sunrise`       | sunrise (top edge of the sun appears on the horizon)                     |\n| `sunriseEnd`    | sunrise ends (bottom edge of the sun touches the horizon)                |\n| `goldenHourEnd` | morning golden hour (soft light, best time for photography) ends         |\n| `solarNoon`     | solar noon (sun is in the highest position)                              |\n| `goldenHour`    | evening golden hour starts                                               |\n| `sunsetStart`   | sunset starts (bottom edge of the sun touches the horizon)               |\n| `sunset`        | sunset (sun disappears below the horizon, evening civil twilight starts) |\n| `dusk`          | dusk (evening nautical twilight starts)                                  |\n| `nauticalDusk`  | nautical dusk (evening astronomical twilight starts)                     |\n| `night`         | night starts (dark enough for astronomical observations)                 |\n| `nadir`         | nadir (darkest moment of the night, sun is in the lowest position)       |\n| `nightEnd`      | night ends (morning astronomical twilight starts)                        |\n| `nauticalDawn`  | nautical dawn (morning nautical twilight starts)                         |\n| `dawn`          | dawn (morning nautical twilight ends, morning civil twilight starts)     |\n\n```javascript\nSunCalc.addTime(/*Number*/ angleInDegrees, /*String*/ morningName, /*String*/ eveningName)\n```\n\nAdds a custom time when the sun reaches the given angle to results returned by `SunCalc.getTimes`.\n\n`SunCalc.times` property contains all currently defined times.\n\n\n## Sun position\n\n```javascript\nSunCalc.getPosition(/*Date*/ timeAndDate, /*Number*/ latitude, /*Number*/ longitude)\n```\n\nReturns an object with the following properties:\n\n * `altitude`: sun altitude above the horizon in radians,\n e.g. `0` at the horizon and `PI/2` at the zenith (straight over your head)\n * `azimuth`: sun azimuth in radians (direction along the horizon, measured from south to west),\n e.g. `0` is south and `Math.PI * 3/4` is northwest\n\n\n## Moon position\n\n```javascript\nSunCalc.getMoonPosition(/*Date*/ timeAndDate, /*Number*/ latitude, /*Number*/ longitude)\n```\n\nReturns an object with the following properties:\n\n * `altitude`: moon altitude above the horizon in radians\n * `azimuth`: moon azimuth in radians\n * `distance`: distance to moon in kilometers\n * `parallacticAngle`: parallactic angle of the moon in radians\n\n\n## Moon illumination\n\n```javascript\nSunCalc.getMoonIllumination(/*Date*/ timeAndDate)\n```\n\nReturns an object with the following properties:\n\n * `fraction`: illuminated fraction of the moon; varies from `0.0` (new moon) to `1.0` (full moon)\n * `phase`: moon phase; varies from `0.0` to `1.0`, described below\n * `angle`: midpoint angle in radians of the illuminated limb of the moon reckoned eastward from the north point of the disk;\n the moon is waxing if the angle is negative, and waning if positive\n\nMoon phase value should be interpreted like this:\n\n| Phase | Name            |\n| -----:| --------------- |\n| 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\nBy subtracting the `parallacticAngle` from the `angle` one can get the zenith angle of the moons bright limb (anticlockwise).\nThe zenith angle can be used do draw the moon shape from the observers perspective (e.g. moon lying on its back).\n\n## Moon rise and set times\n\n```js\nSunCalc.getMoonTimes(/*Date*/ date, /*Number*/ latitude, /*Number*/ longitude[, inUTC])\n```\n\nReturns an object with the following properties:\n\n * `rise`: moonrise time as `Date`\n * `set`: moonset time as `Date`\n * `alwaysUp`: `true` if the moon never rises/sets and is always _above_ the horizon during the day\n * `alwaysDown`: `true` if the moon is always _below_ the horizon\n\nBy default, it will search for moon rise and set during local user's day (frou 0 to 24 hours).\nIf `inUTC` is set to true, it will instead search the specified date from 0 to 24 UTC hours.\n\n\n# License\n\nThis project is based on the source code [https://github.com/shanus/suncalc-swift](https://github.com/shanus/suncalc-swift) written by Shaun Meredith, which is based on the original Javascript suncalc by Vladimir Agafonkin (\"mourner\") available at [https://github.com/mourner/suncalc](https://github.com/mourner/suncalc)\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimac%2Fsuncalc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimac%2Fsuncalc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimac%2Fsuncalc/lists"}