Shamsi Ext is a package for converting Gregorian dates to Solar Hijri. This package consists of the following functions:
extensions
shamsi_format(TIMESTAMP WITH TIME ZONE, with_time BOOLEAN DEFAULT TRUE)
shamsi_format(DATE)
shamsi_part(TEXT, TIMESTAMP WITH TIME ZONE)
shamsi_part(TEXT, DATE)
Examples:
SELECT shamsi_format(now()); --> 1400/10/04 23:45:37
SELECT shamsi_format(now(), false); --> 1400/10/04
SELECT shamsi_format('2019-07-07', false); --> 1398/04/16
SELECT shamsi_format('2021-03-20'); --> 1399/12/30 00:00:00
SELECT shamsi_format('2021-03-20'::date); --> 1399/12/30
SELECT shamsi_part('year', '2019-07-07 14:10:52.84937+04:30'); --> 1398
SELECT shamsi_part('minute', '2019-07-07 14:10:52.84937+04:30'); --> 10
SELECT shamsi_part('doy', '2019-07-07 14:10:52.84937+04:30'); --> 109
SELECT shamsi_part('dow', '2019-07-07'); --> 4
shamsi_part
function can accept these values as the first parameter:
- year
- month
- day
- hour
- minute
- second
- doy (day of year)
- dow (day of week with index zero as saturday)
- quarter
- decade
- century
Dependencies:
sudo apt install postgresql-server-dev-14
Run make to build and install
make
sudo make install
Run this command in your psql shell:
\d your_db_name
> CREATE EXTENSION shamsi_ext;
make installcheck