├── LICENSE
├── README.md
├── examples
├── test.cpp
└── test_OptimizedForRAM.cpp
└── src
├── converter.cpp
└── converter_OptimizedForRAM.cpp
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
166 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # jalaliDate-Cpp
2 |
3 | ## C++ , کتابخانهی تاریخ هجری شمسی (جلالی) برای زبان سی پلاس پلاس
4 |
5 |
6 | > منبع اصلی: https://jdf.scr.ir/jdf/
7 |
8 |
9 | ### برای سایر زبانهای برنامهنویسی:
10 |
11 | مـنـبـع | زبان | مخزن گیتهاب
12 | ---|---|---
13 | [📗 منبع](https://jdf.scr.ir/jdf/?t=c) | C | https://github.com/SCR-IR/jalaliDate-C.git
14 | [📗 منبع](https://jdf.scr.ir/jdf/?t=cpp) | C++ | https://github.com/SCR-IR/jalaliDate-Cpp.git
15 | [📗 منبع](https://jdf.scr.ir/jdf/?t=c_sharp) | C# | https://github.com/SCR-IR/jalaliDate-C_Sharp.git
16 | [📗 منبع](https://jdf.scr.ir/jdf/?t=dart) | Dart | https://github.com/SCR-IR/jalaliDate-Dart.git
17 | [📗 منبع](https://jdf.scr.ir/jdf/?t=go) | Go | https://github.com/SCR-IR/jalaliDate-Go.git
18 | [📗 منبع](https://jdf.scr.ir/jdf/?t=java) | Java | https://github.com/SCR-IR/jalaliDate-Java.git
19 | [📗 منبع](https://jdf.scr.ir/jdf/?t=java_script) | JavaScript | https://github.com/SCR-IR/jalaliDate-JavaScript.git
20 | [📗 منبع](https://jdf.scr.ir/jdf/?t=kotlin) | Kotlin | https://github.com/SCR-IR/jalaliDate-Kotlin.git
21 | [📗 منبع](https://jdf.scr.ir/jdf/?t=objective_c) | Objective_C | https://github.com/SCR-IR/jalaliDate-Objective_C.git
22 | [📗 منبع](https://jdf.scr.ir/jdf/?t=pascal) | Pascal | https://github.com/SCR-IR/jalaliDate-Pascal.git
23 | [📗 منبع](https://jdf.scr.ir/jdf/?t=perl) | Perl | https://github.com/SCR-IR/jalaliDate-Perl.git
24 | [📗 منبع](https://jdf.scr.ir/jdf/?t=php) | Php | https://github.com/SCR-IR/jalaliDate-Php.git
25 | [📗 منبع](https://jdf.scr.ir/jdf/?t=python) | Python | https://github.com/SCR-IR/jalaliDate-Python.git
26 | [📗 منبع](https://jdf.scr.ir/jdf/?t=r) | R | https://github.com/SCR-IR/jalaliDate-R.git
27 | [📗 منبع](https://jdf.scr.ir/jdf/?t=ruby) | Ruby | https://github.com/SCR-IR/jalaliDate-Ruby.git
28 | [📗 منبع](https://jdf.scr.ir/jdf/?t=swift) | Swift | https://github.com/SCR-IR/jalaliDate-Swift.git
29 | [📗 منبع](https://jdf.scr.ir/jdf/?t=visual_basic) | VisualBasic6 | https://github.com/SCR-IR/jalaliDate-VisualBasic.git
--------------------------------------------------------------------------------
/examples/test.cpp:
--------------------------------------------------------------------------------
1 |
2 |
3 | // #include
4 | #include
5 | using namespace std;
6 |
7 | /** Gregorian & Jalali (Hijri_Shamsi,Solar) Date Converter Functions
8 | Author: JDF.SCR.IR =>> Download Full Version : http://jdf.scr.ir/jdf
9 | License: GNU/LGPL _ Open Source & Free :: Version: 2.80 : [2020=1399]
10 | ---------------------------------------------------------------------
11 | 355746=361590-5844 & 361590=(30*33*365)+(30*8) & 5844=(16*365)+(16/4)
12 | 355666=355746-79-1 & 355668=355746-79+1 & 1595=605+990 & 605=621-16
13 | 990=30*33 & 12053=(365*33)+(32/4) & 36524=(365*100)+(100/4)-(100/100)
14 | 1461=(365*4)+(4/4) & 146097=(365*400)+(400/4)-(400/100)+(400/400) */
15 |
16 | long *gregorian_to_jalali(long gy, long gm, long gd, long out[]) {
17 | long days;
18 | {
19 | long gy2 = (gm > 2) ? (gy + 1) : gy;
20 | long g_d_m[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
21 | days = 355666 + (365 * gy) + ((int)((gy2 + 3) / 4)) - ((int)((gy2 + 99) / 100)) + ((int)((gy2 + 399) / 400)) + gd + g_d_m[gm - 1];
22 | }
23 | long jy = -1595 + (33 * ((int)(days / 12053)));
24 | days %= 12053;
25 | jy += 4 * ((int)(days / 1461));
26 | days %= 1461;
27 | if (days > 365) {
28 | jy += (int)((days - 1) / 365);
29 | days = (days - 1) % 365;
30 | }
31 | out[0] = jy;
32 | if (days < 186) {
33 | out[1]/*jm*/ = 1 + (int)(days / 31);
34 | out[2]/*jd*/ = 1 + (days % 31);
35 | } else {
36 | out[1]/*jm*/ = 7 + (int)((days - 186) / 30);
37 | out[2]/*jd*/ = 1 + ((days - 186) % 30);
38 | }
39 | return out;
40 | }
41 |
42 | long *jalali_to_gregorian(long jy, long jm, long jd, long out[]) {
43 | jy += 1595;
44 | long days = -355668 + (365 * jy) + (((int)(jy / 33)) * 8) + ((int)(((jy % 33) + 3) / 4)) + jd + ((jm < 7) ? (jm - 1) * 31 : ((jm - 7) * 30) + 186);
45 | long gy = 400 * ((int)(days / 146097));
46 | days %= 146097;
47 | if (days > 36524) {
48 | gy += 100 * ((int)(--days / 36524));
49 | days %= 36524;
50 | if (days >= 365) days++;
51 | }
52 | gy += 4 * ((int)(days / 1461));
53 | days %= 1461;
54 | if (days > 365) {
55 | gy += (int)((days - 1) / 365);
56 | days = (days - 1) % 365;
57 | }
58 | long gd = days + 1;
59 | long gm;
60 | {
61 | long sal_a[13] = {0, 31, ((gy % 4 == 0 && gy % 100 != 0) || (gy % 400 == 0)) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
62 | for (gm = 0; gm < 13 && gd > sal_a[gm]; gm++) gd -= sal_a[gm];
63 | }
64 | out[0] = gy;
65 | out[1] = gm;
66 | out[2] = gd;
67 | return out;
68 | }
69 |
70 |
71 |
72 | //Example1:
73 | int main() {
74 | long y_in, m_in, d_in, ymd_out[3];
75 | char tabdil;
76 |
77 | while (1) {
78 | cout << "----------------------------------\n\nif gregorian_to_jalali -> press: g\nor jalali_to_gregorian -> press: j\nand finish -> press: e\n";
79 | cin >> tabdil;
80 | if (tabdil == 'e') break; //exit
81 |
82 | cout << "enter Day: ";
83 | cin >> d_in;
84 | cout << "enter Month: ";
85 | cin >> m_in;
86 | cout << "enter Year: ";
87 | cin >> y_in;
88 |
89 | if (tabdil == 'g') {
90 | cout << "----------------------------------\n gregorian: " << y_in << "-" << m_in << "-" << d_in << "\n";
91 | gregorian_to_jalali(y_in, m_in, d_in, ymd_out);
92 | cout << "jalali: " << ymd_out[0] << "/" << ymd_out[1] << "/" << ymd_out[2] << "\n";
93 | } else {
94 | cout << "----------------------------------\n jalali: " << y_in << "/" << m_in << "/" << d_in << "\n";
95 | jalali_to_gregorian(y_in, m_in, d_in, ymd_out);
96 | cout << "gregorian: " << ymd_out[0] << "/" << ymd_out[1] << "/" << ymd_out[2] << "\n";
97 | }
98 | }
99 |
100 | return 0;
101 | }
102 |
103 |
104 |
105 | /*
106 | //Example2:
107 | int main() {
108 |
109 | long tarikh_j[3];
110 | gregorian_to_jalali(2020,5,17,tarikh_j);
111 | int jy=tarikh_j[0];
112 | int jm=tarikh_j[1];
113 | int jd=tarikh_j[2];
114 | cout << jy << "/" << jm << "/" << jd << "\n";
115 |
116 | //long* tarikh_j2=gregorian_to_jalali(2020,5,17,tarikh_j);
117 |
118 |
119 | long tarikh_g[3];
120 | jalali_to_gregorian(1399,2,28,tarikh_g);
121 | int gy=tarikh_g[0];
122 | int gm=tarikh_g[1];
123 | int gd=tarikh_g[2];
124 | cout << gy << "/" << gm << "/" << gd << "\n";
125 |
126 | //long* tarikh_g2=jalali_to_gregorian(1399,2,28,tarikh_g);
127 |
128 | return 0;
129 | }
130 | */
131 |
132 |
133 |
134 |
--------------------------------------------------------------------------------
/examples/test_OptimizedForRAM.cpp:
--------------------------------------------------------------------------------
1 |
2 |
3 | // #include
4 | #include
5 | using namespace std;
6 |
7 | /** Gregorian & Jalali (Hijri_Shamsi,Solar) Date Converter Functions
8 | Author: JDF.SCR.IR =>> Download Full Version : http://jdf.scr.ir/jdf
9 | License: GNU/LGPL _ Open Source & Free :: Version: 2.80 : [2020=1399]
10 | ---------------------------------------------------------------------
11 | 355746=361590-5844 & 361590=(30*33*365)+(30*8) & 5844=(16*365)+(16/4)
12 | 355666=355746-79-1 & 355668=355746-79+1 & 1595=605+990 & 605=621-16
13 | 990=30*33 & 12053=(365*33)+(32/4) & 36524=(365*100)+(100/4)-(100/100)
14 | 1461=(365*4)+(4/4) & 146097=(365*400)+(400/4)-(400/100)+(400/400) */
15 |
16 | long *gregorian_to_jalali(long gy, long gm, long gd, long out[]) {
17 | out[0] = (gm > 2) ? (gy + 1) : gy;
18 | {
19 | long g_d_m[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
20 | out[3] = 355666 + (365 * gy) + ((int)((out[0] + 3) / 4)) - ((int)((out[0] + 99) / 100)) + ((int)((out[0] + 399) / 400)) + gd + g_d_m[gm - 1];
21 | }
22 | out[0] = -1595 + (33 * ((int)(out[3] / 12053)));
23 | out[3] %= 12053;
24 | out[0] += 4 * ((int)(out[3] / 1461));
25 | out[3] %= 1461;
26 | if (out[3] > 365) {
27 | out[0] += (int)((out[3] - 1) / 365);
28 | out[3] = (out[3] - 1) % 365;
29 | }
30 | if (out[3] < 186) {
31 | out[1]/*jm*/ = 1 + (int)(out[3] / 31);
32 | out[2]/*jd*/ = 1 + (out[3] % 31);
33 | } else {
34 | out[1]/*jm*/ = 7 + (int)((out[3] - 186) / 30);
35 | out[2]/*jd*/ = 1 + ((out[3] - 186) % 30);
36 | }
37 | return out;
38 | }
39 |
40 | long *jalali_to_gregorian(long jy, long jm, long jd, long out[]) {
41 | jy += 1595;
42 | out[2] = -355668 + (365 * jy) + (((int)(jy / 33)) * 8) + ((int)(((jy % 33) + 3) / 4)) + jd + ((jm < 7) ? (jm - 1) * 31 : ((jm - 7) * 30) + 186);
43 | out[0] = 400 * ((int)(out[2] / 146097));
44 | out[2] %= 146097;
45 | if (out[2] > 36524) {
46 | out[0] += 100 * ((int)(--out[2] / 36524));
47 | out[2] %= 36524;
48 | if (out[2] >= 365) out[2]++;
49 | }
50 | out[0] += 4 * ((int)(out[2] / 1461));
51 | out[2] %= 1461;
52 | if (out[2] > 365) {
53 | out[0] += (int)((out[2] - 1) / 365);
54 | out[2] = (out[2] - 1) % 365;
55 | }
56 | long sal_a[13] = {0, 31, ((out[0]%4 == 0 && out[0]%100 != 0) || (out[0]%400 == 0))?29:28 , 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
57 | for (out[2]++, out[1] = 0; out[1] < 13 && out[2] > sal_a[out[1]]; out[1]++) out[2] -= sal_a[out[1]];
58 | return out;
59 | }
60 |
61 |
62 |
63 | //Example1:
64 | int main() {
65 | long y_in, m_in, d_in, ymd_out[3];
66 | char tabdil;
67 |
68 | while (1) {
69 | cout << "----------------------------------\n\nif gregorian_to_jalali -> press: g\nor jalali_to_gregorian -> press: j\nand finish -> press: e\n";
70 | cin >> tabdil;
71 | if (tabdil == 'e') break; //exit
72 |
73 | cout << "enter Day: ";
74 | cin >> d_in;
75 | cout << "enter Month: ";
76 | cin >> m_in;
77 | cout << "enter Year: ";
78 | cin >> y_in;
79 |
80 | if (tabdil == 'g') {
81 | cout << "----------------------------------\n gregorian: " << y_in << "-" << m_in << "-" << d_in << "\n";
82 | gregorian_to_jalali(y_in, m_in, d_in, ymd_out);
83 | cout << "jalali: " << ymd_out[0] << "/" << ymd_out[1] << "/" << ymd_out[2] << "\n";
84 | } else {
85 | cout << "----------------------------------\n jalali: " << y_in << "/" << m_in << "/" << d_in << "\n";
86 | jalali_to_gregorian(y_in, m_in, d_in, ymd_out);
87 | cout << "gregorian: " << ymd_out[0] << "/" << ymd_out[1] << "/" << ymd_out[2] << "\n";
88 | }
89 | }
90 |
91 | return 0;
92 | }
93 |
94 |
95 |
96 | /*
97 | //Example2:
98 | int main() {
99 |
100 | long tarikh_j[3];
101 | gregorian_to_jalali(2020,5,17,tarikh_j);
102 | int jy=tarikh_j[0];
103 | int jm=tarikh_j[1];
104 | int jd=tarikh_j[2];
105 | cout << jy << "/" << jm << "/" << jd << "\n";
106 |
107 | //long* tarikh_j2=gregorian_to_jalali(2020,5,17,tarikh_j);
108 |
109 |
110 | long tarikh_g[3];
111 | jalali_to_gregorian(1399,2,28,tarikh_g);
112 | int gy=tarikh_g[0];
113 | int gm=tarikh_g[1];
114 | int gd=tarikh_g[2];
115 | cout << gy << "/" << gm << "/" << gd << "\n";
116 |
117 | //long* tarikh_g2=jalali_to_gregorian(1399,2,28,tarikh_g);
118 |
119 | return 0;
120 | }
121 | */
122 |
123 |
124 |
125 |
--------------------------------------------------------------------------------
/src/converter.cpp:
--------------------------------------------------------------------------------
1 |
2 |
3 | /** Gregorian & Jalali (Hijri_Shamsi,Solar) Date Converter Functions
4 | Author: JDF.SCR.IR =>> Download Full Version : http://jdf.scr.ir/jdf
5 | License: GNU/LGPL _ Open Source & Free :: Version: 2.80 : [2020=1399]
6 | ---------------------------------------------------------------------
7 | 355746=361590-5844 & 361590=(30*33*365)+(30*8) & 5844=(16*365)+(16/4)
8 | 355666=355746-79-1 & 355668=355746-79+1 & 1595=605+990 & 605=621-16
9 | 990=30*33 & 12053=(365*33)+(32/4) & 36524=(365*100)+(100/4)-(100/100)
10 | 1461=(365*4)+(4/4) & 146097=(365*400)+(400/4)-(400/100)+(400/400) */
11 |
12 | long *gregorian_to_jalali(long gy, long gm, long gd, long out[]) {
13 | long days;
14 | {
15 | long gy2 = (gm > 2) ? (gy + 1) : gy;
16 | long g_d_m[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
17 | days = 355666 + (365 * gy) + ((int)((gy2 + 3) / 4)) - ((int)((gy2 + 99) / 100)) + ((int)((gy2 + 399) / 400)) + gd + g_d_m[gm - 1];
18 | }
19 | long jy = -1595 + (33 * ((int)(days / 12053)));
20 | days %= 12053;
21 | jy += 4 * ((int)(days / 1461));
22 | days %= 1461;
23 | if (days > 365) {
24 | jy += (int)((days - 1) / 365);
25 | days = (days - 1) % 365;
26 | }
27 | out[0] = jy;
28 | if (days < 186) {
29 | out[1]/*jm*/ = 1 + (int)(days / 31);
30 | out[2]/*jd*/ = 1 + (days % 31);
31 | } else {
32 | out[1]/*jm*/ = 7 + (int)((days - 186) / 30);
33 | out[2]/*jd*/ = 1 + ((days - 186) % 30);
34 | }
35 | return out;
36 | }
37 |
38 | long *jalali_to_gregorian(long jy, long jm, long jd, long out[]) {
39 | jy += 1595;
40 | long days = -355668 + (365 * jy) + (((int)(jy / 33)) * 8) + ((int)(((jy % 33) + 3) / 4)) + jd + ((jm < 7) ? (jm - 1) * 31 : ((jm - 7) * 30) + 186);
41 | long gy = 400 * ((int)(days / 146097));
42 | days %= 146097;
43 | if (days > 36524) {
44 | gy += 100 * ((int)(--days / 36524));
45 | days %= 36524;
46 | if (days >= 365) days++;
47 | }
48 | gy += 4 * ((int)(days / 1461));
49 | days %= 1461;
50 | if (days > 365) {
51 | gy += (int)((days - 1) / 365);
52 | days = (days - 1) % 365;
53 | }
54 | long gd = days + 1;
55 | long gm;
56 | {
57 | long sal_a[13] = {0, 31, ((gy % 4 == 0 && gy % 100 != 0) || (gy % 400 == 0)) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
58 | for (gm = 0; gm < 13 && gd > sal_a[gm]; gm++) gd -= sal_a[gm];
59 | }
60 | out[0] = gy;
61 | out[1] = gm;
62 | out[2] = gd;
63 | return out;
64 | }
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/src/converter_OptimizedForRAM.cpp:
--------------------------------------------------------------------------------
1 |
2 |
3 | /** Gregorian & Jalali (Hijri_Shamsi,Solar) Date Converter Functions
4 | Author: JDF.SCR.IR =>> Download Full Version : http://jdf.scr.ir/jdf
5 | License: GNU/LGPL _ Open Source & Free :: Version: 2.80 : [2020=1399]
6 | ---------------------------------------------------------------------
7 | 355746=361590-5844 & 361590=(30*33*365)+(30*8) & 5844=(16*365)+(16/4)
8 | 355666=355746-79-1 & 355668=355746-79+1 & 1595=605+990 & 605=621-16
9 | 990=30*33 & 12053=(365*33)+(32/4) & 36524=(365*100)+(100/4)-(100/100)
10 | 1461=(365*4)+(4/4) & 146097=(365*400)+(400/4)-(400/100)+(400/400) */
11 |
12 | long *gregorian_to_jalali(long gy, long gm, long gd, long out[]) {
13 | out[0] = (gm > 2) ? (gy + 1) : gy;
14 | {
15 | long g_d_m[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
16 | out[3] = 355666 + (365 * gy) + ((int)((out[0] + 3) / 4)) - ((int)((out[0] + 99) / 100)) + ((int)((out[0] + 399) / 400)) + gd + g_d_m[gm - 1];
17 | }
18 | out[0] = -1595 + (33 * ((int)(out[3] / 12053)));
19 | out[3] %= 12053;
20 | out[0] += 4 * ((int)(out[3] / 1461));
21 | out[3] %= 1461;
22 | if (out[3] > 365) {
23 | out[0] += (int)((out[3] - 1) / 365);
24 | out[3] = (out[3] - 1) % 365;
25 | }
26 | if (out[3] < 186) {
27 | out[1]/*jm*/ = 1 + (int)(out[3] / 31);
28 | out[2]/*jd*/ = 1 + (out[3] % 31);
29 | } else {
30 | out[1]/*jm*/ = 7 + (int)((out[3] - 186) / 30);
31 | out[2]/*jd*/ = 1 + ((out[3] - 186) % 30);
32 | }
33 | return out;
34 | }
35 |
36 | long *jalali_to_gregorian(long jy, long jm, long jd, long out[]) {
37 | jy += 1595;
38 | out[2] = -355668 + (365 * jy) + (((int)(jy / 33)) * 8) + ((int)(((jy % 33) + 3) / 4)) + jd + ((jm < 7) ? (jm - 1) * 31 : ((jm - 7) * 30) + 186);
39 | out[0] = 400 * ((int)(out[2] / 146097));
40 | out[2] %= 146097;
41 | if (out[2] > 36524) {
42 | out[0] += 100 * ((int)(--out[2] / 36524));
43 | out[2] %= 36524;
44 | if (out[2] >= 365) out[2]++;
45 | }
46 | out[0] += 4 * ((int)(out[2] / 1461));
47 | out[2] %= 1461;
48 | if (out[2] > 365) {
49 | out[0] += (int)((out[2] - 1) / 365);
50 | out[2] = (out[2] - 1) % 365;
51 | }
52 | long sal_a[13] = {0, 31, ((out[0]%4 == 0 && out[0]%100 != 0) || (out[0]%400 == 0))?29:28 , 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
53 | for (out[2]++, out[1] = 0; out[1] < 13 && out[2] > sal_a[out[1]]; out[1]++) out[2] -= sal_a[out[1]];
54 | return out;
55 | }
56 |
57 |
--------------------------------------------------------------------------------