How does the Sky in Google Earth Pro work?
Stellarium is an open-source software that has similar features. The code is available on github, and the developer's documentation is here.

Some information about Stellarium scripting can be found in Stellarium simulation and “Real time” Stellarium Scripting?