Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/build.yml
  • Loading branch information
matsuoshi committed Sep 9, 2024
2 parents 39d403b + f29e0ed commit 2f47aa3
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 13 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build

on:
schedule:
- cron: '0 15 31 12 *'
workflow_dispatch:
push:
branches: [ build-test ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: build api files
env:
TZ: 'Asia/Tokyo'
run: composer build

- name: commit and push
run: |
git add -N .
if ! git diff --exit-code --quiet
then
git config user.email "[email protected]"
git config user.name "from GitHub Actions"
git add --all
git commit -m "build"
git push
fi
42 changes: 42 additions & 0 deletions .github/workflows/touch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: touch

on:
schedule:
- cron: '0 3 1 * *'
workflow_dispatch:

jobs:
touch:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: touch
env:
TZ: 'Asia/Tokyo'
run: composer touch

- name: commit and push
run: |
git add -N .
if ! git diff --exit-code --quiet
then
git config user.email "[email protected]"
git config user.name "from GitHub Actions"
git add --all
git commit -m "touch"
git push
fi
42 changes: 31 additions & 11 deletions app/holidaysJP.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ public function generate()
foreach ($yearly as $year => $a) {
$this->generate_api_file($a, $year);
}

$this->updateCheckedFile();
}

/**
Expand Down Expand Up @@ -80,19 +78,47 @@ function get_holidays($data = null): Collection
}
$date = Chronos::createFromTimestamp(strtotime($m[1]));

// サマリ(祝日名)を求める
if (preg_match('/SUMMARY:(.+?)\n/m', $event, $summary) != 1) {
// 祝日名を取得
$holiday_name = $this->get_holiday_name($event);
if (!$holiday_name) {
continue;
}

$results[$date->timestamp] = $this->convert_holiday_name($date, $summary[1]);
$results[$date->timestamp] = $this->convert_holiday_name($date, $holiday_name);
}

// 日付順にソートして返却
ksort($results);
return Collection::make($results);
}

public function get_holiday_name($event): ?string
{
if (preg_match('/SUMMARY:(.+?)\n/m', $event, $summary) != 1) {
return null;
};

return $this->filetr_holiday_name($summary[1]);
}

public function filetr_holiday_name($name): ?string
{
$holidays = [
'元日', '成人の日', '建国記念の日', '天皇誕生日',
'春分の日', '昭和の日', '憲法記念日', 'みどりの日',
'こどもの日', '海の日', '山の日', '敬老の日',
'秋分の日', 'スポーツの日', '文化の日', '勤労感謝の日',
'国民の休日', '祝日',
// 過去の祝日
'体育の日', '天皇の即位の日', '即位礼正殿の儀の行われる日',
];
foreach ($holidays as $holiday) {
if (strpos($name, $holiday) !== false) {
return $name;
}
}
return null;
}

/**
* @param Chronos $date
Expand Down Expand Up @@ -184,10 +210,4 @@ protected function output_csv_file($filename, $data)
}
fclose($fp);
}

protected function updateCheckedFile()
{
$checkedFile = self::DIST . '/checked_at.txt';
file_put_contents($checkedFile, date('Y-m-d H:i:s'));
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"phpunit/phpunit": "^9.5"
},
"scripts": {
"build": "php main.php",
"build": "php main.php && composer touch",
"touch": "date '+%F %T' > docs/v1/checked_at.txt",
"test": "phpunit"
}
}
23 changes: 23 additions & 0 deletions tests/data/2024.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"2024-01-01": "元日",
"2024-01-08": "成人の日",
"2024-02-11": "建国記念の日",
"2024-02-12": "建国記念の日 振替休日",
"2024-02-23": "天皇誕生日",
"2024-03-20": "春分の日",
"2024-04-29": "昭和の日",
"2024-05-03": "憲法記念日",
"2024-05-04": "みどりの日",
"2024-05-05": "こどもの日",
"2024-05-06": "こどもの日 振替休日",
"2024-07-15": "海の日",
"2024-08-11": "山の日",
"2024-08-12": "休日 山の日",
"2024-09-16": "敬老の日",
"2024-09-22": "秋分の日",
"2024-09-23": "秋分の日 振替休日",
"2024-10-14": "スポーツの日",
"2024-11-03": "文化の日",
"2024-11-04": "文化の日 振替休日",
"2024-11-23": "勤労感謝の日"
}
21 changes: 21 additions & 0 deletions tests/data/2025.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"2025-01-01": "元日",
"2025-01-13": "成人の日",
"2025-02-11": "建国記念の日",
"2025-02-23": "天皇誕生日",
"2025-02-24": "天皇誕生日 振替休日",
"2025-03-20": "春分の日",
"2025-04-29": "昭和の日",
"2025-05-03": "憲法記念日",
"2025-05-04": "みどりの日",
"2025-05-05": "こどもの日",
"2025-05-06": "みどりの日 振替休日",
"2025-07-21": "海の日",
"2025-08-11": "山の日",
"2025-09-15": "敬老の日",
"2025-09-23": "秋分の日",
"2025-10-13": "スポーツの日",
"2025-11-03": "文化の日",
"2025-11-23": "勤労感謝の日",
"2025-11-24": "勤労感謝の日 振替休日"
}
File renamed without changes.
11 changes: 10 additions & 1 deletion tests/holidaysJPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class holidaysJPTest extends TestCase
public function testICALAnalyze()
{
// サンプル ical データの解析テスト
$test_file = __DIR__ . '/testdata.ics';
$test_file = __DIR__ . '/data/testdata.ics';
$holidays = new holidaysJP($test_file);
$data = $holidays->get_holidays($holidays->get_ical_data());

Expand Down Expand Up @@ -57,6 +57,15 @@ public function testGenerator()
$this->checkApiFile("{$nextyear}/datetime.json", $nextyear, true);
$this->checkApiFile("{$nextyear}/date.csv", $nextyear);
$this->checkApiFile("{$nextyear}/datetime.csv", $nextyear, true);

// 2024/2025 ファイル一致チェック
$file1 = file_get_contents(__DIR__ . '/data/2024.json');
$file2 = file_get_contents(dirname(__DIR__) . '/docs/v1/2024/date.json');
$this->assertEquals($file1, $file2);

$file1 = file_get_contents(__DIR__ . '/data/2025.json');
$file2 = file_get_contents(dirname(__DIR__) . '/docs/v1/2025/date.json');
$this->assertEquals($file1, $file2);
}

/**
Expand Down

0 comments on commit 2f47aa3

Please sign in to comment.