js-temporal / proposal-temporal-v2

Future additions to Temporal
MIT License
24 stars 1 forks source link

Support for Lunar Calendars Starting New Days at Sunset Instead of Midnight #30

Open khawarizmus opened 11 months ago

khawarizmus commented 11 months ago

Lunar Calendars, like the Islamic calendar, begin their new days at sunset rather than midnight. To fully support these calendars, Temporal needs to implement astronomical calculations to determine sunset times, which can vary by location.

Additionally, Temporal should expose astronomical calculation functions and variables, such as sunsetTime and sunriseTime, or any other relevant APIs.

This feature was previously discussed in Temporal V1 and was suggested for inclusion in V2.

Advantages:

Supporting this behaviour in lunar calendars would give more accurate results and help in implementing accurate applications such as calendar applications or in the case of Islamic calendars having some astronomical calculations exposed by Temporal can also help in calculating Muslim Prayer times.

Concerns:

The concerns that i can foresee are:

Prior art:

I am not aware of any standard library implementing this behaviour however, here are some libraries that implement astronomical calculations for sunset and sunrise.

Constraints / corner cases:

MohsenAlyafei commented 11 months ago

Correct sunset calculations must include location's elevation (i.e. altitude or height above sea level). This should not be difficult but add to the underlying code.

But will that impact the date calculations and the current algorithms used to calculate and derive the hijri dates in the various islamic calendars?

khawarizmus commented 11 months ago

@MohsenAlyafei I am assuming that if we include altitude then we would need to rely on some offline, standardised, up to date altitude data.

And i was wondering if using elevation data like Aster Global Digital Elevation Model from AppEEARS can do the trick.

This dataset offers an elevation precision of 30m which should be more then accurate for the purpose of calculating sunrise/sunset

MohsenAlyafei commented 11 months ago

Yes this may work assuming always that a location given by lat/long coordinates has only one elevation.

Well this is not always the case.

Let me give you a practical example that it actually happens next door to my country.

In Dubai Burj Khalifa residents at first floor and those at the top floor (2700 feet higher) have different prayer times although same location and geographical coordinates, especially in Ramadan when they have to break the fast.

So, any external library cannot fix this issue and any code must always take 3 parameters as an input to correctly calculate the sunset: latitude, longitude, and elevation.

MohsenAlyafei commented 11 months ago

Existing libraries that calculate sunset without taking into account elevation above sea level are not accurate. You cannot assume that Mexico City is at sea level, for example.

khawarizmus commented 11 months ago

Thanks for @MohsenAlyafei who pointed out that Time4J seems to have a StartOfDay implementation So i am going to add that to the prior art section.