diff --git a/src/Calendars/IndianCalender.php b/src/Calendars/IndianCalender.php new file mode 100644 index 000000000..04da97b51 --- /dev/null +++ b/src/Calendars/IndianCalender.php @@ -0,0 +1,132 @@ + */ + protected function ashura(int $year, int $totalDays = 1): array + { + return $this->getMultiDayHoliday(self::ashura, $year, $totalDays); + } + + /** @return array */ + protected function miladHolidays(int $year, int $totalDays = 1): array + { + return $this->getMultiDayHoliday(self::miladHolidays, $year, $totalDays); + } + + /** @return array */ + protected function bakridHolidays(int $year, int $totalDays = 1): array + { + return $this->getMultiDayHoliday(self::bakridHolidays, $year, $totalDays); + } + + /** @return array */ + protected function ramzanIdHolidays(int $year, int $totalDays = 1): array + { + return $this->getMultiDayHoliday(self::ramzanIdHolidays, $year, $totalDays); + } + + /** @param array $collection */ + protected function getSingleDayHoliday(array $collection, int $year): CarbonImmutable + { + $date = $collection[$year] ?? null; + + if ($date === null) { + throw InvalidYear::range($this->countryCode(), 1970, 2037); + } + + $date = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")?->startOfDay(); + + if ($date === null) { + throw new InvalidFormatException('Invalid date for holiday'); + } + + return $date; + } + + /** + * @param array> $collection + * @return array + */ + protected function getMultiDayHoliday(array $collection, int $year, int $totalDays): array + { + $date = $collection[$year] ?? null; + + if ($date === null) { + throw InvalidYear::range($this->countryCode(), 1970, 2037); + } + + $overlap = $this->getOverlapping($collection, $year, $totalDays); + + if ($overlap) { + $period = $this->createPeriod($overlap, $year - 1, $totalDays); + + $date = [$period, $date]; + } + + if (! is_array($date)) { + return [$this->createPeriod($date, $year, $totalDays)]; + } + + // Twice a year + $periods = []; + $dates = $date; + + /** @var CarbonPeriod|string $date */ + foreach ($dates as $date) { + if ($date instanceof CarbonPeriod) { + $periods[] = $date; + + continue; + } + + $periods[] = $this->createPeriod($date, $year, $totalDays); + } + + return $periods; + } + + protected function createPeriod(string $date, int $year, int $totalDays): CarbonPeriod + { + $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")?->startOfDay(); + $end = $start->addDays($totalDays - 1)->startOfDay(); + + return CarbonPeriod::create($start, '1 day', $end); + } + + /** @param array> $collection */ + protected function getOverlapping(array $collection, int $year, int $totalDays): ?string + { + if ($year === 1970) { + return null; + } + + $date = $collection[$year - 1] ?? null; + + if ($date === null) { + throw InvalidYear::range($this->countryCode(), 1970, 2037); + } + + if (is_array($date)) { + $date = end($date); + } + + $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")?->startOfDay(); + $end = $start->addDays($totalDays - 1)->startOfDay(); + + if ($end->year !== $year) { + return (string) $date; + } + + return null; + } +} diff --git a/src/Countries/India.php b/src/Countries/India.php new file mode 100644 index 000000000..9b82f7491 --- /dev/null +++ b/src/Countries/India.php @@ -0,0 +1,1171 @@ + '03-23', + 1971 => '03-12', + 1972 => '02-29', + 1973 => '03-19', + 1974 => '03-08', + 1975 => '03-27', + 1976 => '03-16', + 1977 => '03-06', + 1978 => '03-25', + 1979 => '03-14', + 1980 => '03-02', + 1981 => '03-21', + 1982 => '03-10', + 1983 => '03-29', + 1984 => '03-17', + 1985 => '03-07', + 1986 => '03-26', + 1987 => '03-16', + 1988 => '03-04', + 1989 => '03-22', + 1990 => '03-11', + 1991 => '03-01', + 1992 => '03-19', + 1993 => '03-08', + 1994 => '03-27', + 1995 => '03-17', + 1996 => '03-05', + 1997 => '03-24', + 1998 => '03-13', + 1999 => '03-02', + 2000 => '03-20', + 2001 => '03-10', + 2002 => '03-29', + 2003 => '03-18', + 2004 => '03-07', + 2005 => '03-26', + 2006 => '03-15', + 2007 => '03-04', + 2008 => '03-22', + 2009 => '03-11', + 2010 => '03-01', + 2011 => '03-20', + 2012 => '03-08', + 2013 => '03-27', + 2014 => '03-17', + 2015 => '03-06', + 2016 => '03-24', + 2017 => '03-13', + 2018 => '03-02', + 2019 => '03-21', + 2020 => '03-10', + 2021 => '03-29', + 2022 => '03-18', + 2023 => '03-08', + 2024 => '03-25', + 2025 => '03-14', + 2026 => '03-04', + 2027 => '03-22', + 2028 => '03-11', + 2029 => '03-01', + 2030 => '03-20', + 2031 => '03-09', + 2032 => '03-27', + 2033 => '03-16', + 2034 => '03-05', + 2035 => '03-24', + 2036 => '03-12', + 2037 => '03-02', + ]; + + public const goodFridayHolidays = [ + 1970 => '03-27', + 1971 => '04-09', + 1972 => '03-31', + 1973 => '04-20', + 1974 => '04-12', + 1975 => '03-28', + 1976 => '04-16', + 1977 => '04-08', + 1978 => '03-24', + 1979 => '04-13', + 1980 => '04-04', + 1981 => '04-17', + 1982 => '04-09', + 1983 => '04-01', + 1984 => '04-20', + 1985 => '04-05', + 1986 => '03-28', + 1987 => '04-17', + 1988 => '04-01', + 1989 => '03-24', + 1990 => '04-13', + 1991 => '03-29', + 1992 => '04-17', + 1993 => '04-09', + 1994 => '04-01', + 1995 => '04-14', + 1996 => '04-05', + 1997 => '03-28', + 1998 => '04-10', + 1999 => '04-02', + 2000 => '04-21', + 2001 => '04-13', + 2002 => '03-29', + 2003 => '04-18', + 2004 => '04-09', + 2005 => '03-25', + 2006 => '04-14', + 2007 => '04-06', + 2008 => '03-21', + 2009 => '04-10', + 2010 => '04-02', + 2011 => '04-22', + 2012 => '04-06', + 2013 => '03-29', + 2014 => '04-18', + 2015 => '04-03', + 2016 => '03-25', + 2017 => '04-14', + 2018 => '03-30', + 2019 => '04-19', + 2020 => '04-10', + 2021 => '04-02', + 2022 => '04-15', + 2023 => '04-07', + 2024 => '03-29', + 2025 => '04-18', + 2026 => '04-03', + 2027 => '03-26', + 2028 => '04-14', + 2029 => '03-30', + 2030 => '04-19', + 2031 => '04-11', + 2032 => '03-26', + 2033 => '04-15', + 2034 => '04-07', + 2035 => '03-23', + 2036 => '04-11', + 2037 => '04-03', + ]; + + public const ramzanIdHolidays = [ + 1970 => '11-30', + 1971 => '11-20', + 1972 => '11-08', + 1973 => '10-28', + 1974 => '10-18', + 1975 => '10-07', + 1976 => '09-25', + 1977 => '09-15', + 1978 => '09-04', + 1979 => '08-25', + 1980 => '08-13', + 1981 => '08-02', + 1982 => '07-23', + 1983 => '07-12', + 1984 => '06-30', + 1985 => '06-20', + 1986 => '06-09', + 1987 => '05-30', + 1988 => '05-18', + 1989 => '05-07', + 1990 => '04-27', + 1991 => '04-16', + 1992 => '04-04', + 1993 => '03-25', + 1994 => '03-14', + 1995 => '03-03', + 1996 => '02-21', + 1997 => '02-09', + 1998 => '01-30', + 1999 => '01-19', + 2000 => [ + '01-08', + '12-28', + ], + 2001 => '12-17', + 2002 => '12-06', + 2003 => '11-26', + 2004 => '11-14', + 2005 => '11-04', + 2006 => '10-24', + 2007 => '10-13', + 2008 => '10-02', + 2009 => '09-21', + 2010 => '09-10', + 2011 => '08-31', + 2012 => '08-20', + 2013 => '08-09', + 2014 => '07-29', + 2015 => '07-19', + 2016 => '07-06', + 2017 => '06-26', + 2018 => [ + '06-15', + '06-16' + ], + 2019 => '06-05', + 2020 => '05-25', + 2021 => '05-14', + 2022 => '05-03', + 2023 => '04-22', + 2024 => '04-11', + 2025 => '03-31', + 2026 => '03-21', + 2027 => '03-10', + 2028 => '02-27', + 2029 => '02-15', + 2030 => '02-05', + 2031 => '01-25', + 2032 => '01-15', + 2033 => [ + '01-03', + '12-24', + ], + 2034 => '12-13', + 2035 => '12-02', + 2036 => '11-20', + 2037 => '11-09', + ]; + + public const ramanavamiHolidays = [ + 1970 => '04-15', + 1971 => '04-03', + 1972 => '03-23', + 1973 => '04-11', + 1974 => '04-01', + 1975 => '04-20', + 1976 => '04-08', + 1977 => '03-29', + 1978 => '04-16', + 1979 => '04-05', + 1980 => '03-24', + 1981 => '04-12', + 1982 => '04-02', + 1983 => '04-21', + 1984 => '04-10', + 1985 => '03-30', + 1986 => '04-18', + 1987 => '04-07', + 1988 => '03-26', + 1989 => '04-14', + 1990 => '04-03', + 1991 => '03-24', + 1992 => '04-11', + 1993 => '04-01', + 1994 => '04-20', + 1995 => '04-09', + 1996 => '03-28', + 1997 => '04-16', + 1998 => '04-05', + 1999 => '03-25', + 2000 => '04-12', + 2001 => '04-02', + 2002 => '04-21', + 2003 => '04-11', + 2004 => '03-30', + 2005 => '04-18', + 2006 => '04-06', + 2007 => '03-26', + 2008 => '04-13', + 2009 => '04-03', + 2010 => '03-24', + 2011 => '04-12', + 2012 => '04-01', + 2013 => '04-19', + 2014 => '04-08', + 2015 => '03-28', + 2016 => '04-15', + 2017 => '04-04', + 2018 => '03-25', + 2019 => '04-13', + 2020 => '04-02', + 2021 => '04-21', + 2022 => '04-10', + 2023 => '03-30', + 2024 => '04-17', + 2025 => '04-06', + 2026 => '03-26', + 2027 => '04-15', + 2028 => '04-03', + 2029 => '04-22', + 2030 => '04-12', + 2031 => '04-01', + 2032 => '04-19', + 2033 => '04-07', + 2034 => '03-28', + 2035 => '04-16', + 2036 => '04-05', + 2037 => '03-25', + ]; + public const mahavirJayantiHolidays = [ + 1970 => '04-19', + 1971 => '04-08', + 1972 => '03-27', + 1973 => '04-15', + 1974 => '04-05', + 1975 => '04-24', + 1976 => '04-12', + 1977 => '04-02', + 1978 => '04-21', + 1979 => '04-10', + 1980 => '03-29', + 1981 => '04-17', + 1982 => '04-06', + 1983 => '04-25', + 1984 => '04-14', + 1985 => '04-03', + 1986 => '04-22', + 1987 => '04-12', + 1988 => '03-31', + 1989 => '04-18', + 1990 => '04-07', + 1991 => '03-28', + 1992 => '04-15', + 1993 => '04-05', + 1994 => '04-24', + 1995 => '04-13', + 1996 => '04-01', + 1997 => '04-20', + 1998 => '04-09', + 1999 => '03-29', + 2000 => '04-16', + 2001 => '04-06', + 2002 => '04-25', + 2003 => '04-15', + 2004 => '04-03', + 2005 => '04-22', + 2006 => '04-11', + 2007 => '03-31', + 2008 => '04-18', + 2009 => '04-07', + 2010 => '04-28', + 2011 => '04-16', + 2012 => '04-05', + 2013 => '04-24', + 2014 => '04-13', + 2015 => '04-02', + 2016 => '04-20', + 2017 => '04-09', + 2018 => '03-29', + 2019 => '04-17', + 2020 => '04-06', + 2021 => '04-25', + 2022 => '04-14', + 2023 => '04-04', + 2024 => '04-21', + 2025 => '04-10', + 2026 => '03-31', + 2027 => '04-19', + 2028 => '04-07', + 2029 => '04-26', + 2030 => '04-16', + 2031 => '04-05', + 2032 => '04-23', + 2033 => '04-12', + 2034 => '04-01', + 2035 => '04-20', + 2036 => '04-08', + 2037 => '03-29', + ]; + + public const buddhaPurnimaHolidays = [ + 1970 => '05-21', + 1971 => '05-10', + 1972 => '05-28', + 1973 => '05-17', + 1974 => '05-06', + 1975 => '05-25', + 1976 => '05-13', + 1977 => '05-03', + 1978 => '05-22', + 1979 => '05-12', + 1980 => '04-30', + 1981 => '05-18', + 1982 => '05-07', + 1983 => '05-26', + 1984 => '05-15', + 1985 => '05-04', + 1986 => '05-23', + 1987 => '05-13', + 1988 => '05-01', + 1989 => '05-20', + 1990 => '05-09', + 1991 => '05-28', + 1992 => '05-16', + 1993 => '05-06', + 1994 => '05-25', + 1995 => '05-14', + 1996 => '05-03', + 1997 => '05-22', + 1998 => '05-11', + 1999 => '04-30', + 2000 => '05-18', + 2001 => '05-07', + 2002 => '05-26', + 2003 => '05-16', + 2004 => '05-04', + 2005 => '05-23', + 2006 => '05-13', + 2007 => '05-02', + 2008 => '05-20', + 2009 => '05-08', + 2010 => '05-27', + 2011 => '05-17', + 2012 => '05-06', + 2013 => '05-25', + 2014 => '05-14', + 2015 => '05-04', + 2016 => '05-21', + 2017 => '05-10', + 2018 => '04-30', + 2019 => '05-18', + 2020 => '05-07', + 2021 => '05-26', + 2022 => '05-16', + 2023 => '05-05', + 2024 => '05-23', + 2025 => '05-12', + 2026 => '05-01', + 2027 => '05-20', + 2028 => '05-08', + 2029 => '05-27', + 2030 => '05-17', + 2031 => '05-07', + 2032 => '05-25', + 2033 => '05-14', + 2034 => '05-03', + 2035 => '05-22', + 2036 => '05-10', + 2037 => '04-29', + ]; + public const bakridHolidays = [ + 1970 => '02-17', + 1971 => '02-06', + 1972 => '01-27', + 1973 => '01-15', + 1974 => [ + '01-04', + '12-25' + ], + 1975 => '12-14', + 1976 => '12-02', + 1977 => '11-22', + 1978 => '11-11', + 1979 => '11-01', + 1980 => '10-20', + 1981 => '10-09', + 1982 => '09-29', + 1983 => '09-18', + 1984 => '09-06', + 1985 => '08-27', + 1986 => '08-16', + 1987 => '08-06', + 1988 => '07-25', + 1989 => '07-14', + 1990 => '07-04', + 1991 => '06-23', + 1992 => '06-11', + 1993 => '06-01', + 1994 => '05-21', + 1995 => '05-10', + 1996 => '04-29', + 1997 => '04-18', + 1998 => '04-08', + 1999 => '03-28', + 2000 => '03-16', + 2001 => '03-06', + 2002 => '02-23', + 2003 => '02-12', + 2004 => '02-02', + 2005 => '01-21', + 2006 => '01-11', + 2007 => '12-20', + 2008 => '12-09', + 2009 => '11-28', + 2010 => '11-17', + 2011 => '11-07', + 2012 => '10-27', + 2013 => '10-16', + 2014 => '10-06', + 2015 => '09-25', + 2016 => '09-13', + 2017 => '09-02', + 2018 => '08-22', + 2019 => '08-12', + 2020 => '08-01', + 2021 => '07-21', + 2022 => '07-10', + 2023 => '06-29', + 2024 => '06-17', + 2025 => '06-07', + 2026 => '05-28', + 2027 => '05-17', + 2028 => '05-06', + 2029 => '04-25', + 2030 => '04-14', + 2031 => '04-03', + 2032 => '03-22', + 2033 => '03-12', + 2034 => '03-02', + 2035 => '02-19', + 2036 => '02-08', + 2037 => '01-27', + ]; + + public const ashura = [ + 1970 => '03-18', + 1971 => '03-08', + 1972 => '02-25', + 1973 => '02-13', + 1974 => '02-03', + 1975 => '01-23', + 1976 => '01-12', + 1977 => [ + '01-01', + '12-21' + ], + 1978 => '12-11', + 1979 => '11-30', + 1980 => '11-18', + 1981 => '11-08', + 1982 => '10-28', + 1983 => '10-17', + 1984 => '10-06', + 1985 => '09-25', + 1986 => '09-15', + 1987 => '09-04', + 1988 => '08-23', + 1989 => '08-13', + 1990 => '08-02', + 1991 => '07-22', + 1992 => '07-11', + 1993 => '06-30', + 1994 => '06-19', + 1995 => '06-09', + 1996 => '05-28', + 1997 => '05-18', + 1998 => '05-07', + 1999 => '04-26', + 2000 => '04-15', + 2001 => '04-04', + 2002 => '03-24', + 2003 => '03-14', + 2004 => '03-02', + 2005 => '02-19', + 2006 => '02-09', + 2007 => '01-30', + 2008 => '01-19', + 2009 => [ + '01-07', + '12-27' + ], + 2010 => '12-17', + 2011 => '12-06', + 2012 => '11-25', + 2013 => '11-14', + 2014 => '11-04', + 2015 => '10-24', + 2016 => '10-12', + 2017 => '10-01', + 2018 => '09-21', + 2019 => '09-10', + 2020 => '08-30', + 2021 => '08-20', + 2022 => '08-09', + 2023 => '07-29', + 2024 => '07-17', + 2025 => '07-06', + 2026 => '06-26', + 2027 => '06-16', + 2028 => '06-04', + 2029 => '05-25', + 2030 => '05-14', + 2031 => '05-03', + 2032 => '04-21', + 2033 => '04-11', + 2034 => '03-31', + 2035 => '03-21', + 2036 => '03-09', + 2037 => '02-26', + ]; + + public const rakshabandhanHolidays = [ + 1970 => '08-17', + 1971 => '08-06', + 1972 => '08-24', + 1973 => '08-13', + 1974 => '08-03', + 1975 => '08-21', + 1976 => '08-09', + 1977 => '08-28', + 1978 => '08-18', + 1979 => '08-08', + 1980 => '08-26', + 1981 => '08-15', + 1982 => '08-04', + 1983 => '08-23', + 1984 => '08-11', + 1985 => '08-30', + 1986 => '08-19', + 1987 => '08-09', + 1988 => '08-27', + 1989 => '08-17', + 1990 => '08-06', + 1991 => '08-25', + 1992 => '08-13', + 1993 => '08-02', + 1994 => '08-21', + 1995 => '08-10', + 1996 => '08-28', + 1997 => '08-18', + 1998 => '08-07', + 1999 => '08-26', + 2000 => '08-15', + 2001 => '08-04', + 2002 => '08-22', + 2003 => '08-12', + 2004 => '08-29', + 2005 => '08-19', + 2006 => '08-09', + 2007 => '08-28', + 2008 => '08-16', + 2009 => '08-05', + 2010 => '08-24', + 2011 => '08-13', + 2012 => '08-02', + 2013 => '08-20', + 2014 => '08-10', + 2015 => '08-29', + 2016 => '08-18', + 2017 => '08-07', + 2018 => '08-26', + 2019 => '08-15', + 2020 => '08-03', + 2021 => '08-22', + 2022 => '08-11', + 2023 => '08-30', + 2024 => '08-19', + 2025 => '08-09', + 2026 => '08-28', + 2027 => '08-17', + 2028 => '08-05', + 2029 => '08-23', + 2030 => '08-13', + 2031 => '08-02', + 2032 => '08-20', + 2033 => '08-10', + 2034 => '08-29', + 2035 => '08-18', + 2036 => '08-06', + 2037 => '08-25', + ]; + + public const janmashtamiHolidays = [ + 1970 => '08-24', + 1971 => '08-13', + 1972 => '09-01', + 1973 => '08-21', + 1974 => '08-11', + 1975 => '08-30', + 1976 => '08-18', + 1977 => '09-06', + 1978 => '08-26', + 1979 => '08-15', + 1980 => '09-02', + 1981 => '08-23', + 1982 => '08-12', + 1983 => '08-31', + 1984 => '08-20', + 1985 => '09-07', + 1986 => '08-27', + 1987 => '08-16', + 1988 => '09-03', + 1989 => '08-24', + 1990 => '08-14', + 1991 => '09-02', + 1992 => '08-21', + 1993 => '08-11', + 1994 => '08-29', + 1995 => '08-18', + 1996 => '09-05', + 1997 => '08-25', + 1998 => '08-15', + 1999 => '09-03', + 2000 => '08-23', + 2001 => '08-12', + 2002 => '08-31', + 2003 => '08-20', + 2004 => '09-07', + 2005 => '08-27', + 2006 => '08-16', + 2007 => '09-04', + 2008 => '08-24', + 2009 => '08-14', + 2010 => '09-02', + 2011 => '08-22', + 2012 => '08-10', + 2013 => '08-28', + 2014 => '08-18', + 2015 => '09-05', + 2016 => '08-25', + 2017 => '08-15', + 2018 => '09-03', + 2019 => '08-24', + 2020 => '08-12', + 2021 => '08-30', + 2022 => '08-19', + 2023 => '09-07', + 2024 => '08-26', + 2025 => '08-16', + 2026 => '09-04', + 2027 => '08-25', + 2028 => '08-13', + 2029 => '09-01', + 2030 => '08-21', + 2031 => '08-10', + 2032 => '08-28', + 2033 => '08-17', + 2034 => '09-06', + 2035 => '08-26', + 2036 => '08-15', + 2037 => '09-03', + ]; + public const miladHolidays = [ + 1970 => '05-19', + 1971 => '05-09', + 1972 => '04-27', + 1973 => '04-16', + 1974 => '04-06', + 1975 => '03-26', + 1976 => '03-14', + 1977 => '03-04', + 1978 => '02-21', + 1979 => '02-11', + 1980 => '01-31', + 1981 => '01-19', + 1982 => [ + '01-09', + '12-29' + ], + 1983 => '12-18', + 1984 => '12-07', + 1985 => '11-26', + 1986 => '11-16', + 1987 => '11-05', + 1988 => '10-24', + 1989 => '10-14', + 1990 => '10-03', + 1991 => '09-22', + 1992 => '09-11', + 1993 => '08-31', + 1994 => '08-20', + 1995 => '08-10', + 1996 => '07-29', + 1997 => '07-19', + 1998 => '07-08', + 1999 => '06-27', + 2000 => '06-16', + 2001 => '06-05', + 2002 => '05-25', + 2003 => '05-15', + 2004 => '05-03', + 2005 => '04-22', + 2006 => '04-11', + 2007 => '04-01', + 2008 => '03-21', + 2009 => '03-09', + 2010 => '02-27', + 2011 => '02-16', + 2012 => '02-05', + 2013 => '01-25', + 2014 => '01-14', + 2015 => '01-04', + 2016 => '12-13', + 2017 => '12-02', + 2018 => '11-21', + 2019 => '11-10', + 2020 => '10-30', + 2021 => '10-19', + 2022 => '10-09', + 2023 => '09-28', + 2024 => '09-16', + 2025 => '09-05', + 2026 => '08-27', + 2027 => '08-16', + 2028 => '08-04', + 2029 => '07-25', + 2030 => '07-14', + 2031 => '07-03', + 2032 => '06-22', + 2033 => '06-11', + 2034 => '05-31', + 2035 => '05-21', + 2036 => '05-09', + 2037 => '04-29', + ]; + + public const dussehraHolidays = [ + 1970 => '10-10', + 1971 => '09-30', + 1972 => '10-17', + 1973 => '10-06', + 1974 => '10-25', + 1975 => '10-14', + 1976 => '10-02', + 1977 => '10-21', + 1978 => '10-11', + 1979 => '10-01', + 1980 => '10-19', + 1981 => '10-08', + 1982 => '10-27', + 1983 => '10-16', + 1984 => '10-04', + 1985 => '10-22', + 1986 => '10-12', + 1987 => '10-02', + 1988 => '10-20', + 1989 => '10-10', + 1990 => '09-29', + 1991 => '10-17', + 1992 => '10-06', + 1993 => '10-24', + 1994 => '10-13', + 1995 => '10-03', + 1996 => '10-21', + 1997 => '10-11', + 1998 => '10-01', + 1999 => '10-19', + 2000 => '10-07', + 2001 => '10-26', + 2002 => '10-15', + 2003 => '10-05', + 2004 => '10-22', + 2005 => '10-12', + 2006 => '10-02', + 2007 => '10-21', + 2008 => '10-09', + 2009 => '09-28', + 2010 => '10-17', + 2011 => '10-06', + 2012 => '10-24', + 2013 => '10-13', + 2014 => '10-03', + 2015 => '10-22', + 2016 => '10-11', + 2017 => '09-30', + 2018 => '10-19', + 2019 => '10-08', + 2020 => '10-25', + 2021 => '10-15', + 2022 => '10-05', + 2023 => '10-24', + 2024 => '10-12', + 2025 => '10-02', + 2026 => '10-20', + 2027 => '10-09', + 2028 => '09-27', + 2029 => '10-16', + 2030 => '10-06', + 2031 => '10-25', + 2032 => '10-14', + 2033 => '10-03', + 2034 => '10-22', + 2035 => '10-11', + 2036 => '09-29', + 2037 => '10-18', + ]; + public const diwaliHolidays = [ + 1970 => '10-29', + 1971 => '10-18', + 1972 => '11-05', + 1973 => '10-25', + 1974 => '11-13', + 1975 => '11-03', + 1976 => '10-22', + 1977 => '11-10', + 1978 => '10-31', + 1979 => '10-20', + 1980 => '11-07', + 1981 => '10-27', + 1982 => '11-15', + 1983 => '11-04', + 1984 => '10-24', + 1985 => '11-12', + 1986 => '11-01', + 1987 => '10-22', + 1988 => '11-09', + 1989 => '10-29', + 1990 => '10-18', + 1991 => '11-05', + 1992 => '10-25', + 1993 => '11-13', + 1994 => '11-03', + 1995 => '10-23', + 1996 => '11-10', + 1997 => '10-30', + 1998 => '10-19', + 1999 => '11-07', + 2000 => '10-26', + 2001 => '11-14', + 2002 => '11-04', + 2003 => '10-25', + 2004 => '11-12', + 2005 => '11-01', + 2006 => '10-21', + 2007 => '11-09', + 2008 => '10-28', + 2009 => '10-17', + 2010 => '11-05', + 2011 => '10-26', + 2012 => '11-13', + 2013 => '11-03', + 2014 => '10-23', + 2015 => '11-11', + 2016 => '10-30', + 2017 => '10-19', + 2018 => '11-07', + 2019 => '10-27', + 2020 => '11-14', + 2021 => '11-04', + 2022 => '10-24', + 2023 => '11-12', + 2024 => '10-31', + 2025 => '10-20', + 2026 => '11-08', + 2027 => '10-29', + 2028 => '10-17', + 2029 => '11-05', + 2030 => '10-26', + 2031 => '11-14', + 2032 => '11-02', + 2033 => '10-22', + 2034 => '11-10', + 2035 => '10-30', + 2036 => '10-18', + 2037 => '11-07', + ]; + + public const bhaiDujHolidays = [ + 1970 => '10-31', + 1971 => '10-21', + 1972 => '11-07', + 1973 => '10-27', + 1974 => '11-15', + 1975 => '11-05', + 1976 => '10-24', + 1977 => '11-12', + 1978 => '11-02', + 1979 => '10-22', + 1980 => '11-09', + 1981 => '10-29', + 1982 => '11-17', + 1983 => '11-06', + 1984 => '10-25', + 1985 => '11-14', + 1986 => '11-03', + 1987 => '10-24', + 1988 => '11-11', + 1989 => '10-31', + 1990 => '10-20', + 1991 => '11-08', + 1992 => '10-27', + 1993 => '11-15', + 1994 => '11-04', + 1995 => '10-25', + 1996 => '11-12', + 1997 => '11-02', + 1998 => '10-22', + 1999 => '11-09', + 2000 => '10-28', + 2001 => '11-16', + 2002 => '11-06', + 2003 => '10-26', + 2004 => '11-14', + 2005 => '11-03', + 2006 => '10-23', + 2007 => '11-11', + 2008 => '10-30', + 2009 => '10-19', + 2010 => '11-07', + 2011 => '10-28', + 2012 => '11-15', + 2013 => '11-05', + 2014 => '10-25', + 2015 => '11-13', + 2016 => '11-01', + 2017 => '10-21', + 2018 => '11-09', + 2019 => '10-29', + 2020 => '11-16', + 2021 => '11-06', + 2022 => '10-26', + 2023 => '11-15', + 2024 => '11-03', + 2025 => '10-23', + 2026 => '11-11', + 2027 => '10-31', + 2028 => '10-19', + 2029 => '11-07', + 2030 => '10-28', + 2031 => '11-16', + 2032 => '11-04', + 2033 => '10-25', + 2034 => '11-12', + 2035 => '11-01', + 2036 => '10-21', + 2037 => '11-08', + ]; + public const guruNanakHolidays = [ + 1970 => '11-13', + 1971 => '11-02', + 1972 => '11-20', + 1973 => '11-10', + 1974 => '11-29', + 1975 => '11-18', + 1976 => '11-06', + 1977 => '11-25', + 1978 => '11-14', + 1979 => '11-04', + 1980 => '11-22', + 1981 => '11-11', + 1982 => '11-30', + 1983 => '11-20', + 1984 => '11-08', + 1985 => '11-27', + 1986 => '11-16', + 1987 => '11-05', + 1988 => '11-23', + 1989 => '11-13', + 1990 => '11-02', + 1991 => '11-21', + 1992 => '11-10', + 1993 => '11-29', + 1994 => '11-18', + 1995 => '11-07', + 1996 => '11-25', + 1997 => '11-14', + 1998 => '11-04', + 1999 => '11-23', + 2000 => '11-11', + 2001 => '11-30', + 2002 => '11-19', + 2003 => '11-08', + 2004 => '11-26', + 2005 => '11-15', + 2006 => '11-05', + 2007 => '11-24', + 2008 => '11-13', + 2009 => '11-02', + 2010 => '11-21', + 2011 => '11-10', + 2012 => '11-28', + 2013 => '11-17', + 2014 => '11-06', + 2015 => '11-25', + 2016 => '11-14', + 2017 => '11-04', + 2018 => '11-23', + 2019 => '11-12', + 2020 => '11-30', + 2021 => '11-19', + 2022 => '11-08', + 2023 => '11-27', + 2024 => '11-15', + 2025 => '11-05', + 2026 => '11-24', + 2027 => '11-14', + 2028 => '11-02', + 2029 => '11-21', + 2030 => '11-10', + 2031 => '11-28', + 2032 => '11-17', + 2033 => '11-06', + 2034 => '11-25', + 2035 => '11-15', + 2036 => '11-03', + 2037 => '11-22', + ]; + + + public function countryCode(): string + { + return 'in'; + } + + protected function allHolidays(int $year): array + { + $newHolidays = [ + 'Holi' => self::holiHolidays[$year], + 'Good Friday' => self::goodFridayHolidays[$year], + 'Rama Navami' => self::ramanavamiHolidays[$year], + 'Mahavir Jayanti' => self::mahavirJayantiHolidays[$year], + 'Buddha Purnima/Vesak' => self::buddhaPurnimaHolidays[$year], + 'Raksha Bandhan' => self::rakshabandhanHolidays[$year], + 'Janmashtami' => self::janmashtamiHolidays[$year], + 'Dussehra' => self::dussehraHolidays[$year], + 'Diwali/Deepavali' => self::diwaliHolidays[$year], + 'Bhai Dooj' => self::bhaiDujHolidays[$year], + 'Guru Nanak Jayanti' => self::guruNanakHolidays[$year], + ]; + + return array_merge([ + 'Republic Day' => '01-26', + 'Independence Day' => '08-15', + 'Mahatma Gandhi Jayanti' => '10-02', + 'Christmas' => '12-25', + ],$newHolidays, $this->otherHolidays($year)); + } + + /** @return array */ + public function otherHolidays(int $year): array + { + $ashura = $this->ashura($year); + $miladHolidays = $this->miladHolidays($year); + $bakridHolidays = $this->bakridHolidays($year); + $ramzanIdHolidays = $this->ramzanIdHolidays($year); + + $holidays = array_merge( + $this->convertPeriods('Milad un-Nabi/Id-e-Milad', $year, $miladHolidays[0], includeEve: false), + $this->convertPeriods('Muharram/Ashura', $year, $ashura[0], includeEve: false), + $this->convertPeriods('Bakrid/Eid ul-Adha', $year, $bakridHolidays[0], includeEve: false), + $this->convertPeriods('Ramzan Id\/Eid-ul-Fitar', $year, $ramzanIdHolidays[0], includeEve: false), + ); + + if (count($miladHolidays) > 1) { + $holidays = array_merge($holidays, + $this->convertPeriods('2. Milad un-Nabi/Id-e-Milad', $year, $miladHolidays[1], includeEve: false), + ); + } + + if (count($ashura) > 1) { + $holidays = array_merge($holidays, + $this->convertPeriods('2. Muharram/Ashura', $year, $ashura[1], includeEve: false), + ); + } + + if (count($bakridHolidays) > 1) { + $holidays = array_merge($holidays, + $this->convertPeriods('2. Bakrid/Eid ul-Adha', $year, $bakridHolidays[1], includeEve: false), + ); + } + + if (count($ramzanIdHolidays) > 1) { + $holidays = array_merge($holidays, + $this->convertPeriods('2. Ramzan Id\/Eid-ul-Fitar', $year, $ramzanIdHolidays[1], includeEve: false), + ); + } + + return $holidays; + } + +} \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/IndiaTest/it_can_calculate_India_holidays_for_2024.snap b/tests/.pest/snapshots/Countries/IndiaTest/it_can_calculate_India_holidays_for_2024.snap new file mode 100644 index 000000000..c2b8cd7d3 --- /dev/null +++ b/tests/.pest/snapshots/Countries/IndiaTest/it_can_calculate_India_holidays_for_2024.snap @@ -0,0 +1,78 @@ +[ + { + "name": "Republic Day", + "date": "2024-01-26" + }, + { + "name": "Holi", + "date": "2024-03-25" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Ramzan Id\\\/Eid-ul-Fitar", + "date": "2024-04-11" + }, + { + "name": "Rama Navami", + "date": "2024-04-17" + }, + { + "name": "Mahavir Jayanti", + "date": "2024-04-21" + }, + { + "name": "Buddha Purnima\/Vesak", + "date": "2024-05-23" + }, + { + "name": "Bakrid\/Eid ul-Adha", + "date": "2024-06-17" + }, + { + "name": "Muharram\/Ashura", + "date": "2024-07-17" + }, + { + "name": "Independence Day", + "date": "2024-08-15" + }, + { + "name": "Raksha Bandhan", + "date": "2024-08-19" + }, + { + "name": "Janmashtami", + "date": "2024-08-26" + }, + { + "name": "Milad un-Nabi\/Id-e-Milad", + "date": "2024-09-16" + }, + { + "name": "Mahatma Gandhi Jayanti", + "date": "2024-10-02" + }, + { + "name": "Dussehra", + "date": "2024-10-12" + }, + { + "name": "Diwali\/Deepavali", + "date": "2024-10-31" + }, + { + "name": "Bhai Dooj", + "date": "2024-11-03" + }, + { + "name": "Guru Nanak Jayanti", + "date": "2024-11-15" + }, + { + "name": "Christmas", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/IndiaTest/it_can_calculate_India_holidays_with_data_set___1970____1970_.snap b/tests/.pest/snapshots/Countries/IndiaTest/it_can_calculate_India_holidays_with_data_set___1970____1970_.snap new file mode 100644 index 000000000..a8504799b --- /dev/null +++ b/tests/.pest/snapshots/Countries/IndiaTest/it_can_calculate_India_holidays_with_data_set___1970____1970_.snap @@ -0,0 +1,78 @@ +[ + { + "name": "Republic Day", + "date": "1970-01-26" + }, + { + "name": "Bakrid\/Eid ul-Adha", + "date": "1970-02-17" + }, + { + "name": "Muharram\/Ashura", + "date": "1970-03-18" + }, + { + "name": "Holi", + "date": "1970-03-23" + }, + { + "name": "Good Friday", + "date": "1970-03-27" + }, + { + "name": "Rama Navami", + "date": "1970-04-15" + }, + { + "name": "Mahavir Jayanti", + "date": "1970-04-19" + }, + { + "name": "Milad un-Nabi\/Id-e-Milad", + "date": "1970-05-19" + }, + { + "name": "Buddha Purnima\/Vesak", + "date": "1970-05-21" + }, + { + "name": "Independence Day", + "date": "1970-08-15" + }, + { + "name": "Raksha Bandhan", + "date": "1970-08-17" + }, + { + "name": "Janmashtami", + "date": "1970-08-24" + }, + { + "name": "Mahatma Gandhi Jayanti", + "date": "1970-10-02" + }, + { + "name": "Dussehra", + "date": "1970-10-10" + }, + { + "name": "Diwali\/Deepavali", + "date": "1970-10-29" + }, + { + "name": "Bhai Dooj", + "date": "1970-10-31" + }, + { + "name": "Guru Nanak Jayanti", + "date": "1970-11-13" + }, + { + "name": "Ramzan Id\\\/Eid-ul-Fitar", + "date": "1970-11-30" + }, + { + "name": "Christmas", + "date": "1970-12-25" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/IndiaTest/it_can_calculate_India_holidays_with_data_set___1977____1977_.snap b/tests/.pest/snapshots/Countries/IndiaTest/it_can_calculate_India_holidays_with_data_set___1977____1977_.snap new file mode 100644 index 000000000..53a8b00a9 --- /dev/null +++ b/tests/.pest/snapshots/Countries/IndiaTest/it_can_calculate_India_holidays_with_data_set___1977____1977_.snap @@ -0,0 +1,82 @@ +[ + { + "name": "Muharram\/Ashura", + "date": "1977-01-01" + }, + { + "name": "Republic Day", + "date": "1977-01-26" + }, + { + "name": "Milad un-Nabi\/Id-e-Milad", + "date": "1977-03-04" + }, + { + "name": "Holi", + "date": "1977-03-06" + }, + { + "name": "Rama Navami", + "date": "1977-03-29" + }, + { + "name": "Mahavir Jayanti", + "date": "1977-04-02" + }, + { + "name": "Good Friday", + "date": "1977-04-08" + }, + { + "name": "Buddha Purnima\/Vesak", + "date": "1977-05-03" + }, + { + "name": "Independence Day", + "date": "1977-08-15" + }, + { + "name": "Raksha Bandhan", + "date": "1977-08-28" + }, + { + "name": "Janmashtami", + "date": "1977-09-06" + }, + { + "name": "Ramzan Id\\\/Eid-ul-Fitar", + "date": "1977-09-15" + }, + { + "name": "Mahatma Gandhi Jayanti", + "date": "1977-10-02" + }, + { + "name": "Dussehra", + "date": "1977-10-21" + }, + { + "name": "Diwali\/Deepavali", + "date": "1977-11-10" + }, + { + "name": "Bhai Dooj", + "date": "1977-11-12" + }, + { + "name": "Bakrid\/Eid ul-Adha", + "date": "1977-11-22" + }, + { + "name": "Guru Nanak Jayanti", + "date": "1977-11-25" + }, + { + "name": "2. Muharram\/Ashura", + "date": "1977-12-21" + }, + { + "name": "Christmas", + "date": "1977-12-25" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/IndiaTest/it_can_calculate_India_holidays_with_data_set___2000____2000_.snap b/tests/.pest/snapshots/Countries/IndiaTest/it_can_calculate_India_holidays_with_data_set___2000____2000_.snap new file mode 100644 index 000000000..3b3f3ffde --- /dev/null +++ b/tests/.pest/snapshots/Countries/IndiaTest/it_can_calculate_India_holidays_with_data_set___2000____2000_.snap @@ -0,0 +1,82 @@ +[ + { + "name": "Ramzan Id\\\/Eid-ul-Fitar", + "date": "2000-01-08" + }, + { + "name": "Republic Day", + "date": "2000-01-26" + }, + { + "name": "Bakrid\/Eid ul-Adha", + "date": "2000-03-16" + }, + { + "name": "Holi", + "date": "2000-03-20" + }, + { + "name": "Rama Navami", + "date": "2000-04-12" + }, + { + "name": "Muharram\/Ashura", + "date": "2000-04-15" + }, + { + "name": "Mahavir Jayanti", + "date": "2000-04-16" + }, + { + "name": "Good Friday", + "date": "2000-04-21" + }, + { + "name": "Buddha Purnima\/Vesak", + "date": "2000-05-18" + }, + { + "name": "Milad un-Nabi\/Id-e-Milad", + "date": "2000-06-16" + }, + { + "name": "Independence Day", + "date": "2000-08-15" + }, + { + "name": "Raksha Bandhan", + "date": "2000-08-15" + }, + { + "name": "Janmashtami", + "date": "2000-08-23" + }, + { + "name": "Mahatma Gandhi Jayanti", + "date": "2000-10-02" + }, + { + "name": "Dussehra", + "date": "2000-10-07" + }, + { + "name": "Diwali\/Deepavali", + "date": "2000-10-26" + }, + { + "name": "Bhai Dooj", + "date": "2000-10-28" + }, + { + "name": "Guru Nanak Jayanti", + "date": "2000-11-11" + }, + { + "name": "Christmas", + "date": "2000-12-25" + }, + { + "name": "2. Ramzan Id\\\/Eid-ul-Fitar", + "date": "2000-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/IndiaTest/it_can_calculate_India_holidays_with_data_set___2018____2018_.snap b/tests/.pest/snapshots/Countries/IndiaTest/it_can_calculate_India_holidays_with_data_set___2018____2018_.snap new file mode 100644 index 000000000..3ab8f2914 --- /dev/null +++ b/tests/.pest/snapshots/Countries/IndiaTest/it_can_calculate_India_holidays_with_data_set___2018____2018_.snap @@ -0,0 +1,82 @@ +[ + { + "name": "Republic Day", + "date": "2018-01-26" + }, + { + "name": "Holi", + "date": "2018-03-02" + }, + { + "name": "Rama Navami", + "date": "2018-03-25" + }, + { + "name": "Mahavir Jayanti", + "date": "2018-03-29" + }, + { + "name": "Good Friday", + "date": "2018-03-30" + }, + { + "name": "Buddha Purnima\/Vesak", + "date": "2018-04-30" + }, + { + "name": "Ramzan Id\\\/Eid-ul-Fitar", + "date": "2018-06-15" + }, + { + "name": "2. Ramzan Id\\\/Eid-ul-Fitar", + "date": "2018-06-16" + }, + { + "name": "Independence Day", + "date": "2018-08-15" + }, + { + "name": "Bakrid\/Eid ul-Adha", + "date": "2018-08-22" + }, + { + "name": "Raksha Bandhan", + "date": "2018-08-26" + }, + { + "name": "Janmashtami", + "date": "2018-09-03" + }, + { + "name": "Muharram\/Ashura", + "date": "2018-09-21" + }, + { + "name": "Mahatma Gandhi Jayanti", + "date": "2018-10-02" + }, + { + "name": "Dussehra", + "date": "2018-10-19" + }, + { + "name": "Diwali\/Deepavali", + "date": "2018-11-07" + }, + { + "name": "Bhai Dooj", + "date": "2018-11-09" + }, + { + "name": "Milad un-Nabi\/Id-e-Milad", + "date": "2018-11-21" + }, + { + "name": "Guru Nanak Jayanti", + "date": "2018-11-23" + }, + { + "name": "Christmas", + "date": "2018-12-25" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/IndiaTest/it_can_calculate_India_holidays_with_data_set___2037____2037_.snap b/tests/.pest/snapshots/Countries/IndiaTest/it_can_calculate_India_holidays_with_data_set___2037____2037_.snap new file mode 100644 index 000000000..4030f8392 --- /dev/null +++ b/tests/.pest/snapshots/Countries/IndiaTest/it_can_calculate_India_holidays_with_data_set___2037____2037_.snap @@ -0,0 +1,78 @@ +[ + { + "name": "Republic Day", + "date": "2037-01-26" + }, + { + "name": "Bakrid\/Eid ul-Adha", + "date": "2037-01-27" + }, + { + "name": "Muharram\/Ashura", + "date": "2037-02-26" + }, + { + "name": "Holi", + "date": "2037-03-02" + }, + { + "name": "Rama Navami", + "date": "2037-03-25" + }, + { + "name": "Mahavir Jayanti", + "date": "2037-03-29" + }, + { + "name": "Good Friday", + "date": "2037-04-03" + }, + { + "name": "Buddha Purnima\/Vesak", + "date": "2037-04-29" + }, + { + "name": "Milad un-Nabi\/Id-e-Milad", + "date": "2037-04-29" + }, + { + "name": "Independence Day", + "date": "2037-08-15" + }, + { + "name": "Raksha Bandhan", + "date": "2037-08-25" + }, + { + "name": "Janmashtami", + "date": "2037-09-03" + }, + { + "name": "Mahatma Gandhi Jayanti", + "date": "2037-10-02" + }, + { + "name": "Dussehra", + "date": "2037-10-18" + }, + { + "name": "Diwali\/Deepavali", + "date": "2037-11-07" + }, + { + "name": "Bhai Dooj", + "date": "2037-11-08" + }, + { + "name": "Ramzan Id\\\/Eid-ul-Fitar", + "date": "2037-11-09" + }, + { + "name": "Guru Nanak Jayanti", + "date": "2037-11-22" + }, + { + "name": "Christmas", + "date": "2037-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/IndiaTest.php b/tests/Countries/IndiaTest.php new file mode 100644 index 000000000..378e825b6 --- /dev/null +++ b/tests/Countries/IndiaTest.php @@ -0,0 +1,38 @@ +get(); + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('does not return a holiday falsely', function () { + $dateInstance = CarbonImmutable::createFromDate('2024-01-03'); + $holiday = Holidays::for(country: 'in'); + + $isHoliday = $holiday->isHoliday($dateInstance); + expect($isHoliday)->toBeFalse(); + + $holidayName = $holiday->getName($dateInstance); + expect($holidayName)->toBeNull(); +}); + +it('can calculate India holidays', function ($year) { + CarbonImmutable::setTestNow($year.'-01-01'); + $holidays = Holidays::for('in')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +})->with([1970, 1977, 2000, 2018, 2037]); +