feat: add employee timing system, notification templates, and professor class plan sms
This commit is contained in:
@@ -100,6 +100,38 @@ const parseImportDate = (raw) => {
|
||||
return Number.isNaN(date.getTime()) ? null : date;
|
||||
};
|
||||
|
||||
const gregorianToJalali = (gy, gm, gd) => {
|
||||
const g_d_m = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
|
||||
let jy;
|
||||
if (gy > 1600) {
|
||||
jy = 979;
|
||||
gy -= 1600;
|
||||
} else {
|
||||
jy = 0;
|
||||
gy -= 621;
|
||||
}
|
||||
const gy2 = gm > 2 ? gy + 1 : gy;
|
||||
let days = 365 * gy + Math.floor((gy2 + 3) / 4) - Math.floor((gy2 + 99) / 100) + Math.floor((gy2 + 399) / 400) - 80 + gd + g_d_m[gm - 1];
|
||||
jy += 33 * Math.floor(days / 12053);
|
||||
days %= 12053;
|
||||
jy += 4 * Math.floor(days / 1461);
|
||||
days %= 1461;
|
||||
if (days > 365) {
|
||||
jy += Math.floor((days - 1) / 365);
|
||||
days = (days - 1) % 365;
|
||||
}
|
||||
const jm = days < 186 ? 1 + Math.floor(days / 31) : 7 + Math.floor((days - 186) / 30);
|
||||
const jd = 1 + (days < 186 ? days % 31 : (days - 186) % 30);
|
||||
return `${jy}/${String(jm).padStart(2, '0')}/${String(jd).padStart(2, '0')}`;
|
||||
};
|
||||
|
||||
const formatJalaliDate = (rawDate) => {
|
||||
if (!rawDate) return '';
|
||||
const date = rawDate instanceof Date ? rawDate : new Date(rawDate);
|
||||
if (Number.isNaN(date.getTime())) return '';
|
||||
return gregorianToJalali(date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate());
|
||||
};
|
||||
|
||||
const utcDayRange = (value) => {
|
||||
const date = parseImportDate(value);
|
||||
if (!date) return null;
|
||||
@@ -111,6 +143,8 @@ const utcDayRange = (value) => {
|
||||
module.exports = {
|
||||
toEnglishDigits,
|
||||
jalaliToGregorian,
|
||||
gregorianToJalali,
|
||||
formatJalaliDate,
|
||||
parseJalaliDate,
|
||||
parseImportDate,
|
||||
utcDayRange
|
||||
|
||||
Reference in New Issue
Block a user