Git Product home page Git Product logo

gshconverter's Introduction

A very lightweight package that provides functions to convert between Gregorian and Solar Hijri calendars. Solar Hijri is the official calendar being used in Iran.

Installation

Requires Python 3.12+

pip install gshconverter

Usage

The main functions are:

  • solar_hijri_to_gregorian(sh_year: int, sh_month: int, sh_day: int) -> tuple[int, int, int]
  • gregorian_to_solar_hijri(g_year: int, g_month: int, g_day: int) -> tuple[int, int, int]
  • is_g_leap(year: int) -> bool
  • is_sh_leap(year: int) -> bool

Example:

>>> from gshconverter import *
>>> is_sh_leap(1403)
True
>>> solar_hijri_to_gregorian(1403, 12, 30)
(2025, 3, 20)
>>> gregorian_to_solar_hijri(2025, 3, 20)
(1403, 12, 30)

Notes

This library currently assumes 33-year cycles which means it will get inaccurate for dates too far in the future (the first known incorrect year is 1502 SH) or too far in the past (the results are known to be correct at least until 1210 SH according to University of Tehran astronomical calculation).

The output of converter functions are the same as the ones in FarsiWeb's jalali.c , but gshconverter uses a different algorithm and is written from scratch. It also is faster than the current Python implementation used in jdatetime library .

gshconverter's People

Contributors

5j9 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.