Skip to content

Commit

Permalink
ChineseCalendar changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nielsvanpach committed Jan 27, 2024
1 parent 57ff3b2 commit 9bb7bb2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/Calendars/ChineseCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

trait ChineseCalendar
{
protected string $asianTimezone = 'Asia/Shanghai';
protected string $chineseCalendarTimezone = 'Asia/Shanghai';

public function setTimezoneForChineseCalendar(string $asianTimezone): static
public function setChineseCalendarTimezone(string $chineseCalendarTimezone): static
{
$this->asianTimezone = $asianTimezone;
$this->chineseCalendarTimezone = $chineseCalendarTimezone;

return $this;
}
Expand All @@ -23,7 +23,7 @@ protected function chineseToGregorianDate(string $input, int $year): CarbonImmut

return (new CarbonImmutable())
->setTimeStamp($timestamp)
->setTimezone(new DateTimeZone($this->asianTimezone));
->setTimezone(new DateTimeZone($this->chineseCalendarTimezone));
}

protected function getFormatter(): IntlDateFormatter
Expand All @@ -32,7 +32,7 @@ protected function getFormatter(): IntlDateFormatter
locale: 'zh-CN@calendar=chinese',
dateType: IntlDateFormatter::SHORT,
timeType: IntlDateFormatter::NONE,
timezone: $this->asianTimezone,
timezone: $this->chineseCalendarTimezone,
calendar: IntlDateFormatter::TRADITIONAL
);
}
Expand Down
17 changes: 9 additions & 8 deletions src/Countries/Vietnam.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;
use Carbon\CarbonInterface;
use Spatie\Holidays\Calendars\ChineseCalendar;

class Vietnam extends Country
Expand Down Expand Up @@ -31,7 +32,7 @@ protected function allHolidays(int $year): array
/** @return array<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
$this->setTimezoneForChineseCalendar('Asia/Ho_Chi_Minh');
$this->setChineseCalendarTimezone('Asia/Ho_Chi_Minh');

return array_merge(
$this->getHungKingsFestival($year),
Expand Down Expand Up @@ -82,31 +83,31 @@ protected function getTheExtraDayForIndependenceDay(int $year): array
$independenceDay = CarbonImmutable::parse("$year-09-02")
->setTimeZone('Asia/Ho_Chi_Minh');

if ($independenceDay->dayOfWeek == CarbonImmutable::MONDAY) {
if ($independenceDay->dayOfWeek === CarbonInterface::MONDAY) {
return ['Ngày Sau Quốc Khánh' => $independenceDay->addDay()];
}

if ($independenceDay->dayOfWeek == CarbonImmutable::TUESDAY) {
if ($independenceDay->dayOfWeek === CarbonInterface::TUESDAY) {
return ['Ngày Trước Quốc Khánh' => $independenceDay->subDay()];
}

if ($independenceDay->dayOfWeek == CarbonImmutable::WEDNESDAY) {
if ($independenceDay->dayOfWeek === CarbonInterface::WEDNESDAY) {
return ['Ngày Trước Quốc Khánh' => $independenceDay->subDay()];
}

if ($independenceDay->dayOfWeek == CarbonImmutable::THURSDAY) {
if ($independenceDay->dayOfWeek === CarbonInterface::THURSDAY) {
return ['Ngày Sau Quốc Khánh' => $independenceDay->addDay()];
}

if ($independenceDay->dayOfWeek == CarbonImmutable::FRIDAY) {
if ($independenceDay->dayOfWeek === CarbonInterface::FRIDAY) {
return ['Ngày Trước Quốc Khánh' => $independenceDay->subDay()];
}

if ($independenceDay->dayOfWeek == CarbonImmutable::SATURDAY) {
if ($independenceDay->dayOfWeek === CarbonInterface::SATURDAY) {
return ['Ngày Trước Quốc Khánh' => $independenceDay->subDay()];
}

if ($independenceDay->dayOfWeek == CarbonImmutable::SUNDAY) {
if ($independenceDay->dayOfWeek === CarbonInterface::SUNDAY) {
return ['Ngày Sau Quốc Khánh' => $independenceDay->addDays(2)];
}

Expand Down

0 comments on commit 9bb7bb2

Please sign in to comment.