kip
ex_cldr Core Team
Please say hi to a new lib, Astro that aims to deliver easy-to-consume astronomy calculations of practical use. For now it only calculates sunrise and sunset. In testing its precision is within 1 minute of the results returns from DateAndTime.com.
It makes use of tz_world to dereference geo coordinates to a timezone and tzdata for time zone conversions.
This lib started our as a requirement to support certain solar, lunar and lunisolar calendars but it has wider applicability.
Examples
# Sunrise in Sydney on December 4th
iex> Astro.sunrise({151.20666584, -33.8559799094}, ~D[2019-12-04])
{:ok, #DateTime<2019-12-04 05:37:00.000000+11:00 AEDT Australia/Sydney>}
# Sunset in Sydney on December 4th
iex> Astro.sunset({151.20666584, -33.8559799094}, ~D[2019-12-04])
{:ok, #DateTime<2019-12-04 19:53:00.000000+11:00 AEDT Australia/Sydney>}
# Sunset in the town of Alert in Nunavut, Canada
# ...doesn't exist since there is no sunset in summer
iex> Astro.sunset({-62.3481, 82.5018}, ~D[2019-07-01])
{:error, :no_time}
# ...or sunrise in winter
iex> Astro.sunrise({-62.3481, 82.5018}, ~D[2019-12-04])
{:error, :no_time}
Next steps (as of 0.5.0)
- Sunrise
- Sunset
- Solstice
- Equinox
- Moon phase
- Moon rise
- Moon set
Trending in Announcing
WebAuthnLiveComponent WebAuthnComponents
See this post about renaming the package.
Passwordless authentication for Phoenix LiveView app...
New
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
I released Doggo, a collection of unstyled Phoenix components.
https://github.com/woylie/doggo
Features
Unstyled Phoenix components....
New
Hi everyone,
I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
I’ll shortly be launching Text, a nascent text analysis library.
Current functionality
In this early version (not ready for prime time) ...
New
Following on from my CLDR lbraries I started work on Unicode transforms. But like everything related to CLDR there is a lot of yak-shavin...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with.
But I don’t use it anymore.
Serverless was the promis...
New
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
kip
New version 0.2.0 is now out:
Enhancements
Add
Astro.equinox/2andAstro.solstice/2to calculate solstices and equinoxes for a year. From these can be derived the seasons.Add
Astro.Time.datetime_from_julian_days/1Add
Astro.Time.utc_datetime_from_terrestrial_datetime/1Now on to lunar calculations (phase, moonrise, moonset)… And to implement the Persian calendar (which is a Solar based calendar).
kip
New version 0.3.0 is now out:
Change in behaviour
Enhancements
Add
Astro.solar_noon/2to return the true solar noon for a location and dateAdd
Astro.hours_of_daylight/2to return hours, minutes and seconds as aTime.t()representing the number of daylight hours for a give location and dateAdd
Astro.sun_apparent_longitude/1to return the apparent solar longitude on a given date. The result, a number of degrees between 0 and 360, can be used to determine the seasons.This completes the work required to support the Persian calendar which will be landing on hex.pm in the next couple of days.
kip
Astro version 0.5.0 is now out. The release adds functions that calculate the phase of the moon which, apart from anything else, is needed to calculate the Chinese calendar. Please note that Elixir 1.11 or later is required.
Bug Fixes
Updates documentation to be clear about installation and setup requirements for
tz_worldFixes test data for São Paulo now that it no longer uses DST
Ensure
:astrois started in test modeEnhancements
This primary focus of this release is to add lunar calculations for moon phase.
Adds
Astro.date_time_new_moon_before/1Adds
Astro.date_time_new_moon_at_or_after/1Adds
Astro.lunar_phase_at/1Adds
Astro.date_time_lunar_phase_at_or_before/2Adds
Astro.date_time_lunar_phase_at_or_after/2kip
Astro version 0.6.0 is now out. This version avoids requiring some dependencies which makes the footprint smaller and compilation much faster. I have been using it to support the upcoming Chinese calendar with all tests passing so I consider the basic solar and lunar algorithms to be in solid shape.
Please note that Elixir 1.11 or later is required.
Roadmap
Roadmap to version 1.0 is to add
Astro.moonrise/2andAstro.moonset/2.Additional development proposals or suggestions are very welcome.
Bug Fixes
Fix
Astro.Math.atan_r/2Fix
Astro.Earth.ephemeris/1Breaking changes
Astro.Time.date_time_{from, to}_iso_days/1toAstro.Time.date_time_{from, to}_moment/1Enhancements
Remove dependency on
ex_cldr_calendarandjasonAdd
Astro.sun_position_at/1which is a public API for returning the right ascension, declination and radius (distance to the sun) at a given date/time.Add
Astro.moon_position_at/1which is a public API for returning the right ascension, declination and radius (distance to the moon) at a given date/time.Add
Astro.illuminated_fraction_of_moon_at/1to return the fraction of the moon that is lit at a given date/time.kip
A small update resulting in Astro version 0.9.0 that adds
Astro.lunar_phase_emoji/1to return the phase of the moon as an emoji. For example:kip
@habeebkhan, happy to help if I can but I’m not sure what you’re asking? Can you describe your use case for me?
stevensonmt
Man, there are so many cool things built with Elixir.
kip
I’ve released Astro 1.0 almost exactly a year after the last published version. This indicates API stability for existing functions (stable in most cases for at least 3 years). There is only one new function in this release:
Enhancements
Release 1.0. This library was started four years ago and the public API has been stable for at least three of those years.
Adds
Astro.sun_azimuth_altitude/2. Thanks to @kimlai for the suggestion. Closes #3.mayel
Nice lib!
Is it possible to use it with tz instead of
tzdata?Edit: never mind, I should have checked the docs
Astro — Astro v1.0.0
kip
I’ve published Astro version 1.0.2. The primary fix is to calculate astronomical, nautical and civil sunrise/sunset correctly. The changelog entry is:
Bug Fixes
Elixir 1.17 support
Astro compiles and runs without warnings on Elixir 1.17.
The difference between dawn and sunrise
There are four main daily milestones in the progress from darkness to light each day.
Astronomical twilight is calculated when the geometric centre of the sun is 18 degrees below the horizon. This is the solar elevation where stars start to disappear agains the sky’s background. Therefore typically the time at which optical observation will stop.
Nautical twilight is calculated when the geometric centre of the sun is 12 degrees below the horizon. This is the time at which the horizon can be observed by eye although it is not generally considered light enough for outdoor activity. The important of seeing the horizon is understandable for mariners.
Civil twilight is what is generally considered to be dawn and is calculated when the geometric centre of the sun is 6 degrees below the horizon. This is the point at which outdoor activity is possible due to light from the sun below the horizon refracting in the atmosphere.
Sunrise is calculated when the upper edge of the sun breaks the horizon, adapted to account for refraction of the suns rays.
Each of these - and indeed any arbitrary solar elevation - can be calculated in Astro by:
Example