LB Booster
« Hijri calendar »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 03:55am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Hijri calendar  (Read 610 times)
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Hijri calendar
« Thread started on: Aug 4th, 2015, 01:04am »

I was asked to write a program to find the date according to the Hijri (Islamic) calendar. It took a lot of Googling to discover how to do it; here's the answer in case anybody else is interested. It needs Windows Vista or later:

Code:
    CAL.HIJRI = 6
    global CAL.HIJRI

    struct SYSTEMTIME, wYear as word, wMonth as word, _
      wDayOfWeek as word, wDay as word, wHour as word, _
      wMinute as word, wSecond as word, wMilliseconds as word

    struct CALDATETIME, CalId as long, Era as long, _
      Year as long, Month as long, Day as long, DayOfWeek as long, _
      Hour as long, Minute as long, Second as long, Tick as long

    calldll #kernel32, "GetSystemTime", SYSTEMTIME as struct, _
      result as long

    calldll #kernel32, "ConvertSystemTimeToCalDateTime", _
      SYSTEMTIME as struct, CAL.HIJRI as long, _
      CALDATETIME as struct, result as long

    print "Today's date in the Hijri calendar is:"
    print "Year ";  CALDATETIME.Year.struct;", ";
    print "Month "; CALDATETIME.Month.struct;", ";
    print "Day ";   CALDATETIME.Day.struct 

Richard.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Hijri calendar
« Reply #1 on: Aug 12th, 2015, 1:56pm »

Gregorian-to-Hijri and Hijri-to-Gregorian conversion functions (the parameters are not checked for validity).

Edit: Corrected HijriToGregorian function.

Code:
    CAL.HIJRI = 6
    global CAL.HIJRI

    struct SYSTEMTIME, wYear as word, wMonth as word, _
      wDayOfWeek as word, wDay as word, wHour as word, _
      wMinute as word, wSecond as word, wMilliseconds as word

    struct CALDATETIME, CalId as long, Era as long, _
      Year as long, Month as long, Day as long, DayOfWeek as long, _
      Hour as long, Minute as long, Second as long, Tick as long

    year = 1952 : month = 5 : day = 3

    call GregorianToHijri year, month, day
    print year, month, day

    call HijriToGregorian year, month, day
    print year, month, day

    wait
    end

sub GregorianToHijri byref year, byref month, byref day
    SYSTEMTIME.wYear.struct = year
    SYSTEMTIME.wMonth.struct = month
    SYSTEMTIME.wDay.struct = day
    calldll #kernel32, "ConvertSystemTimeToCalDateTime", _
      SYSTEMTIME as struct, CAL.HIJRI as long, _
      CALDATETIME as struct, result as long
    year = CALDATETIME.Year.struct
    month = CALDATETIME.Month.struct
    day = CALDATETIME.Day.struct
end sub

sub HijriToGregorian byref year, byref month, byref day
    CALDATETIME.Year.struct = year
    CALDATETIME.Month.struct = month
    CALDATETIME.Day.struct = day
    CALDATETIME.CalId.struct = CAL.HIJRI
    CALDATETIME.Era.struct = 1
    for dow = 1 to 7
      CALDATETIME.DayOfWeek.struct = dow
      calldll #kernel32, "ConvertCalDateTimeToSystemTime", _
        CALDATETIME as struct, SYSTEMTIME as struct, _
        result as long
    next
    year = SYSTEMTIME.wYear.struct
    month = SYSTEMTIME.wMonth.struct
    day = SYSTEMTIME.wDay.struct
end sub 

Richard.
« Last Edit: Aug 14th, 2015, 09:35am by Richard Russell » User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Hijri calendar
« Reply #2 on: Aug 13th, 2015, 9:24pm »

I found this note about Gregorian-Hijri conversions generally:

"The same Gregorian date may actually have up to four Hijri equivalent dates according to the PLACE & TIME. The 1st of Ramadan in Jordan for example could be the 30th of Shaban in some other parts of the world according to the sighting of the moon, also 1st of Ramadan at an instance in San Francisco could be equivalent to the 2nd of Ramadan in China because of time zone difference. To add on top of that, the Islamic & Hebrew days begin at sunset, so the 1st of August before sunset & after sunset will correspond to two different Islamic & Hebrew days."

I don't know what assumptions the Windows API routines make, so don't be surprised if the conversion functions above give a different result from other converters you might find.

Richard.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Hijri calendar
« Reply #3 on: Aug 14th, 2015, 09:04am »

Sorry, I discovered that the HijriToGregorian function didn't work. Now corrected in the post above.

Richard.
« Last Edit: Aug 14th, 2015, 09:36am by Richard Russell » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls