Waqt

For developers

Afghan dates and time for your program

The Shamsi and Qamari calendars, month names in seven languages, and sunrise and sunset at every provincial capital: a few plain files and one JavaScript module. No key, no sign-up.

Version 1JSON and JavaScriptExamples in JavaScript and PHP

On this page

In shortAll the files are at waqt.qudqu.com/api/v1/ and open from any site. Each one is made from the same code this site runs, so the API and the site never give two different dates. No Iranian month name is in any of them.

Quick start

One import in a <script type="module"> is all it takes: no install, no key, no sign-up. This code just ran in your browser; today's answer is under each line.

quick-start.htmlHTML
Ran just now
<script type="module">
	import { Calendar, Language, formatDate, wallTime }
		from 'https://waqt.qudqu.com/api/v1/waqt.js';

	// Today on Afghan time, as a day number
	const today = wallTime(Date.now()).day;

	console.log(formatDate(today, Calendar.SHAMSI, Language.DARI).text);
	// → …
	console.log(formatDate(today, Calendar.QAMARI, Language.PASHTO).text);
	// → …
	console.log(formatDate(today, Calendar.GREGORIAN, Language.ENGLISH).text);
	// → …
</script>

The files

FileWhat it holdsSize
calendar.jsonThe Shamsi and Qamari year tables, what a day number is, Afghan time3 KB
names.jsonThe months of the three calendars, the weekdays and the digits, in seven languages3 KB
places.jsonThe 34 provincial capitals: coordinates, the city's and the province's names in seven languages4 KB
sun/kabul.jsonThe sun on every day of the Shamsi year; one file for each provincial capital4 KB
waqt.jsThe JavaScript module: converting and writing dates, Afghan time, the sun and the moon20 KB
Sizes compressed (gzip), as a browser receives them. Each JSON file says in its description how to read it.

Converting dates with day numbers

Every date has a day number: the days since 1 January 1970. All three calendars convert to and from day numbers, so a date goes from one calendar to another by way of its day number.

The module does this with one function. Without it, it is simple too: in calendar.json, find the last year that starts on or before the day, then count the months.

import {
	Calendar, Digits, HijriAdjustment, Language,
	formatDate, fromGregorian, fromShamsi,
	toGregorian, toQamari, toShamsi, wallTime
} from 'https://waqt.qudqu.com/api/v1/waqt.js';

// A date is a day number: whole days since 1 January 1970
const nowruz = fromGregorian(2026, 3, 21);
console.log(nowruz);
// → 20533
console.log(toShamsi(nowruz));
// → { year: 1405, month: 1, day: 1 }
console.log(toQamari(nowruz));
// → { year: 1447, month: 10, day: 2 }
console.log(toGregorian(fromShamsi(1404, 12, 29)));
// → { year: 2026, month: 3, day: 20 }

// If the month began a day later in Afghanistan than in Umm al-Qura
console.log(toQamari(nowruz, HijriAdjustment.DAY_LATER));
// → { year: 1447, month: 10, day: 1 }

// As text, in any of the seven languages
console.log(formatDate(nowruz, Calendar.SHAMSI, Language.DARI).text);
// → ۱ حمل ۱۴۰۵
console.log(formatDate(nowruz, Calendar.SHAMSI, Language.PASHTO).text);
// → ۱ وری ۱۴۰۵
console.log(formatDate(nowruz, Calendar.QAMARI, Language.ENGLISH).text);
// → 2 Shawwal 1447

// With the weekday, in Latin digits
const options = { weekday: true, digits: Digits.LATIN };
console.log(formatDate(nowruz, Calendar.SHAMSI, Language.DARI, options).text);
// → شنبه، 1 حمل 1405

// Today, on Afghan time
const today = wallTime(Date.now()).day;
console.log(formatDate(today, Calendar.QAMARI, Language.DARI).text);

Qamari dates and moon sighting

The Qamari table is the Umm al-Qura calendar. In Afghanistan a Qamari month begins when the new crescent is seen, and that cannot be calculated in advance: a date is sometimes a day off from the table. If a month began a day later than the table says, read the table at the day before (the day number minus 1); if a day earlier, at the day after. The module's functions take the same as HijriAdjustment.DAY_LATER or HijriAdjustment.DAY_EARLIER.

