Automatically switch themes based on sun altitude

For the longest time I have sworn by dark theme, but every once in a while I found myself struggling to see things during the day with sun shining. I tried dealing with this by increasing my monitor brightness, but it can only do so much. Switching to a light theme instantly solved any legibility issues. Then some time later I thought, why not automate this (and solve the light/dark theme issue once and for all)? So thats what I did.

I initially thought about using some sort of free API to get whether sun has set, but that would have likely required API keys, making API requests every few minutes from the editor and also wouldn’t work offline. While looking for said API I found that science is really cool and it is possible to pretty accurately approximate sun position with math. Since then I have been using this and still smile from time to time when the theme automatically switches.