38 #include "gnc-jalali.h"
47 int g_days_in_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
48 int j_days_in_month[12] = {31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29};
49 const char *j_month_name[12] =
51 "Farvardin",
"Ordibehesht",
"Khordad",
52 "Tir",
"Mordad",
"Shahrivar",
53 "Mehr",
"Aban",
"Azar",
54 "Dey",
"Bahman",
"Esfand"
57 int gnc_jalali_days_in_month(
int month_index)
59 g_assert(month_index < 12);
60 return j_days_in_month[month_index];
63 const char* gnc_jalali_month_name(
int month_index)
65 g_assert(month_index < 12);
66 return j_month_name[month_index];
69 void gnc_gregorian_to_jalali(
int *j_y,
int *j_m,
int *j_d,
70 int g_y,
int g_m,
int g_d)
74 long g_day_no, j_day_no;
83 g_day_no = 365 * gy + (gy + 3) / 4 - (gy + 99) / 100 + (gy + 399) / 400;
84 for (i = 0; i < gm; ++i)
85 g_day_no += g_days_in_month[i];
86 if (gm > 1 && ((gy % 4 == 0 && gy % 100 != 0) || (gy % 400 == 0)))
91 j_day_no = g_day_no - 79;
93 j_np = j_day_no / 12053;
96 jy = 979 + 33 * j_np + 4 * (j_day_no / 1461);
101 jy += (j_day_no - 1) / 365;
102 j_day_no = (j_day_no - 1) % 365;
105 for (i = 0; i < 11 && j_day_no >= j_days_in_month[i]; ++i)
107 j_day_no -= j_days_in_month[i];
116 void gnc_jalali_to_gregorian(
int *g_y,
int *g_m,
int *g_d,
117 int j_y,
int j_m,
int j_d)
121 long g_day_no, j_day_no;
130 j_day_no = 365 * jy + (jy / 33) * 8 + (jy % 33 + 3) / 4;
131 for (i = 0; i < jm; ++i)
132 j_day_no += j_days_in_month[i];
136 g_day_no = j_day_no + 79;
138 gy = 1600 + 400 * (g_day_no / 146097);
139 g_day_no = g_day_no % 146097;
142 if (g_day_no >= 36525)
145 gy += 100 * (g_day_no / 36524);
146 g_day_no = g_day_no % 36524;
154 gy += 4 * (g_day_no / 1461);
162 gy += g_day_no / 365;
163 g_day_no = g_day_no % 365;
166 for (i = 0; g_day_no >= g_days_in_month[i] + (i == 1 && leap); i++)
167 g_day_no -= g_days_in_month[i] + (i == 1 && leap);
187 gregorian_to_jalali(&y, &m, &d,
188 1900 + br_time.tm_year,
192 printf(
"Current Jalali date: %d %s %d\n", d, j_month_name[m-1], y);
struct tm * gnc_localtime_r(const time64 *secs, struct tm *time)
fill out a time struct from a 64-bit time value adjusted for the current time zone.
time64 gnc_time(time64 *tbuf)
get the current local time