Month and weekday names in seven languages

names.json has, for each language, the months of the three calendars, the weekdays from Saturday, "before noon" and "after noon", the calendars' names and the language's digits. Pashto has its own month names; the other languages write the Dari names in their own script.

No Iranian month name is in these files, and our tests check every day in every language. Take the names from this file, not from the browser: many browsers show Iranian names for Afghanistan.

names.jsonJSON
{
  "languages": {
    "fa": {
      "months": {
        "shamsi": [
          "حمل", "ثور", "جوزا", "سرطان", "اسد", "سنبله",
          "میزان", "عقرب", "قوس", "جدی", "دلو", "حوت"
        ],
        "qamari": ["محرم", …],
        "gregorian": ["جنوری", …]
      },
      "weekdays": [
        "شنبه", "یکشنبه", "دوشنبه", "سه‌شنبه",
        "چهارشنبه", "پنجشنبه", "جمعه"
      ],
      "digits": "۰۱۲۳۴۵۶۷۸۹",
      …
    },
    "ps": {
      "months": {
        "shamsi": [
          "وری", "غویی", "غبرګولی", "چنګاښ", "زمری", "وږی",
          "تله", "لړم", "لیندۍ", "مرغومی", "سلواغه", "کب"
        ],
        "qamari": ["محرم", …],
        "gregorian": ["جنوري", …]
      },
      "weekdays": [
        "شنبه", "یکشنبه", "دوشنبه", "سه شنبه",
        "چهارشنبه", "پنجشنبه", "جمعه"
      ],
      "digits": "۰۱۲۳۴۵۶۷۸۹",
      …
    },
    "en": { "months": { "shamsi": ["Hamal", "Sawr", "Jawza", …] }, … },
    …
  }
}

Sunrise and sunset

For each provincial capital there is a table: first light, sunrise, solar noon, sunset, nightfall and the length of the day, for every day of the Shamsi year, on Afghan time. The table holds for every year within 2 minutes, because the Shamsi year follows the sun.

For the exact minute in one year, or for any other place, use sunDay. Its formula is here in PHP too.

// A sun table needs no code: months[m - 1][d - 1] is Shamsi month m, day d
const url = 'https://waqt.qudqu.com/api/v1/sun/herat.json';
const table = await (await fetch(url)).json();
console.log(table.columns);
// → [ 'firstLight', 'sunrise', 'noon', 'sunset', 'dark', 'dayLength' ]
console.log(table.months[0][0]); // 1 Hamal
// → [ '05:30', '06:25', '12:29', '18:33', '19:27', '12:08' ]

The moon

The module gives the moon's place in the sky from anywhere, how much of it is lit, its rise and set on any day, and the next new and full moon. It is not for sighting the first crescent of a month.

moon.jsJavaScript
import {
	MoonPhase, moonState, nextMoonPhase
} from 'https://waqt.qudqu.com/api/v1/waqt.js';

// The moon over Kabul on an evening (or moonState(ms, latitude, longitude))
const evening = Date.parse('2026-03-21T19:00:00+04:30');
const moon = moonState(evening);

// Percent lit, and days since the new moon
console.log(Math.round(moon.lit * 100), moon.age.toFixed(1));
// → 9 2.8

const full = nextMoonPhase(evening, MoonPhase.FULL);
console.log(new Date(full).toISOString().slice(0, 16));
// → 2026-04-02T02:14

Version 1: what does not change

  • The files keep their shape. Things may be added to them, but no name is removed or changed. A change that doesn't fit this rule becomes /api/v2/, and version 1 stays.
  • From 1 January 1900 to 25 November 2174 (1278 to 1553 Shamsi, 1317 to 1600 Qamari). Outside these dates the functions give an error.
  • From any site. The files are sent with Access-Control-Allow-Origin: *, and browsers keep them for 10 minutes.
  • No statistics or cookies. The files set no cookies and collect no statistics.

Licence

Licence: CC BY 4.0

Seen a mistake, or is something missing? Write to us.