implementation of islamic (hijri) calendar for Calendar extension

php.internals

mostapha31

22 years ago
Hi these is my contribution to implement islamic (hijri) calendar. Waiting for your suggestions.

Sara Golemon

22 years ago
> these is my contribution to implement islamic (hijri) calendar. > > Waiting for your suggestions. >
Without knowing the internals of the hijri calender here are a few generic suggestions: 1) Consider using zend_parse_parameters rather than zend_get_parameters, it'll help furture readability. 2) Rather than combining month/day/year into astring for returning from jdtohijri() consider returning them as an array of values, as string-OR-array depending on optional flag parameter, or return the component pieces by-ref. 3) What's the maximum length of a hijri date string? If it's 10 like the gregorian calender MM/DD/YYYY, then you need to make your temporary buffer be char[11] to hold the terminating NULL. 3a) When dealing with a short buffer it's a good idea to use snprintf() to be absolutely certain you don't overrun. Since you'll be estrdup()ing this call (in RETURN_STRING()) later on anyway, you could just use spprintf() here and pass the return in with a duplicate parameter of 0, but that's splitting hairs. 3b) It'll also avoid an extra strlen() in RETURN_STRING() if you capture the legnth output of sprintf() and pass it into RETURN_STRINGL(). 4) To avoid potential namespace conflicts, it'd help to prefix the internal methods you define in hijri.c with something uniqing (i.e.: php_cal_hijri_SdnToHijri(), php_cal_hijri_HijriToSdn), or speicfy them as 'static' if they will only be used within their local object file. 5) Internal method names should be all lowercase with underscores used for word boundaries. i.e.: SdnToHijri => std_to_hijri. studlyCaps is meant for object method names exported to userspace. 6) How is Hijri pronounced? Is the j hard like english-"Jump", soft like spanish-"Juego", or silent? Just curious on that one... -Sara

Mehdi Achour

22 years ago
> 6) How is Hijri pronounced? Is the j hard like english-"Jump", soft
like
> spanish-"Juego", or silent? Just curious on that one...
It's like the g in edge. It comes from "El Hijra", the exodus of Muhamed the Islamic prophet :) didou

mostapha31

22 years ago
Hi,
>>these is my contribution to implement islamic (hijri) calendar. >> >>Waiting for your suggestions. >> >> >> >Without knowing the internals of the hijri calender here are a few generic >suggestions: > >1) Consider using zend_parse_parameters rather than zend_get_parameters, >it'll help furture readability. >
for suggestion 1 & 5 : the same code ans the same style of writing are used for the other calendars.
> >2) Rather than combining month/day/year into astring for returning from >jdtohijri() consider returning them as an array of values, as >string-OR-array depending on optional flag parameter, or return the >component pieces by-ref. >
i use that to keep the same syntax for result used with for the others calendars, so the code must be reviewed in totality.
>3) What's the maximum length of a hijri date string? If it's 10 like the >gregorian calender MM/DD/YYYY, then you need to make your temporary buffer >be char[11] to hold the terminating NULL. > >3a) When dealing with a short buffer it's a good idea to use snprintf() to >be absolutely certain you don't overrun. Since you'll be estrdup()ing this >call (in RETURN_STRING()) later on anyway, you could just use spprintf() >here and pass the return in with a duplicate parameter of 0, but that's >splitting hairs. > >3b) It'll also avoid an extra strlen() in RETURN_STRING() if you capture the >legnth output of sprintf() and pass it into RETURN_STRINGL(). > >
ok, I replace sprintf by snprintf
>4) To avoid potential namespace conflicts, it'd help to prefix the internal >methods you define in hijri.c with something uniqing (i.e.: >php_cal_hijri_SdnToHijri(), php_cal_hijri_HijriToSdn), or speicfy them as >'static' if they will only be used within their local object file. > >
I add the prefix to the internal methods defined in hijri.
>5) Internal method names should be all lowercase with underscores used for >word boundaries. i.e.: SdnToHijri => std_to_hijri. studlyCaps is meant for >object method names exported to userspace. > >6) How is Hijri pronounced? Is the j hard like english-"Jump", soft like >spanish-"Juego", or silent? Just curious on that one... > >
for more information about hijri calendar, please read islamic_calendar.txt
>-Sara > > >
Thank you.