From 4008b39e1be5473a92ba7c2591b1d7aefef0c708 Mon Sep 17 00:00:00 2001 From: Milad Date: Mon, 25 Mar 2024 10:58:38 +0100 Subject: [PATCH 1/7] use jalali lib as a separate dependency --- jdatetime/__init__.py | 4 +- jdatetime/jalali.py | 129 ------------------------------------------ setup.py | 1 + 3 files changed, 2 insertions(+), 132 deletions(-) delete mode 100644 jdatetime/jalali.py diff --git a/jdatetime/__init__.py b/jdatetime/__init__.py index 3559245..eabd784 100644 --- a/jdatetime/__init__.py +++ b/jdatetime/__init__.py @@ -14,9 +14,7 @@ except ImportError: from _thread import get_ident -from jdatetime.jalali import ( - GregorianToJalali, JalaliToGregorian, j_days_in_month, -) +from jalali_core import GregorianToJalali, JalaliToGregorian, j_days_in_month __VERSION__ = "4.1.1" MINYEAR = 1 diff --git a/jdatetime/jalali.py b/jdatetime/jalali.py deleted file mode 100644 index 912f1b5..0000000 --- a/jdatetime/jalali.py +++ /dev/null @@ -1,129 +0,0 @@ -# The algorithms to convert between Jalali and Gregorian dates, are based on -# FarsiWeb's jalali.c library (http://www.farsiweb.info/jalali/jalali.c). -# -# Copyright (C) 2001 Roozbeh Pournader -# Copyright (C) 2001 Mohammad Toossi -# Copyright (C) 2003-2011 Parspooyesh Fanavar (http://parspooyesh.com/) -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You can receive a copy of GNU Lesser General Public License at the -# World Wide Web address . - -g_days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] -j_days_in_month = [31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29] - - -class GregorianToJalali: - def __init__(self, gyear, gmonth, gday): - """ - Convert gregorian date to jalali date - gmonth: number of month in range 1-12 - """ - self.gyear = gyear - self.gmonth = gmonth - self.gday = gday - self.__gregorianToJalali() - - def getJalaliList(self): - return (self.jyear, self.jmonth, self.jday) - - def __gregorianToJalali(self): - """ - g_y: gregorian year - g_m: gregorian month - g_d: gregorian day - """ - gy = self.gyear - 1600 - gm = self.gmonth - 1 - - j_day_no = ( - 365 * gy + (gy + 3) // 4 - (gy + 99) // 100 - + (gy + 399) // 400 + self.gday - 1 - 79 - ) - - for i in range(gm): - j_day_no += g_days_in_month[i] - if gm > 1 and ((gy % 4 == 0 and gy % 100 != 0) or (gy % 400 == 0)): - # leap and after Feb - j_day_no += 1 - - j_np = j_day_no // 12053 - j_day_no %= 12053 - jy = 979 + 33 * j_np + 4 * (j_day_no // 1461) - - j_day_no %= 1461 - - if j_day_no >= 366: - j_day_no -= 1 - jy += j_day_no // 365 - j_day_no %= 365 - - for i in range(11): - if not j_day_no >= j_days_in_month[i]: - i -= 1 - break - j_day_no -= j_days_in_month[i] - - self.jyear = jy - self.jmonth = i + 2 - self.jday = j_day_no + 1 - - -class JalaliToGregorian: - def __init__(self, jyear, jmonth, jday): - """ - Convert db time stamp (in gregorian date) to jalali date - """ - self.jyear = jyear - self.jmonth = jmonth - self.jday = jday - self.__jalaliToGregorian() - - def getGregorianList(self): - return (self.gyear, self.gmonth, self.gday) - - def __jalaliToGregorian(self): - jy = self.jyear - 979 - g_day_no = 365 * jy + (jy // 33) * 8 + (jy % 33 + 3) // 4 + self.jday - 1 + 79 - for i in range(self.jmonth - 1): - g_day_no += j_days_in_month[i] - - gy = 1600 + 400 * (g_day_no // 146097) # 146097 = 365*400 + 400/4 - 400/100 + 400/400 - g_day_no %= 146097 - - leap = 1 - if g_day_no >= 36525: # 36525 = 365*100 + 100/4 - g_day_no -= 1 - gy += 100 * (g_day_no // 36524) # 36524 = 365*100 + 100/4 - 100/100 - g_day_no %= 36524 - - if g_day_no >= 365: - g_day_no += 1 - else: - leap = 0 - - gy += 4 * (g_day_no // 1461) # 1461 = 365*4 + 4/4 - g_day_no %= 1461 - - if g_day_no >= 366: - leap = 0 - g_day_no -= 1 - gy += g_day_no // 365 - g_day_no %= 365 - - i = 0 - while g_day_no >= g_days_in_month[i] + (i == 1 and leap): - g_day_no -= g_days_in_month[i] + (i == 1 and leap) - i += 1 - self.gmonth = i + 1 - self.gday = g_day_no + 1 - self.gyear = gy diff --git a/setup.py b/setup.py index f2d8334..3cb8186 100644 --- a/setup.py +++ b/setup.py @@ -15,6 +15,7 @@ url="https://github.com/slashmili/python-jalali", long_description=open('README').read(), python_requires=">=3.8", + install_requires=["jalali-core>=1.0"], classifiers=[ "Intended Audience :: Developers", "Intended Audience :: System Administrators", From a084ce3c4a4b54e7dbd2e9ae85615ce56d391fde Mon Sep 17 00:00:00 2001 From: Milad Date: Mon, 25 Mar 2024 11:00:56 +0100 Subject: [PATCH 2/7] prepare for majour release --- CHANGELOG.md | 4 ++-- LICENSE | 21 --------------------- README.rst | 5 ----- setup.py | 2 +- 4 files changed, 3 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 627a703..009e022 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,14 +1,14 @@ # Changelog -## [Unreleased] +## [5.0.0] - YYYY-MM-DD ### Add * Add support for Python 3.12 -* add LGPL licence for jalali.py file ### Changed * BREAKING CHANGE: Arithmetic operations on `date`/`datetime` against an unknown type will now return `NotImplemented` instead of raising `TypeError` * Drop Python 3.7 support +* Use jalali.py as jalali_core dependency #148 ### Fixed * treat %% as an escape sequence in strftime diff --git a/LICENSE b/LICENSE index a3c7e2b..277b10f 100644 --- a/LICENSE +++ b/LICENSE @@ -3,24 +3,3 @@ jdatetime is (c) 2010-2018 Milad Rastian . The jdatetime module was contributed to Python as of Python 2.7 and thus was licensed under the Python license. Same license applies to all files in the jdatetime package project. - -The algorithms to convert between Jalali and Gregorian dates, are based on -FarsiWeb's jalali.c library (http://www.farsiweb.info/jalali/jalali.c). - -Copyright (C) 2001 Roozbeh Pournader -Copyright (C) 2001 Mohammad Toossi -Copyright (C) 2003-2011 Parspooyesh Fanavar (http://parspooyesh.com/) - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You can receive a copy of GNU Lesser General Public License at the -World Wide Web address . - diff --git a/README.rst b/README.rst index 6913e43..d296020 100644 --- a/README.rst +++ b/README.rst @@ -3,11 +3,6 @@ jdatetime jdatetime is Jalali_ implementation of Python's datetime module -Licence -------- -This pacakge is released under dual licenses, check LICENSE file for more information. - - Status ------ diff --git a/setup.py b/setup.py index 3cb8186..3c6c123 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ setup( name='jdatetime', - version='4.1.1', + version='5.0.0', packages=['jdatetime', ], license='Python Software Foundation License', keywords='Jalali implementation of Python datetime', From 18183f839e37e33fe13aecf65b16f5e507b2c94f Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Mon, 25 Mar 2024 14:08:03 +0100 Subject: [PATCH 3/7] Update jdatetime/__init__.py --- jdatetime/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/jdatetime/__init__.py b/jdatetime/__init__.py index eabd784..0eca79b 100644 --- a/jdatetime/__init__.py +++ b/jdatetime/__init__.py @@ -16,6 +16,7 @@ from jalali_core import GregorianToJalali, JalaliToGregorian, j_days_in_month + __VERSION__ = "4.1.1" MINYEAR = 1 MAXYEAR = 9377 From aff6823937062551ba690ea8701ec7bc78dcec93 Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Mon, 25 Mar 2024 14:17:37 +0100 Subject: [PATCH 4/7] Update jdatetime/__init__.py --- jdatetime/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/jdatetime/__init__.py b/jdatetime/__init__.py index 0eca79b..eabd784 100644 --- a/jdatetime/__init__.py +++ b/jdatetime/__init__.py @@ -16,7 +16,6 @@ from jalali_core import GregorianToJalali, JalaliToGregorian, j_days_in_month - __VERSION__ = "4.1.1" MINYEAR = 1 MAXYEAR = 9377 From e47185d4a01d94ae8ccafd15b8120615fddb1ddd Mon Sep 17 00:00:00 2001 From: Milad Date: Mon, 25 Mar 2024 14:28:04 +0100 Subject: [PATCH 5/7] update version --- jdatetime/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdatetime/__init__.py b/jdatetime/__init__.py index eabd784..2aa83f2 100644 --- a/jdatetime/__init__.py +++ b/jdatetime/__init__.py @@ -16,7 +16,7 @@ from jalali_core import GregorianToJalali, JalaliToGregorian, j_days_in_month -__VERSION__ = "4.1.1" +__VERSION__ = "5.0.0" MINYEAR = 1 MAXYEAR = 9377 From ea31e087ba2b5ec7a14370d915eb11495534bbd0 Mon Sep 17 00:00:00 2001 From: Milad Date: Mon, 25 Mar 2024 17:16:45 +0100 Subject: [PATCH 6/7] update CHANGELOG with version 5 release date --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 009e022..ee6c366 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## [5.0.0] - YYYY-MM-DD +## [5.0.0] - 2024-03-26 ### Add * Add support for Python 3.12 From 796d58812b89db5512ee818bfe9020487b952d19 Mon Sep 17 00:00:00 2001 From: Milad Date: Tue, 26 Mar 2024 10:39:13 +0100 Subject: [PATCH 7/7] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee6c366..87f1734 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ ### Changed * BREAKING CHANGE: Arithmetic operations on `date`/`datetime` against an unknown type will now return `NotImplemented` instead of raising `TypeError` * Drop Python 3.7 support -* Use jalali.py as jalali_core dependency #148 +* Move jalali.py to jalali_core dependency due to licensing issues #148 ### Fixed * treat %% as an escape sequence in strftime