JIMBO HAZIM

Ensuring Accurate Hijri Dates in Memo Generation using JAKIM e-solat API

PROJECT

// OVERVIEW

This project involved addressing an inaccuracy in our internal “Chinese Lunar Calendar/Gregorian” system, which was causing a one-day shift in the displayed Hijri date, particularly noticeable during the observation of Ramadan. To rectify this, I took the initiative to research and implement a solution that leverages the reliable e-solat API provided by JAKIM (Jabatan Kemajuan Islam Malaysia), a trusted Malaysian federal government agency. This API provides accurate prayer times and related Islamic calendar information, including the Hijri date. The solution was integrated into our existing system, which generates Memos (PDF documents) using Jasper Reports. A custom function was implemented to retrieve the accurate Hijri dates and ensure their inclusion in the generated reports.

OBSTACLE

// THE CHALLENGE

Our internal calendar system was incorrectly calculating the start of Ramadan based on the new moon sighting, leading to Inconsistencies with the actual dates. This was a critical issue, especially for official memos and internal record-keeping during this significant religious period. The e-solat API offered a potential solution by providing real-time, accurate Hijri dates. However, the specific API endpoint and parameters for retrieving Hijri dates were not officially documented, requiring investigation and problem-solving.

THE SOLUTION

// THE SOLUTION & IMPLEMENTATION

To integrate the accurate Hijri dates, I developed a new PostgreSQL function, convert_to_hijri_date_from_api, within our database layer. This function performs the following steps:

  • Input: Takes a Miladi (Gregorian) date (DD/MM/YYYY format) as input.

  • Formatting: Reformats the input date to ‘YYYY-MM-DD’, the expected format for the API request.

  • API Call: Makes an HTTP GET request to the e-solat API endpoint: 

				
					curl https://www.e-solat.gov.my/index.php?r=esolatApi%2Ftarikhtakwim&period=today&datetype=miladi&date=[YYYY-MM-DD]
				
			
  • Status Check: Verifies if the API endpoint is reachable by checking the HTTP status code.

  • JSON Parsing: If the API call is successful (status code 200), the function parses the JSON response to extract the Hijri date associated with the provided Miladi date. As seen in the example below, the Hijri date is nested within the "takwim" object:

				
					{
  "takwim": {
    "2025-03-21": "1446-09-20"
  },
  "serverTime": "2025-03-21 16:08:42",
  "dateType": "miladi",
  "dateRequest": "2025-03-21",
  "status": "OK!"
}
				
			

The function extracts the value associated with the Miladi date key within the "takwim" object.

  • Fallback Mechanism: In case the API is unreachable (non-200 status code) or the Hijri date is not found in the response, the function gracefully falls back to using our existing internal Hijri date calculation function to ensure the memo generation process is not interrupted.

  • Output: Returns the accurate Hijri date in ‘DD-MM-YYYY’ format.

INSIGHTS

// KEY ACCOMPLISHMENTS

  • Proactive Problem Solving: Identified a critical data inaccuracy and took the initiative to find and implement a reliable external solution.
  • Working with Undocumented APIs: Successfully navigated the lack of official documentation for the specific Hijri date aspect of the e-solat API by inspecting API responses and understanding its structure. This demonstrates the ability to learn and adapt in the absence of formal guides.
  • Seamless Integration: Successfully integrated the external API into our existing PostgreSQL database and CodeIgniter application with minimal disruption to the workflow.
  • Improved Data Accuracy: Ensured the generated memos now display accurate Hijri dates, resolving a significant discrepancy and improving the reliability of our system.
  • Robustness through Fallback: Implemented a fallback mechanism to handle potential API downtime or errors, ensuring the continued functionality of the memo generation feature.
  • Enhanced Documentation (for future reference): This showcase page serves as documentation for the implemented solution, outlining the problem, the approach, the technical details, and the outcomes for future reference by other team members.

PROJECT

// CONCLUSION

This project highlights my ability to identify and solve critical issues, work with external and even undocumented APIs, integrate solutions within existing systems, and prioritize data accuracy. The successful implementation of the JAKIM e-solat API for Hijri date retrieval has significantly improved the reliability and accuracy of our memo generation process, particularly during important religious observances. I am always eager to tackle challenges and find innovative solutions to improve system functionality and data integrity.