Skip to content

jdate

Jalali calendar date, timestamp and range types

postgres-jdate · Jalali calendar date, timestamp and range types

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
102486jdatepostgres-jdate1.0.1TYPEMITC

PostgreSQL · 16, 17, 18

Usage

Sources:

jdate provides Jalali calendar dates, timestamps and ranges. Release 1.0.1 uses SQL extension version 1.0. Upstream requires PostgreSQL 16 or later and tests 16–18.

Enable and Convert

After installing the server files, a superuser creates the extension. No preload or restart is required. Choose the installation schema at creation: the extension cannot be relocated because some syntax overloads live in pg_catalog.

CREATE EXTENSION jdate;
SELECT DATE '2024-03-20'::jdate;
SELECT '1403-01-01'::jdate::date;
SELECT jmonth_format(DATE '2024-04-20'::jdate);

The results are 1403-01-01, 2024-03-20 and 1403-02.

Calendar Operations

Types include jdate, jtimestamp, jtimestamptz, jdaterange, jtsrange and jtstzrange, with B-tree/hash support for scalar types. jdate_part, jdate_trunc, jday_format and jmonth_format provide fields and reporting keys; jgenerate_series and jdate_bin generate or group time periods.

SELECT '1403-06-31'::jdate + INTERVAL '1 month';
SELECT EXTRACT(month FROM '1403-05-15'::jdate);
SET timezone = 'Asia/Tehran';
SELECT '1403-01-01 12:00'::jtimestamp AT TIME ZONE 'Asia/Tehran';

Month arithmetic clamps invalid month-end days. Weeks start on Saturday for Jalali week truncation. Cast untyped literals and parameters explicitly to avoid overload ambiguity. Text input uses Jalali dates; cast from core date/timestamp types to convert Gregorian values.

Boundaries and Maintenance

The finite calendar range is limited by the documented conversion algorithm; out-of-range casts or arithmetic fail. jtimestamptz display and local-day conversion depend on TimeZone; to_jdate from epoch seconds uses the UTC day. Use an explicit reporting zone for indexed expressions.

Patch releases retain SQL version 1.0, so no SQL update script is needed for 1.0.1. Backups require extension files on the restore server and superuser installation privileges.

Table reader