PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: cCalendar RC 1  (Read 1057 times)

Richard Kelly

  • FireFly3 Registered User
  • Senior FireFly Member
  • *
  • Posts: 318
cCalendar RC 1
« on: September 18, 2016, 03:10:03 AM »

I'm calling this release candidate 1 since the foundation code is complete and the next steps are to add other calendars with their holiday rules if applicable. I have code snippets as a work in progress for moonrise/set and if time permits, will add it later.

Whats New:

1. Chinese Calendar
2. Sunrise/Sunset including Civil, Nautical and Astronomical times
3. Solar Noon or Transit
4. Daylight Savings support
5. Lunar Distance
6. Solar Distance
7. Lunar Illumination
8. Lunar Phases, New, First Quarter, Full, and, Last Quarter
9. Distance and Bearing between two points

Everything is marked private for maximum dead code removal per Jose's recommendation.

Test script is included in the attachment.

Next up is the Hebrew Calendar.

If you use FF, turn on your console option before running the test script.

You need to add the following since I used the Format command.

#Include Once "String.bi"

Enjoy!
« Last Edit: September 18, 2016, 02:44:43 PM by Richard Kelly »
Logged

Richard Kelly

  • FireFly3 Registered User
  • Senior FireFly Member
  • *
  • Posts: 318
Re: cCalendar RC 1
« Reply #1 on: September 18, 2016, 08:32:23 PM »

Just a quick note regarding the Islamic calendar. As you are probably aware, there is no global accepted practice to determining when a new month begins. The common denominator in all the hours I've read Islamic publications speaking to this is that each month begins when a visible crescent appears after the birth of a new moon.

Some councils accept astronomical calculations, some accept sightings by observers while there are some blending of the two.

What astronomers tell me is that the crescent after a new moon can take up to 23 hours to become visible with some rare sighting times closer to 15 hours.

After consideration, I've decided to take a universal approach with a basis in factual astronomy and incorporate the international date line (IDT). If the UTC time of a new moon occurs on or prior to noon then a crescent moon must be visible in the world as the day unfolds to the west of the IDT else it will be visible the next day. This only requires the calculation of a new moon time and cCalendar has very accurate lunar calculations.

Preliminary results look promising.

Perhaps there are some learned Islamic readers here that could shed additional insight. I could take the Mecca rule about the relationship between new moon time and local sunset/moonrise times and cCalendar could be directed to use the calculation of your choice.

Rick


Logged

Richard Kelly

  • FireFly3 Registered User
  • Senior FireFly Member
  • *
  • Posts: 318
Re: cCalendar RC 1
« Reply #2 on: September 20, 2016, 07:53:36 PM »

OMG, I found an error. It's all those funny symbols mathematicians use to write their formulas.... :o

This affects some of the lunar and solar calculations, at times, significantly.

This function:

Code: [Select]
' ========================================================================================
' Angular distance measured eastward along the celestial equator from the vernal equinox
' ========================================================================================
Private Function cCalendar.cmRightAscension (ByVal nObliquity as Double, _
                                             ByVal nLatitude as Double, _
                                             ByVal nLongitude as Double) as Double

    Function = cmArcTanDegrees((cmSinDegrees(nLatitude) * _
                    cmCoSineDegrees(nObliquity)) - _
                    (cmTangentDegrees(nLongitude) * _
                    cmSinDegrees(nObliquity)),cmCoSineDegrees(nLatitude))
                   
End Function

Should be changed to:

Code: [Select]
' ========================================================================================
' Angular distance measured eastward along the celestial equator from the vernal equinox
' ========================================================================================
Private Function cCalendar.cmRightAscension (ByVal nObliquity as Double, _
                                             ByVal nLatitude as Double, _
                                             ByVal nLongitude as Double) as Double

    Function = cmArcTanDegrees((cmSinDegrees(nLongitude) * _
                    cmCoSineDegrees(nObliquity)) - _
                    (cmTangentDegrees(nLatitude) * _
                    cmSinDegrees(nObliquity)),cmCoSineDegrees(nLongitude))
                   
End Function
Logged

Richard Kelly

  • FireFly3 Registered User
  • Senior FireFly Member
  • *
  • Posts: 318
Re: cCalendar RC 1
« Reply #3 on: September 20, 2016, 11:49:54 PM »

I also have the determination of daylight savings backwards. For Anchorage, Alaska standard time zone is -9 hours and the adjustment is -60 minutes. Between the spring when DST is active and the Fall when is inactive, I need to take -9 - (-60 min or -1 hour) which will shift the zone to -8 hours. I'll get it cleaned up....I promise.... ::)
Logged

Richard Kelly

  • FireFly3 Registered User
  • Senior FireFly Member
  • *
  • Posts: 318
Re: cCalendar RC 1
« Reply #4 on: September 22, 2016, 07:35:55 PM »

Daylight Savings patch

Replace function cmDaylightSavings with:

Code: [Select]
' ========================================================================================
' Adjust a serial date for daylight savings
' ========================================================================================
Private Function cCalendar.cmDaylightSavings (ByVal nSerial as LongInt, _
                                              ByRef uLocale as LOCATION_LOCALE) as LongInt

    uLocale.bDaylightLightSavingsActive = False
                                             
    If nSerial >= uLocale.DaylightSavingsBegins AndAlso nSerial <  uLocale.DaylightSavingsEnds _
       AndAlso uLocale.bApplyDaylightSavings = True Then

       nSerial = nSerial _
               + (Abs(uLocale.DaylightSavingsMinutes) _
               * cCalendarClass.ONE_MINUTE _
               * cmSignum(uLocale.Zone) _
               * -1)
       uLocale.bDaylightLightSavingsActive = True
     
    End If                                             

    Function = nSerial
   
End Function

and update the test script with:

Code: [Select]
' Daylight Savings rules for most of USA
 
    arRules(0).Name = "Daylight Savings Begins"   
    arRules(0).Month = cCalendarClass.MARCH
    arRules(0).Day = 0
    arRules(0).Year = nYear
    arRules(0).RuleClass = cCalendarClass.GREGORIAN_RULES
    arRules(0).Rule = cCalendarClass.SECOND_WEEK
    arRules(0).Weekday = cCalendarClass.SUNDAY
    arRules(0).SaturdayRule = cCalendarClass.NO_SATURDAY_RULE
    arRules(0).SundayRule = cCalendarClass.NO_SUNDAY_RULE
    arRules(0).YearRule = cCalendarClass.ALL_YEARS
    arRules(0).NonBusinessDate = False
   
    arRules(1).Name = "Daylight Savings Ends"   
    arRules(1).Month = cCalendarClass.NOVEMBER
    arRules(1).Day = 0
    arRules(1).Year = nYear
    arRules(1).RuleClass = cCalendarClass.GREGORIAN_RULES
    arRules(1).Rule = cCalendarClass.FIRST_WEEK
    arRules(1).Weekday = cCalendarClass.SUNDAY
    arRules(1).SaturdayRule = cCalendarClass.NO_SATURDAY_RULE
    arRules(1).SundayRule = cCalendarClass.NO_SUNDAY_RULE
    arRules(1).YearRule = cCalendarClass.ALL_YEARS
    arRules(1).NonBusinessDate = False
   
    oCalendar.DateCalculation(arRules())
    nDaylightSavingsBegins = arRules(0).ObservedDays1 + cCalendarClass.ONE_HOUR * 2
    nDaylightSavingsEnds = arRules(1).ObservedDays1  + cCalendarClass.ONE_HOUR * 2
.
.
.
    uLocale.Zone = -9                       ' Standard Time
Logged