This API is written in ruby programming language and uses parsi-date gem to return value of time and date. You can use this API to find date in Persian (Jalali) and Gregorial calendars.
It's simple, just run api.rb like this :
~$ ruby api.rb -p 4567note that 4567 is default port of sinatra, but you can change it. Now, you can run test.rb, test2.rb and test3.rb to see how the API works.
First, you need a server. For example, your computer is your server and 'localhost' is its host name. Now, you need to install http gem, then write something like this :
require 'http'
request = HTTP.get("http://localhost:4567/time") This will get time from server. Now, you can add this lines :
body = request.body
body = body.to_sto have the output as a string in your program.
Returns current time of the server. Shows result in this format :
HH : MM : SS , Zone = TIMEZONE
You need to give it a parameter, for example :
GET /time/+0330
Then it returns difference between given zone and UTC.
Returns current gregorian day of the server in this format :
MM / DD / YYYY
P.S : American format is more popular than other formats, and this is why I used it.
Returns current Jalali date of the server in this format :
DD / MM / YYY
This is regular format we use in Iran, Afghanistan, Tajikistan and other regions of the world which people use Jalali calendar.
This will convert given date and time to the current date and time of the server. For example :
GET /date/parse/10:25 +0430
And if server is located in Iran, it'll return:
10/14/2016, 9:25:00, Zone: IRST
It takes a gregorian date and converts it to Jalali. for examlpe :
GET /date/to/jalali/2016-05-29
Will return :
9/3/1395
It takes a Jalali date and converts it to Gregorian. for example :
GET /date/to/gregorian/1395-03-09
Will return :
05/29/2016
It takes a timezone, and returns current time of that :
GET /zone/Asia-Tehran
You need to convert zones using this table:
| UNIX Format | API Format |
|---|---|
| Asia/Tehran | Asia-Tehran |
For more zones, you need to do this :
ls /usr/share/zoneinfoon your server.