Gahshomar Date and Time API

Hello, World!

This API is written in Sinatra , for those who want to have real time date and time in their own applications. The project is open sources, and sources are available on Github . Also, there are some tests on github, please take a look at them to understand how this API works.

How it works?

Time

GET /time

Returns current time of the server. Shows result in this format :

HH : MM : SS , Zone = TIMEZONE

Difference Between Given Zone and UTC

GET /time/:zone

You need to give it a parameter, for example :

GET /time/+0330

Then it returns difference between given zone and UTC.

Date

GET /date

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.

Jalali Date

GET /date/jalali

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.

Parsing a date

GET /date/parse/:current

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

Converting Gregorian to Jalali

GET /date/to/jalali/:current

It takes a gregorian date and converts it to Jalali. for examlpe :

GET /date/to/jalali/2016-05-29

Will return:

9/3/1395

Converting Jalali to Gregorian

GET /date/to/gregorian/:current

It takes a Jalali date and converts it to Gregorian. for example :

GET /date/to/gregorian/1395-03-09

Will return:

05/29/2016

Current time from a timezone

GET /zone/:zone

It takes a timezone, and returns current time of that :

GET /zone/Asia-Tehran

For more zones, you need to do this:

ls /usr/share/zoneinfo

Writing a simple test

We use ruby programming language and "http" gem for writing tests. This is a very, very simplr test which returns current server's date:

require 'http'

r = HTTP.get("http://localhost/date")
puts r.body.to_s

Now, it's ready to use!