feat: add TurkeyHolidayHelper to exclude official holidays from intern day calculations and logs
This commit is contained in:
@@ -466,7 +466,7 @@ class InternApplicationResource extends Resource
|
||||
|
||||
$days = 0;
|
||||
while ($startDate->lte($endDate)) {
|
||||
if (!$startDate->isWeekend()) {
|
||||
if (!$startDate->isWeekend() && !\App\Helpers\TurkeyHolidayHelper::isHoliday($startDate)) {
|
||||
$days++;
|
||||
}
|
||||
$startDate->addDay();
|
||||
@@ -489,7 +489,7 @@ class InternApplicationResource extends Resource
|
||||
$temp = $startDate->copy();
|
||||
|
||||
while ($count < $daysToAdd) {
|
||||
if ($temp->isWeekend()) {
|
||||
if ($temp->isWeekend() || \App\Helpers\TurkeyHolidayHelper::isHoliday($temp)) {
|
||||
$temp->addDay();
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
class TurkeyHolidayHelper
|
||||
{
|
||||
/**
|
||||
* Checks if a given date is a national or religious holiday in Turkey.
|
||||
*
|
||||
* @param string|Carbon $date
|
||||
* @return bool
|
||||
*/
|
||||
public static function isHoliday($date): bool
|
||||
{
|
||||
$carbonDate = Carbon::parse($date);
|
||||
$md = $carbonDate->format('m-d'); // Month-Day
|
||||
$ymd = $carbonDate->format('Y-m-d'); // Year-Month-Day
|
||||
|
||||
// 1. Fixed Yearly Holidays
|
||||
$fixedHolidays = [
|
||||
'01-01', // Yılbaşı (New Year's Day)
|
||||
'04-23', // Ulusal Egemenlik ve Çocuk Bayramı
|
||||
'05-01', // Emek ve Dayanışma Günü
|
||||
'05-19', // Atatürk'ü Anma, Gençlik ve Spor Bayramı
|
||||
'07-15', // Demokrasi ve Milli Birlik Günü
|
||||
'08-30', // Zafer Bayramı
|
||||
'10-29', // Cumhuriyet Bayramı
|
||||
];
|
||||
|
||||
if (in_array($md, $fixedHolidays)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 2. Variable Holidays (Ramazan & Kurban Bayramı including Eve/Arife days)
|
||||
// Hardcoded ranges for 2024 to 2030 based on Islamic lunar calendar projections.
|
||||
$variableHolidays = [
|
||||
// 2024
|
||||
'2024-04-09', // Ramazan Bayramı Arife
|
||||
'2024-04-10', '2024-04-11', '2024-04-12', // Ramazan Bayramı
|
||||
'2024-06-15', // Kurban Bayramı Arife
|
||||
'2024-06-16', '2024-06-17', '2024-06-18', '2024-06-19', // Kurban Bayramı
|
||||
|
||||
// 2025
|
||||
'2025-03-29', // Ramazan Bayramı Arife
|
||||
'2025-03-30', '2025-03-31', '2025-04-01', // Ramazan Bayramı
|
||||
'2025-06-05', // Kurban Bayramı Arife
|
||||
'2025-06-06', '2025-06-07', '2025-06-08', '2025-06-09', // Kurban Bayramı
|
||||
|
||||
// 2026
|
||||
'2026-03-19', // Ramazan Bayramı Arife
|
||||
'2026-03-20', '2026-03-21', '2026-03-22', // Ramazan Bayramı
|
||||
'2026-05-26', // Kurban Bayramı Arife
|
||||
'2026-05-27', '2026-05-28', '2026-05-29', '2026-05-30', // Kurban Bayramı
|
||||
|
||||
// 2027
|
||||
'2027-03-08', // Ramazan Bayramı Arife
|
||||
'2027-03-09', '2027-03-10', '2027-03-11', // Ramazan Bayramı
|
||||
'2027-05-15', // Kurban Bayramı Arife
|
||||
'2027-05-16', '2027-05-17', '2027-05-18', '2027-05-19', // Kurban Bayramı
|
||||
|
||||
// 2028
|
||||
'2028-02-26', // Ramazan Bayramı Arife
|
||||
'2028-02-27', '2028-02-28', '2028-02-29', // Ramazan Bayramı
|
||||
'2028-05-04', // Kurban Bayramı Arife
|
||||
'2028-05-05', '2028-05-06', '2028-05-07', '2028-05-08', // Kurban Bayramı
|
||||
|
||||
// 2029
|
||||
'2029-02-14', // Ramazan Bayramı Arife
|
||||
'2029-02-15', '2029-02-16', '2029-02-17', // Ramazan Bayramı
|
||||
'2029-04-23', // Kurban Bayramı Arife (Note: also April 23)
|
||||
'2029-04-24', '2029-04-25', '2029-04-26', '2029-04-27', // Kurban Bayramı
|
||||
|
||||
// 2030
|
||||
'2030-02-03', // Ramazan Bayramı Arife
|
||||
'2030-02-04', '2030-02-05', '2030-02-06', // Ramazan Bayramı
|
||||
'2030-04-12', // Kurban Bayramı Arife
|
||||
'2030-04-13', '2030-04-14', '2030-04-15', '2030-04-16', // Kurban Bayramı
|
||||
];
|
||||
|
||||
return in_array($ymd, $variableHolidays);
|
||||
}
|
||||
}
|
||||
@@ -177,7 +177,7 @@ class CareerController extends Controller
|
||||
$temp = $startDate->copy();
|
||||
|
||||
while ($count < $daysToAdd) {
|
||||
if ($temp->isWeekend()) {
|
||||
if ($temp->isWeekend() || \App\Helpers\TurkeyHolidayHelper::isHoliday($temp)) {
|
||||
$temp->addDay();
|
||||
continue;
|
||||
}
|
||||
@@ -464,7 +464,7 @@ class CareerController extends Controller
|
||||
$count = 0;
|
||||
|
||||
while ($count < $daysToAdd) {
|
||||
if ($temp->isWeekend()) {
|
||||
if ($temp->isWeekend() || \App\Helpers\TurkeyHolidayHelper::isHoliday($temp)) {
|
||||
$temp->addDay();
|
||||
continue;
|
||||
}
|
||||
@@ -501,9 +501,9 @@ class CareerController extends Controller
|
||||
return response()->json(['success' => false, 'message' => 'İleriye dönük staj günleri için defter doldurulamaz.'], 422);
|
||||
}
|
||||
|
||||
// 2. Prevent weekend entries
|
||||
if ($dateObj->isWeekend()) {
|
||||
return response()->json(['success' => false, 'message' => 'Hafta sonu günlerine staj günlüğü girilemez.'], 422);
|
||||
// 2. Prevent weekend and holiday entries
|
||||
if ($dateObj->isWeekend() || \App\Helpers\TurkeyHolidayHelper::isHoliday($dateObj)) {
|
||||
return response()->json(['success' => false, 'message' => 'Hafta sonu günlerine ve resmi tatillere staj günlüğü girilemez.'], 422);
|
||||
}
|
||||
|
||||
// 3. Determine if retroactive
|
||||
|
||||
@@ -1485,6 +1485,41 @@
|
||||
}
|
||||
}
|
||||
|
||||
function isTurkeyHoliday(dateObj) {
|
||||
const yyyy = dateObj.getFullYear();
|
||||
const mm = String(dateObj.getMonth() + 1).padStart(2, '0');
|
||||
const dd = String(dateObj.getDate()).padStart(2, '0');
|
||||
const ymd = `${yyyy}-${mm}-${dd}`;
|
||||
const md = `${mm}-${dd}`;
|
||||
|
||||
const fixedHolidays = [
|
||||
'01-01', '04-23', '05-01', '05-19', '07-15', '08-30', '10-29'
|
||||
];
|
||||
|
||||
if (fixedHolidays.includes(md)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const variableHolidays = [
|
||||
'2024-04-09', '2024-04-10', '2024-04-11', '2024-04-12',
|
||||
'2024-06-15', '2024-06-16', '2024-06-17', '2024-06-18', '2024-06-19',
|
||||
'2025-03-29', '2025-03-30', '2025-03-31', '2025-04-01',
|
||||
'2025-06-05', '2025-06-06', '2025-06-07', '2025-06-08', '2025-06-09',
|
||||
'2026-03-19', '2026-03-20', '2026-03-21', '2026-03-22',
|
||||
'2026-05-26', '2026-05-27', '2026-05-28', '2026-05-29', '2026-05-30',
|
||||
'2027-03-08', '2027-03-09', '2027-03-10', '2027-03-11',
|
||||
'2027-05-15', '2027-05-16', '2027-05-17', '2027-05-18', '2027-05-19',
|
||||
'2028-02-26', '2028-02-27', '2028-02-28', '2028-02-29',
|
||||
'2028-05-04', '2028-05-05', '2028-05-06', '2028-05-07', '2028-05-08',
|
||||
'2029-02-14', '2029-02-15', '2029-02-16', '2029-02-17',
|
||||
'2029-04-23', '2029-04-24', '2029-04-25', '2029-04-26', '2029-04-27',
|
||||
'2030-02-03', '2030-02-04', '2030-02-05', '2030-02-06',
|
||||
'2030-04-12', '2030-04-13', '2030-04-14', '2030-04-15', '2030-04-16'
|
||||
];
|
||||
|
||||
return variableHolidays.includes(ymd);
|
||||
}
|
||||
|
||||
function calculateEndDateFrontend() {
|
||||
const startDateVal = document.getElementById('internship_start_date').value;
|
||||
const totalDaysVal = document.getElementById('internship_total_days').value;
|
||||
@@ -1501,7 +1536,7 @@
|
||||
|
||||
while (count < daysToAdd) {
|
||||
const dayOfWeek = date.getDay();
|
||||
if (dayOfWeek === 6 || dayOfWeek === 0) { // 6 = Saturday, 0 = Sunday
|
||||
if (dayOfWeek === 6 || dayOfWeek === 0 || isTurkeyHoliday(date)) { // 6 = Saturday, 0 = Sunday
|
||||
date.setDate(date.getDate() + 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user