Date Conversion API Documentation

Overview

The Date Conversion API provides functionality to convert dates between the Bikram Sambat (BS) and Gregorian (AD) calendars. The API is built using Flask and supports Cross-Origin Resource Sharing (CORS).

Base URL

https://sudhang.pythonanywhere.com/

Live Demo BStoAD

Request URL: https://sudhang.pythonanywhere.com/BStoAD/2005/05/11

Live Demo ADtoBS

Request URL: https://sudhang.pythonanywhere.com/ADtoBS/2005/05/11

API Endpoints

1. Homepage

Endpoint: /

Method: GET

Description: Renders the documentation page for the API.

Response: Returns the documentation.html file.

GET / HTTP/1.1
Host: sudhang.pythonanywhere.com

2. Date Conversion Page

Endpoint: /dateconvert

Method: GET

Description: Renders the date conversion page for users.

Response: Returns the dateconvert.html file.

GET /dateconvert HTTP/1.1
Host: sudhang.pythonanywhere.com

3. Convert BS Date to AD Date

Endpoint: /BStoAD/<int:year>/<int:month>/<int:day>

Method: GET

Path Parameters:

Description: Converts a given BS date to its corresponding AD date.

Response: Returns a JSON object containing the AD date or an error message.

Response Format:

Success:

{ "ad_date": { "day": <day>, "month": <month>, "year": <year> } }

Error:

{ "error": "Error message" }
GET /BStoAD/2080/1/1 HTTP/1.1
Host: sudhang.pythonanywhere.com

Successful Response:

{ "ad_date": { "day": 14, "month": 4, "year": 2023 } }

4. Convert AD Date to BS Date

Endpoint: /ADtoBS/<int:year>/<int:month>/<int:day>

Method: GET

Path Parameters:

Description: Converts a given AD date to its corresponding BS date.

Response: Returns a JSON object containing the BS date or an error message.

Response Format:

Success:

{ "bs_date": { "day": <day>, "month": <month>, "year": <year> } }

Error:

{ "error": "Error message" }
GET /ADtoBS/2023/1/15 HTTP/1.1
Host: sudhang.pythonanywhere.com

Successful Response:

{ "bs_date": { "day": 1, "month": 10, "year": 2079 } }

Error Handling

If an error occurs during the conversion, the API will return a JSON object with an error message. Common errors may include:

Example Error Response:

{ "error": "Invalid date format returned from conversion function." }

Add Date Convertor In your website

To embed the Date Conversion page in your own application, use the following iframe code:

Author

This API is developed by Sudhan Parajuli.

Notes

Handle potential exceptions in client-side code to manage errors gracefully.