jalali-core 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- jalali_core-1.0.0/LICENSE +19 -0
- jalali_core-1.0.0/PKG-INFO +20 -0
- jalali_core-1.0.0/README.rst +0 -0
- jalali_core-1.0.0/jalali_core/__init__.py +129 -0
- jalali_core-1.0.0/jalali_core.egg-info/PKG-INFO +20 -0
- jalali_core-1.0.0/jalali_core.egg-info/SOURCES.txt +8 -0
- jalali_core-1.0.0/jalali_core.egg-info/dependency_links.txt +1 -0
- jalali_core-1.0.0/jalali_core.egg-info/top_level.txt +1 -0
- jalali_core-1.0.0/setup.cfg +4 -0
- jalali_core-1.0.0/setup.py +27 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# The algorithms to convert between Jalali and Gregorian dates, are based on
|
|
2
|
+
# FarsiWeb's jalali.c library (http://www.farsiweb.info/jalali/jalali.c).
|
|
3
|
+
#
|
|
4
|
+
# Copyright (C) 2001 Roozbeh Pournader <roozbeh@sharif.edu>
|
|
5
|
+
# Copyright (C) 2001 Mohammad Toossi <mohammad@bamdad.org>
|
|
6
|
+
# Copyright (C) 2003-2011 Parspooyesh Fanavar (http://parspooyesh.com/)
|
|
7
|
+
#
|
|
8
|
+
# This program is free software; you can redistribute it and/or
|
|
9
|
+
# modify it under the terms of the GNU Lesser General Public
|
|
10
|
+
# License as published by the Free Software Foundation; either
|
|
11
|
+
# version 2.1 of the License, or (at your option) any later version.
|
|
12
|
+
#
|
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
16
|
+
# Lesser General Public License for more details.
|
|
17
|
+
#
|
|
18
|
+
# You can receive a copy of GNU Lesser General Public License at the
|
|
19
|
+
# World Wide Web address <http://www.gnu.org/licenses/lgpl.html>.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: jalali_core
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: a Gregorian to Jalali and inverse date convertor
|
|
5
|
+
Home-page: https://github.com/slashmili/jalali-core
|
|
6
|
+
Author: Milad Rastian
|
|
7
|
+
Author-email: eslashmili@gmail.com
|
|
8
|
+
License: LGPL
|
|
9
|
+
Platform: any
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Intended Audience :: System Administrators
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Requires-Python: >=3.8
|
|
20
|
+
License-File: LICENSE
|
|
File without changes
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# The algorithms to convert between Jalali and Gregorian dates, are based on
|
|
2
|
+
# FarsiWeb's jalali.c library (http://www.farsiweb.info/jalali/jalali.c).
|
|
3
|
+
#
|
|
4
|
+
# Copyright (C) 2001 Roozbeh Pournader <roozbeh@sharif.edu>
|
|
5
|
+
# Copyright (C) 2001 Mohammad Toossi <mohammad@bamdad.org>
|
|
6
|
+
# Copyright (C) 2003-2011 Parspooyesh Fanavar (http://parspooyesh.com/)
|
|
7
|
+
#
|
|
8
|
+
# This program is free software; you can redistribute it and/or
|
|
9
|
+
# modify it under the terms of the GNU Lesser General Public
|
|
10
|
+
# License as published by the Free Software Foundation; either
|
|
11
|
+
# version 2.1 of the License, or (at your option) any later version.
|
|
12
|
+
#
|
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
16
|
+
# Lesser General Public License for more details.
|
|
17
|
+
#
|
|
18
|
+
# You can receive a copy of GNU Lesser General Public License at the
|
|
19
|
+
# World Wide Web address <http://www.gnu.org/licenses/lgpl.html>.
|
|
20
|
+
|
|
21
|
+
g_days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
|
22
|
+
j_days_in_month = [31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class GregorianToJalali:
|
|
26
|
+
def __init__(self, gyear, gmonth, gday):
|
|
27
|
+
"""
|
|
28
|
+
Convert gregorian date to jalali date
|
|
29
|
+
gmonth: number of month in range 1-12
|
|
30
|
+
"""
|
|
31
|
+
self.gyear = gyear
|
|
32
|
+
self.gmonth = gmonth
|
|
33
|
+
self.gday = gday
|
|
34
|
+
self.__gregorianToJalali()
|
|
35
|
+
|
|
36
|
+
def getJalaliList(self):
|
|
37
|
+
return (self.jyear, self.jmonth, self.jday)
|
|
38
|
+
|
|
39
|
+
def __gregorianToJalali(self):
|
|
40
|
+
"""
|
|
41
|
+
g_y: gregorian year
|
|
42
|
+
g_m: gregorian month
|
|
43
|
+
g_d: gregorian day
|
|
44
|
+
"""
|
|
45
|
+
gy = self.gyear - 1600
|
|
46
|
+
gm = self.gmonth - 1
|
|
47
|
+
|
|
48
|
+
j_day_no = (
|
|
49
|
+
365 * gy + (gy + 3) // 4 - (gy + 99) // 100
|
|
50
|
+
+ (gy + 399) // 400 + self.gday - 1 - 79
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
for i in range(gm):
|
|
54
|
+
j_day_no += g_days_in_month[i]
|
|
55
|
+
if gm > 1 and ((gy % 4 == 0 and gy % 100 != 0) or (gy % 400 == 0)):
|
|
56
|
+
# leap and after Feb
|
|
57
|
+
j_day_no += 1
|
|
58
|
+
|
|
59
|
+
j_np = j_day_no // 12053
|
|
60
|
+
j_day_no %= 12053
|
|
61
|
+
jy = 979 + 33 * j_np + 4 * (j_day_no // 1461)
|
|
62
|
+
|
|
63
|
+
j_day_no %= 1461
|
|
64
|
+
|
|
65
|
+
if j_day_no >= 366:
|
|
66
|
+
j_day_no -= 1
|
|
67
|
+
jy += j_day_no // 365
|
|
68
|
+
j_day_no %= 365
|
|
69
|
+
|
|
70
|
+
for i in range(11):
|
|
71
|
+
if not j_day_no >= j_days_in_month[i]:
|
|
72
|
+
i -= 1
|
|
73
|
+
break
|
|
74
|
+
j_day_no -= j_days_in_month[i]
|
|
75
|
+
|
|
76
|
+
self.jyear = jy
|
|
77
|
+
self.jmonth = i + 2
|
|
78
|
+
self.jday = j_day_no + 1
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class JalaliToGregorian:
|
|
82
|
+
def __init__(self, jyear, jmonth, jday):
|
|
83
|
+
"""
|
|
84
|
+
Convert db time stamp (in gregorian date) to jalali date
|
|
85
|
+
"""
|
|
86
|
+
self.jyear = jyear
|
|
87
|
+
self.jmonth = jmonth
|
|
88
|
+
self.jday = jday
|
|
89
|
+
self.__jalaliToGregorian()
|
|
90
|
+
|
|
91
|
+
def getGregorianList(self):
|
|
92
|
+
return (self.gyear, self.gmonth, self.gday)
|
|
93
|
+
|
|
94
|
+
def __jalaliToGregorian(self):
|
|
95
|
+
jy = self.jyear - 979
|
|
96
|
+
g_day_no = 365 * jy + (jy // 33) * 8 + (jy % 33 + 3) // 4 + self.jday - 1 + 79
|
|
97
|
+
for i in range(self.jmonth - 1):
|
|
98
|
+
g_day_no += j_days_in_month[i]
|
|
99
|
+
|
|
100
|
+
gy = 1600 + 400 * (g_day_no // 146097) # 146097 = 365*400 + 400/4 - 400/100 + 400/400
|
|
101
|
+
g_day_no %= 146097
|
|
102
|
+
|
|
103
|
+
leap = 1
|
|
104
|
+
if g_day_no >= 36525: # 36525 = 365*100 + 100/4
|
|
105
|
+
g_day_no -= 1
|
|
106
|
+
gy += 100 * (g_day_no // 36524) # 36524 = 365*100 + 100/4 - 100/100
|
|
107
|
+
g_day_no %= 36524
|
|
108
|
+
|
|
109
|
+
if g_day_no >= 365:
|
|
110
|
+
g_day_no += 1
|
|
111
|
+
else:
|
|
112
|
+
leap = 0
|
|
113
|
+
|
|
114
|
+
gy += 4 * (g_day_no // 1461) # 1461 = 365*4 + 4/4
|
|
115
|
+
g_day_no %= 1461
|
|
116
|
+
|
|
117
|
+
if g_day_no >= 366:
|
|
118
|
+
leap = 0
|
|
119
|
+
g_day_no -= 1
|
|
120
|
+
gy += g_day_no // 365
|
|
121
|
+
g_day_no %= 365
|
|
122
|
+
|
|
123
|
+
i = 0
|
|
124
|
+
while g_day_no >= g_days_in_month[i] + (i == 1 and leap):
|
|
125
|
+
g_day_no -= g_days_in_month[i] + (i == 1 and leap)
|
|
126
|
+
i += 1
|
|
127
|
+
self.gmonth = i + 1
|
|
128
|
+
self.gday = g_day_no + 1
|
|
129
|
+
self.gyear = gy
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: jalali_core
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: a Gregorian to Jalali and inverse date convertor
|
|
5
|
+
Home-page: https://github.com/slashmili/jalali-core
|
|
6
|
+
Author: Milad Rastian
|
|
7
|
+
Author-email: eslashmili@gmail.com
|
|
8
|
+
License: LGPL
|
|
9
|
+
Platform: any
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Intended Audience :: System Administrators
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Requires-Python: >=3.8
|
|
20
|
+
License-File: LICENSE
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
jalali_core
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from distutils.core import setup
|
|
2
|
+
|
|
3
|
+
import setuptools
|
|
4
|
+
|
|
5
|
+
setup(
|
|
6
|
+
name='jalali_core',
|
|
7
|
+
version='1.0.0',
|
|
8
|
+
packages=['jalali_core', ],
|
|
9
|
+
license='LGPL',
|
|
10
|
+
platforms='any',
|
|
11
|
+
author='Milad Rastian',
|
|
12
|
+
author_email='eslashmili@gmail.com',
|
|
13
|
+
description=("a Gregorian to Jalali and inverse date convertor"),
|
|
14
|
+
url="https://github.com/slashmili/jalali-core",
|
|
15
|
+
python_requires=">=3.8",
|
|
16
|
+
classifiers=[
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Intended Audience :: System Administrators",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python",
|
|
21
|
+
"Programming Language :: Python :: 3.8",
|
|
22
|
+
"Programming Language :: Python :: 3.9",
|
|
23
|
+
"Programming Language :: Python :: 3.10",
|
|
24
|
+
"Programming Language :: Python :: 3.11",
|
|
25
|
+
"Programming Language :: Python :: 3.12",
|
|
26
|
+
],
|
|
27
|
+
)
|