I have a site with a lot of these stand alone "snippets" so that you don't have to include/port an entire astronomy library just to get the Sun rise/set times, etc. https://www.celestialprogramming.com/ Most of them are written in JavaScript only, but specifically written to be easy to port to other languages.
Show HN: Tiny Moon – Swift library to calculate the moon phase
11–20 of 41 posts
Re: Show HN: Tiny Moon – Swift library to calculate the moon phase
#12Here's a tiny calculator for moon phase that I kludged up ca. 2018 but (at least as of this month) is still tracking the full moon (which makes sense given that the algo came out of a dead tree source from over half a century ago?): _=min lphase = lambda y,m,d: _( lkp(ph,p) for lkp in [lambda t,x: _(v for (kl,v),(kh,w) in zip(t,t[1:]) if kl
Re: Show HN: Tiny Moon – Swift library to calculate the moon phase
#13Re: Show HN: Tiny Moon – Swift library to calculate the moon phase
#14Here's a tiny calculator for moon phase that I kludged up ca. 2018 but (at least as of this month) is still tracking the full moon (which makes sense given that the algo came out of a dead tree source from over half a century ago?): _=min lphase = lambda y,m,d: _( lkp(ph,p) for lkp in [lambda t,x: _(v for (kl,v),(kh,w) in zip(t,t[1:]) if kl
So this is just saying that the phase of the moon is the day mod 29.53, starting from a new moon on 2000-01-06. That's about a minute off the actual mean length of a lunation - I guess the error from that approximation is less than the approximation in your "varies significantly"? (For what it's worth - 29.53 * 300 = 8859 exactly, and 2000-01-06 + 8859 days = 2024-04-08, and I am quite sure there was a new moon on th…
[If that constant is only a minute off, it ought to be good for a few centuries more, and I'm not planning on being around longer than decades, so probably good enough for my purposes.]
Re: Show HN: Tiny Moon – Swift library to calculate the moon phase
#15Nice work. Just FYI for anybody else - it adds an icon to status bar (if that's what it's called? - top right icons). I thought it was going to open an app window and didn't notice the icon, so thought it wasn't working. (In hindsight, it's clear from screenshots in app store).
I think it's called the menu bar, and apps that don't open windows (with an icon in the menu bar) are known as "menu bar apps". Until recently, these were a PITA to implement with Apple's SDK. Thankfully they provided API support sometime I think starting with macOS 13... before that it was pretty kludgy.
Re: Show HN: Tiny Moon – Swift library to calculate the moon phase
#16Is there a plan to add this for linux / windows? Either way, super cool project
=LET(phase,MOD(ROUND(MOD(NOW(),29.5275)/3.691,0)-2,8)+1,UNICHAR(127760+phase)))
Re: Show HN: Tiny Moon – Swift library to calculate the moon phase
#17Earlier quoted context omitted.
So this is just saying that the phase of the moon is the day mod 29.53, starting from a new moon on 2000-01-06. That's about a minute off the actual mean length of a lunation - I guess the error from that approximation is less than the approximation in your "varies significantly"? (For what it's worth - 29.53 * 300 = 8859 exactly, and 2000-01-06 + 8859 days = 2024-04-08, and I am quite sure there was a new moon on th…
Yes. (any cultures that have a purely lunar calendar could do away with all the date fiddling? but then again, I guess they'd just know when the next full moon would be...) [If that constant is only a minute off, it ought to be good for a few centuries more, and I'm not planning on being around longer than decades, so probably good enough for my purposes.]
Honestly, I recommend people use the most accurate algorithm they practically can, even if it's overkill for the given application. This just avoids user confusion when different apps give different answers, even if it's not significant.
E.g., I have ported VSOP87 which gives the position of the moon and planets to sub-arcsecond accuracy to a couple of dozen languages. They are much, much longer than the "snippets", but are not impractical, and users won't notice much difference in application size or computation time. https://github.com/gmiller123456/vsop87-multilang
Re: Show HN: Tiny Moon – Swift library to calculate the moon phase
#18Re: Show HN: Tiny Moon – Swift library to calculate the moon phase
#19Side note, if you use Emacs you can get the phases of the Moon by pressing “M” in either calendar or Org Agenda.
Thursday, June 6, 2024: New Moon 8:40am (EDT)
Friday, June 14, 2024: First Quarter Moon 1:20am (EDT)
.. I removed a few lines ...
Monday, August 19, 2024: Full Moon 2:24pm (EDT)
Monday, August 26, 2024: Last Quarter Moon 5:34am (EDT
Also, M-x sunrise-sunset computes sunrise and sunset after you give it lat/long.Re: Show HN: Tiny Moon – Swift library to calculate the moon phase
#20I don't really have use for this, but I must compliment the author on a job well-done. The code is well-structured, well-documented, well-tested, and well-designed.
Doing so also allowed me to completely remove and replace my first attempt at implementing the moon phase algorithm when it turned out to be not-accurate enough (the values were off by about 4 hours).