Created
December 22, 2019 12:09
-
-
Save alizadeh118/c03467e452f0d0c122f8f8675363f402 to your computer and use it in GitHub Desktop.
تبدیل تاریخ هجری قمری به هجری شمسی / جلالی / خورشیدی
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// m: 1-12 | |
// d: 1-31 | |
const q2j = (y, m, d) => { | |
let result = (((y - 1) + (m - 1) / 12) * 354.3670 + d + 119) / 365.2422 | |
result = result.toString().split('.') | |
y = +result[0] + 1 | |
d = +(('0.' + result[1]) * 365.2422).toString().split('.')[0] | |
if (d > 186) { | |
d = d - 186 | |
m = parseInt(d / 30) + (d % 30 ? 7 : 6) | |
d = d % 30 || 30 | |
} else { | |
m = parseInt(d / 31) + +!!(d % 31) | |
d = d % 31 || 31 | |
} | |
return {y,m,d} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
هشدار: محاسبات این تابع خیلی دقیق نیست و صرفا برای تست پیاده سازی شده است